dead code

B

bramu.ss

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.
 
A

Abdelkader Boudih

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
 
J

Joshua Ballanco

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top