On 13.12.2010 18:39, Nick Sabalausky wrote:
"Stephan Soller"<stephan.sol...@helionweb.de> wrote in message
news:ie4srq$138...@digitalmars.com...
On 12.12.2010 18:01, Simen kjaeraas wrote:
Absolutely not. Ruby reads like Yoda-speak, while D is almost plain
English. Had foreach used 'in' instead of the semicolon, only
punctuation and 'ln' would be off.
Unfortunately I have to disagree here. If you have well written Ruby code
(like Ruby on Rails usually provides) it can usually be read like plain
English. That's the reason why I dropped writing documentation comments
for Ruby code: it's just redundant.
This common Ruby idiom is totally Yoda-speak to me:
doSomething unless condition?
The order-of-execution is completely backwards. Plus the "unless" instead of
"if" makes my mind pause to process an "inverted-context" because *now*
seeing a "blah" really means "not", and a "!blah" no longer means "not".
Yea, "(action) unless (condition)" is fairly normal English, but code has
different requirements than normal speech. And besides, it's also perfectly
normal, easily-understandable English to say "unless (condition), (action)",
or even a negated if: "if you don't have x, do y". In fact I'd argue the
English "if you don't have X, do Y" is much easier to understand than "do B
unless you have C".
With normal English, it's easy enough to hear "do this", and then
appropriately modify it in your head when you hear it followed by "unless
that". This is largely because instructions in normal English tend to be
*much* simpler than instructions in code. With code, there's so many other
instructions to consider that that extra little mental work of modifying
something you already processed suddenly makes a difference. But if you see
something start with the modifier (the condition, in this case) then your
mind automatically knows it's still an incomplete thought and doesn't do a
premature "commit". At least that's how my (twisted?) mind works.
Also, Ruby reading like English might be part of why I'm *not* quite won
over by Ruby's syntax: I'm a native English speaker and I still think
English makes no sense!
I'm not a native English speaker so I can't really judge how much "like
English" Ruby really is. However I prefer Rubys pseudo English over some
nested function calls with templates or mixins or something like that.
Not that code like this is not possible in Ruby but no one actually
writes such code with it (or I just haven't seen it).
I avoided "unless" for about a year after learning Ruby. It gave me a
headache translating it to "if not" and converting "or"s to "and"s. But
over time I fund it useful to write down thoughts without translating
them to "if". Maybe "(do something) unless (something)" it's only a
common thought pattern in German, don't know how much it is used in
English. "unless" is just a small detail and I wouldn't call it a
revelation but Ruby has many small details that help you to keep your
thoughts more in the problem domain and write code with less
"translation" done by the brain. It _feels_ very pleasant over time,
sometimes even fun. But I don't think this is something a talk or
presentation can convey. One just has to use Ruby for well suited
problems for some time.
Happy programming
Stephan Soller