Getting a random line from a file - and a question!!!
29 10 2007
line = IO.readlines('some_file')
c = rand*line.length.to_i
puts line[c-1]
Very simple logic and it can be easily understood by just looking at the code itself. No explanation needed. If someone knows a better way to do it then please post it in the comments. BTW..thats in ruby.
I am really puzzled about something and would like to know your answer since you are here. The question is, when or under what conditions an experienced programmer cannot write a code like this
print something if some_other_thing == something_else
Considering that the guy has written codes like this thousands of times and hundreds of times involving very complex logic.
My thoughts are below, you can use the comment form for yours:
1) when the guy hasn’t understood the problem fully
2) when the guy is sleeping
3) when the guy is stressed
4) when the guy is not able to focus
5) when the guy is dumb, no i don’t think a dumb guy can become an experienced programmer
PS. I would like to expand on this post in future and write in detail about it once I thought about it fully and gathered some opinions.
PPS. I would also like to know if someone else had similar experiences / aware of stories like this in other fields as well, not necessarily in programming.
Sign up and be a part of SPhred.com and don’t forget to invite your friends ;o)







I don’t think it is expected from an experienced programmer. I used to pretend that I don’t know something very simple with one of my new recruit just to check his response and have fun sometimes.
It is really fun and also an eye opener to watch how people respond when they come across something unexpected.
I did intentionally act igorant and foolish a few times in the past to avoid a future confrontational situation.
To me, it makes more sense to be called stupid rather being called a bad guy.
Because if you act stupid then atleast you still have a relationship with others involved but if you become a bad guy then its very difficult to build that relationship again.