# Dead code

**URL:** <https://www.ruby-forum.com/t/dead-code/133229>\
**Category:** Ruby\
**Created:** [March 29, 2008, 3:00am UTC](https://www.ruby-forum.com/t/dead-code/133229 "2008-03-29T03:00:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 29, 2008, 3:00am UTC](https://www.ruby-forum.com/t/dead-code/133229/1 "2008-03-29T03:00:48Z")

</div>

Hello,

I started learning Ruby couple of days back while I am practicing  
some of the examples I saw that Ruby interpreter doesn’t warn me if my  
ruby file has dead code. I think its good if Ruby warns me about dead  
code when doing interpretation…

if true  
puts “its english”  
elsif choice == 2  
puts “my choice is 2”  
end

in the above code elsif block will never get execute. Please give u r  
views about this…

Thanks,  
Ramu.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 4, 2008, 12:36pm UTC](https://www.ruby-forum.com/t/dead-code/133229/2 "2008-04-04T12:36:10Z")

</div>

Ruby is an interpreted language so it don’t check what you write only on  
run-time!

Writing dead-code is mostly because the programmer is not experimented.  
So instead of adding a feature to analyse/warn which will make ruby more  
slower, it will be better for the programmers to improve theirs skills!

Regards

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 4, 2008, 3:13pm UTC](https://www.ruby-forum.com/t/dead-code/133229/3 "2008-04-04T15:13:28Z")

</div>

removed\_email\_address@domain.invalid wrote:

> if true  
> puts “its english”  
> elsif choice == 2  
> puts “my choice is 2”  
> end

I guess the “correct” answer here would be to write tests for your code.  
If this appeared in a method, and you wrote a test for that method, a  
tool such as ‘rcov’ would let you know that the ‘elsif’ is never  
reached.

Cheers,  
Josh
