News for hackers. Stuff that matters.
Re:My Objection to Array#sum by nostrademons on Thursday April 09, 2009 @04:12PM (#555055)
That was my point when I started the thread. The Python decision is objectively justified for technical reasons. Yet a large number of people viscerally feel it's wrong. I blame human irrationality - but then, programming languages are meant for humans, so shouldn't they accommodate our irrationality? Otherwise, you get something like Haskell. ;-)

BTW, there are other cases where Python has gone the other way. Multiline lambdas, for instance. The case against multiline lambdas is essentially that they look ugly - they let you embed an indentation-sensitive block in what might be a parenthesized expression, which means you need some dangling delimiters. But they're certainly useful, as Scheme/Lisp/Ocaml/etc. have shown.

It's similar to the compare-constants-from-the-left idiom in languages where assignment is a valid expression (notably C). If you always write "if (NULL == foo)" instead of "if (foo == NULL)", you eliminate a whole class of bugs. But I've seen very few programmers do this, because it "feels" wrong to a lot of people.

Re:My Objection to Array#sum by calambrac on Thursday April 09, 2009 @04:31PM (#555090)
I completely agreed with your original point. The fact that we went from your comment to people actually bitching about join made me really sad.

I shouldn't have said that the join argument was "purely aesthetic", I should have said that it was "purely aesthetic and trivial", because you're right, aesthetics are important, and (imo) are reason enough to disallow multiline lambdas. How do you cross the line from trivial to not? I don't know exactly, but I do know that swapping the position of the involved nouns and taking up the same number of characters for a good technical reason doesn't.

Re:My Objection to Array#sum by lacker on Thursday April 09, 2009 @05:13PM (#555177)
"if (NULL == foo)" and "'\n'.join(lines)" both feel wrong because you are putting the most complicated object last. The most complicated thing should go first so you can sooner figure out what the heck this line of code is talking about.

I would support making the C compiler just disallow "if (x = y)".

Re:My Objection to Array#sum by nostrademons on Thursday April 09, 2009 @05:54PM (#555240)
OTOH, in languages that support first-class functions, it's pretty common to put the functional argument last because then it can wrap to another line without leaving dangling parameters:

    $.each(my_array, function(val) {
      // Do something
      // Do something else
    });
That's putting the most complicated object last, and feels much more natural than:

    $.each(function(val) {
      // Do something
      // Do something else
    }, my_array);
I suspect it's more that English has trained us to read "noun verb object" sentences. In an if statement, `foo` feels like the subject, and then "== NULL" is the predicate. In an array map, the array is the subject, and the function is the predicate. In the Python join example, the array feels like the subject, "join" is the verb, and "," is the object, which is what makes it seem so awkward. Ruby's array.sum feels more natural because the array is the subject and sum is an intransitive verb.