5 ms·
If Hemingway wrote JavaScript
- Fletch137 14y agoAs a book nerd myself (and a lover of JS), I really enjoyed that.I think the criticism of Dickens was undeserved, even if it was a quote - but the Shakespeare iteration was spot on, loved it.
- Ygg2 14y agoMy antivirus has found Mal/HTMLGen-A virus on this page. Has anyone verified this is legitimate? The domain .xxx doesn't inspire much confidence either.
- eevilspock 14y agoAngus Croll's own website points to it.
- jrockway 14y agoExcellent use of the .xxx domain name. If people start using .xxx for normal writing, the concept of "one place to conveniently censor" will not work out. Heh.
- federicoweber 14y agoI do agree, the .xxx domain is not an excellent choice, but at the end it doesn't really bother me.
- citricsquid 14y agoI don't think that is true, what will happen is people browsing hackernews from work (in not particularly liberal work places) will not be able to read posts. Even if people choose to (incorrectly) use the .xxx extension I don't think it's going to push people to stop assuming .xxx is pornographic. edit: assuming you're not being sarcastic, can't tell.
- eevilspock 14y agoSome people don't give a fuck about page views. I highly suspect that @fat is one of those.
- chanux 14y agoHe may not be a guy who doesn't give a fuck about people _reading_ the article though.
- freehunter 14y agoIt reminds me of bands who have offensive names, or developers who name their software after offense words. They might not care about "rules" or "society" or this and that they might say, but it's inconvenient for me. Even though I am not offended easily, some of my coworkers, bosses, classmates, people on the bus, etc might be. If it's inconvenient for me to view the site, use the software, or have the album art showing on my iPod/computer, I'm going to avoid it even if I like it. That's their choice, I understand. They made the determination that there are people who could appreciate their work but aren't willing to take the same hit to their reputation. It just disappoints me as a fan.
- RossM 14y agoOddly enough, not blocked by SonicWall (at least in our config, which I would assume is fairly default-ish).
- nicholas_tuzzio 14y agoIt was automatically blocked by my work filter as porn. First time I've even noticed a .xxx extension, and I didn't notice it until I noticed it was blocked.
- loeschg 14y agoYup, still hesitant to click .xxx links at work even if it's not filtered. Didn't see any repercussions after the last time I accidentally clicked one at work (another HN article)... though I didn't get promoted this time around... correlation? I'm going to make myself feel better and say yes.
- onurozkan 14y agowebsite automatically blocked in mid-east countries. sad.
- MengYuanLong 14y agoI can't access a lot of posts in China but this one works great \o/
- becojo 14y agoIndeed. It's blocked by my college's proxy.
- RobAtticus 14y agoIs this like on a public computer at your campus? Or is it your personal machine connected to the college network? If it's the latter, it seems odd to me that a college would filter your results for your personal machine.
- timje 14y agoI love this post, it reminds me a bit of the Mark Crick's 'Sartre's Sink' series of books.
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]
- eevilspock 14y agoVonnegut. Beautiful except for this omission. Anyone?
- RyanMcGreal 14y agoVonnegut would tell you the return value in the first line and then spend the rest of the function showing you how he got there.
- jpolitz 14y agoLike this? function fibs(size) { return f(); function f() { ... implementation here ... } }
- Void_ 14y agoThis is cool as a joke, but I don't think code should be compared to writing. For example I am an engineer, so this comment is written like code. It contains just enough words to express my point, it's clearly structured and my goal is to make it easy to read. That's okay writing, but far from great. Great writers can just sit down and write amazing text. I could never do that. I have to go back, read after myself and refactor. I wonder if other engineers feel similarly.
- arnsholt 14y agoWriting prose is actually quite similar to writing code. I don't think any author writes in linear, unidirectional process. Just like coding, you solve some subproblems (chapters, sections, etc.) before moving on to somewhere else, you go back and refactor so that the text flows better, or the ordering of points is better. And there are bugs. Stuff that's wrong, a dropped word and so on. My experience with writing is mainly with academic prose, but I think most literary authors work like this as well. Besides, I do think that different programmers will have different styles in the same way different authors have styles. In part it'll probably influence your choice of language, but there'll be variation within a single language as well.
- andreasvc 14y ago> I don't think any author writes in linear, unidirectional process. Yes, people do. On the extreme end you have the stream-of-consciousness style. E.g., on the road was written on a typewriter with a series of sheets of paper joined together to avoid interruptions. I also think I remember Neal Stephenson saying in a talk that the writing should come out naturally, not sculpted word for word. When it doesn't, it's called writer's block; a programmer's block on the other hand is not really a thing. Text is typically read linearly, so it's also easier to write that way. Code, except for the very simplest, jumps around from function to function so it's going to require some additional planning.
- jrajav 14y agoI disagree. I think the best writers work precisely like the best coders. They don't compromise on a single letter, they ruthlessly rewrite and refactor their own work as many times as they need to, and they value simplicity, elegance, and effectiveness. The main difference isn't the method, it's that writers usually get a lot more time to do their work. Tangentially, I believe that learning to write better will make you a much better coder and communicator.
- atdt 14y agoChrist, what an asshole.
- suprawsm 14y agoWow, I really enjoyed this post.
- dschiptsov 14y ago..it would be Scheme. or, well, Arc, which, I think, is already obese.)
- ajuc 14y agoGreat post, but I don't agree with the critique of "Dickens'" solution. Using one-step equation to solve iterative problem is IMHO better (obvious speed benefits for large n, the only drawback is floating point imprecision), and deriving the equation requires deeper understanding of the problem than simply modeling the iterative equation with a loop.
- t_lark 14y agoagree, one step is better, but extra points for bounding for what values of n the floating imprecision kicks in
- relix 14y agoI'm not sure I understand how a speed benefit would be had here, since to get number N+1 they still need to retrieve (and/or calculate) number N-1. The difference between getting (N and N-1) or only N-1 is negligible, especially for large n, unless I'm missing something? It's not really more parallelizable either.
- ajuc 14y agoAh, yes, I've read the part about multiplying, and skipped over the real code. My bad. The benefit would be there, if Dickens went one step further, and used Math.pow to get the result instead of loop (that is - assuming calculating the power is faster than doing a loop (but it should be - you can square a few times to get near the result instead of multiplying "by one factor" each time)).
- relix 14y agoNow I see, yeah that would improve it.
- stylewalker 14y agoWhat is that CMS i see more and more often?
- jrnkntl 14y agohttp://svbtle.com/ http://svbtle.com/ but it's for an exclusive group of writers.
- deleted 14y ago[deleted]
- nadam 14y agoI 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/ http://nadamhu.wordpress.com/2011/09/29/javascript-genesis/
- jrajav 14y agoMaybe 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?
- DougBTX 14y agoJust 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.
- angusC 14y agoIf anyone wants to add Vonnegut or anyone else please feel free to fork my original code. No reasonable pull request refused :-) https://github.com/angus-c/literaryJavaScript https://github.com/angus-c/literaryJavaScript
- russelluresti 14y agoI was actually really hoping to see a Vonnegut.
- lmm 14y agoAm I alone in finding this ridiculously pretentious? I got as far as the mocking olde-worlde "shakespeare" comments before giving up. Javascript is not a better language than others (in fact it's a far worse language), and it's downright insulting to put words in the mouth of someone like Hemingway to try and make yourself feel better.
- dmorgan 14y ago>Am I alone in finding this ridiculously pretentious? No, but you must be among the few not getting the joke or not being stuck-up to see that IT IS a joke post. I mean, "it's downright insulting to put words in the mouth of someone like Hemingway to try and make yourself feel better." Really? >Javascript is not a better language than others (in fact it's a far worse language) Even if that was true (which is highly debatable, because a language is not just it's syntax, or even it's semantics), it doesn't have anything to do with the post (besides it being about Javascript).
- andreasvc 14y agoEven if you see that it is a joke you can find it a bad, pretentious joke.
- PuerkitoBio 14y agoThis is fun. Remember fun?
- lmm 14y agoI thought fun wasn't allowed on HN
- waterlesscloud 14y agoFun that requires some effort is fine. Mindlessly copying the meme of the week is not. See: IOCCC, Esoteric Languages, etc.
- engtech 14y ago
- Millennium 14y agoMy problem with the Hemingway one is that there's not nearly enough function call chaining going on. Hemingway would be all over that particular construct.
- frenchfries 14y agothis guy needs more xxx ...
- tomchristie 14y agoThe Hemingway snippet is genius. Spot on.
- andrewcooke 14y agothe code for the bolaño one is not so good, although the explanation improves it (i think all the others snippets give you a fair idea of what to expect in a book by the author; that really doesn't). when i first skimmed the article i got down to that section, read the code, with a list of names, and expected something french and post-modern. was really surprised when i checked back to the title to see bolaño. (if you haven't read him, i wouldn't start with 2666, but with the savage detectives, which is a really sweet, funny, smart novel. also, if you speak spanish as a second language, he's very easy to read in the original - a modern, simple, colloquial style, just like you're used to speaking.) [edit: huh; i don't even remember the dream sequences at the start of 2666, so maybe my bad. will have to go back and re-read. edit2: oh, yeah, i do remember. ok... but there's nothing like that in any other book of his i have read. hmph. you might as well characterise his writing as a list of murders.]
- christensen_emc 14y agoIt seemed like a pretty obvious reference to 2666 to me. The first part of the book has a number of dream sequences where its characters will just list off philosophers and put them into groups and connect them with lines. Definitely took me a few days to get through that book.
- omegant 14y agoIt´s very well written but I can´t stand(nor understand) the way writers expand the thickness of the books just adding nonsense parts to the stories. And they get rewarded by that! Pamuk´s "Black book" is a 2 inch thick book of Istanbul streets descriptions, and... that´s it. I forced myself to finish it because I thought:"there should be something else, is not possible that all this is for nothing". I was wrong.
- ritchiea 14y agoPerhaps but having only read Savage Detectives it still felt like Bolano to me.
- brudgers 14y agoreturn result; } That happy ending is not Hemingwayesque.
- monatron 14y agoTop post HN (check), interesting title (check), innocuous title (check) -- click -- "Blocked by Security Policy" (huh?)-- .xxx domain? wtf! damnit! now i have an xxx domain logged to my corporate login... EXCELLENT. thanks. Really though... Is there some sort of clever reason why this person's blog is on a xxx domain aside from annoying people like myself stuck behind corporate proxies?
- breakall 14y agoI am immediately suspicious of a .xxx link. Any professional writer should avoid this TLD.
- klausa 14y agoThen it's great that fat isn't a professional writer, but a developer.
- glesica 14y agoFirst, I sympathize with you. However, I personally love the idea of polluting .xxx with non-pornographic (and interesting) material because I think the entire idea behind .xxx is flawed and goes against the spirit of the Internet. Freedom, and the assumption of freedom, should always be the default. If you choose to associate with people who seek to restrict your access to information (your freedom), then it is your responsibility to be vigilant.
- Charlesmigli 14y agoVery well written article. Conclusion is very sharp, I like it. I tried to make the tl;dr version but it's definitely worth reading the full article http://api.tldr.io/tldrs/506c2f7991598c0f55000098 http://api.tldr.io/tldrs/506c2f7991598c0f55000098.
- JasonFruit 14y agoIf the "Closing Thoughts" express the point of his amusing and mostly well-executed exercise, then for all his skill it's a wasted effort. It's precisely "doctrine and dogma", "rulebooks and boilerplate", that make JavaScript work for group development and long-term maintainability. This is the coding equivalent of the garage musician who says, "Don't bother me with rules — I'm playing pure emotion here, man!"
- anonymous 14y agoIt worked for the Beatles.
- JasonFruit 14y agoThey also had (in addition to abnormal amounts of talent) a producer who not only knew the rules but had the knack of knowing how much could be applied without squashing their music.
- freehunter 14y agoI love coding with emotion. As someone who is not a professional developer, I write mainly scripts or small, single purpose programs. Most are command line, some others only have the most basic GUI that would make everyone at HN cringe. This is fine for me. Reading my code, many times you can tell what mood I was in while writing it. Unfortunately, finding new languages that allow me to write how I feel is sometimes difficult because no one talks about raw emotion in code, or single-developer and one-off projects. I love Lua for this.
- dyeje 14y agoWho says everything has to be suitable for group development or long term maintainability? What's wrong with just coding for the sake of expressing oneself? I love these kind of things precisely because of this. Programming is an art, and I feel we need to be reminded of that every now and again. You don't always write a song or picture to maximize their appeal to others, sometimes you just have something in you that needs to get out.
- leif 14y agoOf course, writers would all consume linear space.
- thomasfl 14y agoTLDR; Doing javascript like Douglas Crockford is boring.
- pron 14y agoEven as a long-time Hemingway nut, I’d be the first to admit that Papa would probably have loathed programming (and programmers). You got that right.
- DanI-S 14y agoThis brings up a sore point, for me. I love to read. At some points in my life I have been able to read two or three books every week. I have spent years of time drifting through the endlessly multiplicating realities of prose. However: since moving to the Valley, working full time whilst attacking various business and development side projects, I can usually manage 2-3 pages (immediately before bed). Where do you find the time to read?
- adamgray 14y agoIf public transportation is an option for you, I find that I get about an hour (30 minutes each way) of dedicated reading / people-watching time every day while I ride the Chicago L.
- Scriptor 14y agoAt some point you have to relax a little with the side projects and just sit down with a book and read. Maybe go to a park or coffee shop to get a change in scenery so you're not tempted to open the laptop and start coding again. If you take public transportation, your commute's a good time as well.
- syaz1 14y agoHow were you able to repost this? I see similar URL. I know because when I tried to post this before I got redirected to a submission... probably this one: http://news.ycombinator.com/item?id=4336148 http://news.ycombinator.com/item?id=4336148
- habosa 14y agoPretty sure Shakespeare would not use JavaScript at all, but rather this: http://en.wikipedia.org/wiki/Shakespeare_(programming_language) http://en.wikipedia.org/wiki/Shakespeare_(programming_langua...
- tnuc 14y agoDickens got paid by the word. I would expect a lot more code that does nothing.
- russelluresti 14y agoI'm gonna go with the Bard's. Not for the solution, but for the comments.
- richardofyork 14y agoI love Literature as well as JavaScript, too. Here is a literary JavaScript post that is a fun read: http://javascriptissexy.com/javascript-is-super-sexy/ http://javascriptissexy.com/javascript-is-super-sexy/
- calvin 14y agoCan anyone provide a SFW link for this?