Hacker News new | past | comments | ask | show | jobs | submit login

"Ruby, in an adorable little attempt to wear big-boy pants, is turning this expression into the following pseudo-code"

Is the condescending tone necessary?

An alternative:

"Ruby turns this expression into the following pseudo-code"




The author, in an adorable little attempt to wear big-boy pants[0], seems not to know that '<' is a message passed to a receiver. You can even redefine it if you like.

Better pseudo code would be

    1.lt(2).lt(3)
In fact, this is correct (albeit ungainly) ruby code

    1.<(2)  # true
and so

    1.<(2).<(3) # Say wha ... ?
makes no sense.

[0]: Yes, a cheap shot.


The underlying mechanism doesn't matter if it's wrong.

Those familiar with the mathematical notation would think:

     1. '1 < 2 < 3' parses to '(1 < 2) and (2 < 3)'.
     2. '3 - 4 - 5' parses to '(3 - 4) - 5'.
     3. '3 ^ 4 ^ 5' parses to '3 ^ (4 ^ 5)'.
Ruby's convention is clever, but ultimately wrong, and this is one of the cases.


Unfortunately Ruby is not wrong. Ruby is simply being strictly correct from a logic point of view, where < is R^2 -> {T, F}, as opposed to being strictly correct from a math-notation point of view, where < is treated syncategorematically. Neither is correct, sans qualification; given that Ruby is not aimed at mathematicians, it's not unsurprising to find that it's not going to go through the extra parsing effort to use math notation.


1 < 2 < 3 DOES evaluate to (1 < 2) < 3

And 1 < 2 evaluates to true. What else would it evaluate to?

That leaves (true < 3)

Which fails. This isn't a mistake by ruby. When you chain methods you have to think about what they return.

And the issue here isn't associativity.


The comment you're replying to was not asserting that Ruby fails to follow its own rules, but rather arguing with the rules Ruby follows; other languages have made an exception to their normal rules for this case, and apparently some people feel it would be better for Ruby to do the same.


> 3. '3 ^ 4 ^ 5' parses to '3 ^ (4 ^ 5)'.

I actually think that a trained mathematician would have no idea what to do with 3 ^ 4 ^ 5. It's a completely ambiguous statement and has no proper mathematical parsing.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: