Dead code

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.

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

[email protected] 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