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

I don't know Hemmingway, but given this description:

"No surprises here. Code reduced to its essentials with no word or variable wasted. It’s not fancy; maybe its even a little pedantic - but that’s the beauty of Hemingway’s writing. No need for elaborate logic or clever variable names. It’s plain and its clear and it does what it has to - and nothing more."

I am not sure why he did not choose this style:

    function fibonacci(size) {

      var result = [0, 1], i;

      if(size < 2)
        return "the request was made but it was not good"

      for(i=2; i<size; i++)
        result.push(result[i-1] + result[i-2]));
  
      return result;
}

Perhaps because Hemmingway would care about performance?

-----

Slightly related: One year ago Javascript inspired me to write the javascript version of genesis:

http://nadamhu.wordpress.com/2011/09/29/javascript-genesis/




Just pulling quotes from the Wikipedia page, "he avoided complicated syntax and about 70 percent of the sentences are simple sentences — a childlike syntax without subordination."

Subordination is the key word, ie, limiting the amount of nesting. That's why the for quoted above is out, since there are two statements and an expression nested inside the for statement (i=2, i<size, and i++), and there are two sub-expressions nested inside the push call (result[i-1] and result[i-2]).

Going out on a limb, I'd say Hemmingway's writing is building up complex narrative using simple building blocks. The body of the for loop above is a single line, which does simple arithmetic, array indexing, and a method call all together. In contrast, each line in the while loop body does roughly one thing: first addition, then assignment, assignment again, then a method call.


Maybe I'm alone in thinking this, but I find the article version to be much more faithful to "no elaborate logic or clever variable names." Most programmers are intimately familiar with for loops and the 'i' index variable convention by now, and also wouldn't have trouble deciphering a simple one-liner like that push, but it's still more obscure than the original.

To single out for loops in particular, they've always struck me as a little too obfuscated and messy compared to the benefits they provide. It's a large, awkward word that nevertheless remains a dependable part of everyone's vocabulary, so we let it stick around. But should we?


I highly recommend: The Sun Also Rises (1926)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: