The Principle of Hard Not to Understand #
Chang Sau Sheong: Ruby has an elegant form to it that is simply a pleasure to program in. A simple example of this is the way Ruby treats everything as objects, manifested by beautiful statements such as:
5.times do |i| puts “This is loop #{i}” endwhich is hard not to understand.
I had not heard of Chang before, but it’s a pleasure to read about this Rubyist from Singapore. PuneRuby is a blog covering Ruby+Railsish activities in Pune, India. One of its authors, Satish Talim has broadened his coverage to capture a slew of very nice interviews with some lesser-known but highly intriguing folks. It’s great, really, just great.
Arrogant
Manfred
Arrogant, can you explain the strange dots in that expression to the readers at home?
DerGuteMoritz
I don’t get Arrogant’s point. This blog is obviously about Ruby, so why would you complain about praise for this particular language in place like this? Also: Stating that Ruby is beautiful is non-exclusive. Io may as well be very easy to comprehend. Subjective opinion: I think the Ruby bit is easier on the eyes (less parens). Whatever suits you best.
MonkeeSage
Arrogant: Fanboyism? Is that something like hijacking a ruby thread to promote your own favorite language? otaku taku? :)
Also, where is your implementation of the Number#to method?
You know that…
:P (all in good humor)
Manfred: In Io ’..’ is the concatination operator.
MenTaLguY
Hmm, maybe Arrogant needed to pick a better example.
Reading both I think the Ruby version is a little more direct—“do X five times” versus IO’s “for each integer in the range 0 through 4 (inclusive) do X”. I mean yeah?
Granted, in the Ruby version it’s slightly less obvious where
i
is coming from, except that the context of its use makes it a bit clearer.Sausheong
I was writing that response to the interview at 2am in the morning, and that was the only thing I could think of at the moment. Blushes on the not too good English.
hgs
I have yet to penetrate the deep mystery that is Hoodwink.d :-) When I get time I’d like to explore Io, it’s get-new-object-by-cloning is a style I’ve never used, so it would be interesting to experience that. It will have been chosen for a reason I don’t yet appreciate.
jon
0 to(4) foreach(i, writeln(“This is loop ” .. i))
rofl
shadytrees
Fortunately, my proposal solves this problem.
I expect this to be parsed forthwith.
Joe Ruby
Arrogant’s code is nasty, give me Ruby any day.
FlashHater
The double pipes take some time to get used to, but I really see no other nice syntactical way to declare how variables are to be passed into the block.
Joe Ruby
crzwdjk
MonkeeSage
I like the fieldgoals, personally. They syntactically distinguish block arguments from method arguments, and (to me at least) appear to be passive, thus recieving the arguments, whereas the arrow looks to me to be active, like it’s injecting something into the mix. But the arrow thing is mainly a learned/cultural convention…there could be some culture somewhere or in theory that sees the “pointy” end of the arrow as a collector and the “stem” end as doing the pointing so that it would mean to them the exact reverse of what I percieve it to mean. I still like the fieldgoals, though.
BTW , Sausheong, your English was fine. Keep up the good work or promoting ruby. :)
MonkeeSage
*or promoting = of promoting
david
I agree Ruby is very readable.
...but, the above “canonical example” of Ruby is somewhat misleading. Dont we Rubyist agree that it is good programming practice to typically write: When the expression fits on one line? :)...and then one could ask, whats the { } for? :)
but I degress…I think has the cleanest syntax of the languages I currently use and it is a pleasure to work with.
-happy coding
Joe Ruby
I also hate Ruby’s #{} and =>, and :var rather than var, but other than that I like Ruby!
richi
Well, sometimes it’s just enough to ask “Can your programming language do this?” ( http://www.joelonsoftware.com/items/2006/08/01.html ) !
MonkeeSage
Joe Ruby: You don’t have to use the string interpolation syntax; you could use the format syntax:
The => can be replaced by commas when using the literal or square-bracket constructor:
And the :symbol notation can be avoided by using only strings:
The || goalposts is all you’re really stuck with.
MonkeeSage
Hmm. In thinking about
format
andsprintf
...wouldn’t the Ruby Way™ be to add those methods toString
...something like:Then you’d do:
And that also makes me wonder about top-level print functions from
Kernel
also…shouldn’t it be:Kind of strange since I’m used to top-level print functions…but what say ye, oh austere rubyists of the red hand?
Mark
MonkeeSage
I was suggesting that
format
andsprintf
act like the “literal” with modulo. ;) I figured thatp, puts
andprint
could be added toObject
andformat, sprintf
andprintf
could be added toString
. It works. I wasn’t aware ofObject#display
! Learn somthin’ new every day.