Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The problem is that you have to run the code in your head to understand what it means. It obfuscates the intent. Just read it aloud and you'll see what I mean,

"Once upon a time there was a variable named, totals that was initialized to an empty array. Next, a for loop happened and some var, i appeared (his name doesn't really matter.) i was initialized to 0. Enter stage right, totals's buddy, orders. orders has a property named length. i was told that it shall be incremented by 1 so long as i was less than order's length property. Sadly, the for loop was just using i. i didn't know it would be disregarded once for loop was finished.

Not surprisingly, what happened next was quite remarkable. The total property of orders index i lept onto totals. i was incremented. Then the total property at index i lept onto totals... i was incremented... Finally i was greater than or equal to orders.length, so the for loop ended. totals lived on, changed by its journey while i was never seen or heard from again.

Study guide question: how did totals's character change by the end of the story and what did this mean?" "

The following code snippet means the same thing, but it's also self-documenting. Plus there's less accidental complexity:

    var totals = orders.map(function(order){ 
        return order.total;
    }); 
Read it aloud and you'll see what I mean,

"Once upon a time, there was a var named, totals. It was a list of order totals. Fin."



I think the argument is that:

> It was a list of order totals.

You can only say this knowing (basically):

> map is a function which, for each item in a list, in order, executes a function on that item and populates a new list with the returned value of that function.

(I'm sure that description is technically wrong or misstated on some level.)

And that goes back to the original post. map is jargon, meaning basically what I posted above. If you don't know the jargon, it looks a lot like obfuscating cleverness.


Your example is great, but it would be even more convincing if it used list comprehension syntax such as

totals = [order.total for order in orders]

(like some other poster in this thread did)

Then you don't even need to know what "map" means, you only need to know "for" (well, maybe you would need an insight that "order" is defined after its use, but I digress)




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

Search: