From: William James Date: 2007-10-01T02:10:04+09:00 Subject: Re: Can you please help to make decision? On Sep 30, 8:47 am, 7stud -- wrote: [...] > Ruby also relies heavily on regex's, and regex's are never going to be > easy to read for anyone. regex's are not beginner friendly, and that > might be a big barrier for a beginner trying to learn ruby. There are > lots of people who just can't learn regex's. Those are probably the same people who can't figure out what a code block is. Even little old Awk relies heavily on regular expressions, which should be learned by anyone who wants to rise above COBOL and BASIC and C. [...] > 5) > - and this is my favorite: "Code Blocks", learning to use code blocks > is probably the single greatest benefit from learning Ruby, Python > just will not give this to you. > > I don't know what "code blocks" are and the subject isn't in the > appendix of ruby's bible: pickaxe2, so I can't comment on that. Zounds! And yet the soul, shut up in her dark room, Viewing so clear abroad, at home sees nothing; But, like a mole in earth, busy and blind, Works all her folly up, and casts it outward To the world's open view. ---Dryden [...] > 7) There are some really nice little touches that python implements, > which make programming less aggravating. I'll highlight one. > > Both ruby and python have string formatting, which requires more typing > as well as typing harder to reach characters on the keyboard in order to > output some information to the screen. But let's say you just want to > quickly display something to the screen with minimal typing. In ruby, > you can use the method: puts. For instance, > > val1 = 10 > val2 = 20 > > puts val1, val2 > > puts adds a newline after each value, so the output is: > > 10 > 20 > > But, what if you want to print two things on the same line. Ruby also > has a print method: > > print val1, val2 > > but the output will be: 1020. To get some separation, you have to do > this: > > print val1, " ", val2 > > and then the output will be: 10 20. Having to include the quoted space > in there is almost not worth the effort--you might be swayed to use the > more laborious string formatting instead. In addition, print does not > add a newline at the end, so to keep any subsequent output from > displaying on the same line, you need to write: > > print val1, " ", val2, "\n" > > That's just too much of a hassle. Using puts with string formatting is > probably no harder to type: > > puts "#{val1} #{val2}" > > So much for being able to type something quickly that displays a few > values to the screen. > > In python, the print command is like the puts method in ruby. However, > it works a little bit differently. The statement: > > print val1, val2 > > works differently in two ways: > > 1) print adds a newline after all the output--not after each variable > 2) print automatically adds a space between each variable > > So this code: > > val1 = 10 > val2 = 20 > > print val1, val2 > > produces the output: 10 20, and since print automatically adds a newline > after all the output, the next print statement won't display output on > the same line. As a result, python's print statement is incredibly > handy and easy to use. I think it shows how much thought is put into > the details of the language. Apparently, Ruby gives the programmer more power here. Just as Awk has OFS (output-field-separator) and ORS (output-record-separator), Ruby has $, and $\. E:\Ruby>irb --prompt xmp print 88,99 8899 ==>nil $, = ' ' ==>" " print 88,99 88 99 ==>nil $\ = "\n" ==>"\n" print 88,99 88 99 ==>nil $, = '--' ==>"--" print 88,99 88--99 ==>nil $\ = "<<\n" ==>"<<\n" print 88,99 88--99<< ==>nil