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

What characteristics does code share with literature? Code is more like a manual. Or rather, that's exactly what it is.


I have a crazy theory that when we read code, we actually read it as a narrative, because that's how our brains are wired. And we can't help it. It's baked in.[0]

Good, readable, code tells a story. (Here is the protagonist(s), the value(s) you're starting out with, next is the journey, the transformations on the data, then the conclusion at the end is the return value.) This is why I like functions more than objects. Each function is a self-contained story. Bad code is like reading a stream of run-on sentences with no coherent beginning, middle or end. It's like hearing a story from someone who gives you all the irrelevant details of whatever they're trying to tell you and doesn't get to the point.[1]

[0] https://medium.com/the-protagonist/the-science-behind-storyt...

[1] https://youtu.be/n5CgGTziQ4Y?t=61


> And we can't help it. It's baked in.

I often like to point out that our instinctive need to see narratives (or aversion to the inexplicable) is so strong that we construct stories even onto situations where we know (in other moments) that the story is wrong.

Gambling is a great example, and it's easy to see when people are flipping coins while insisting that recent past flips determine the next flip because of "a hot streak" or "the other one is overdue".


As someone with formal education in both literature (including lots of analytical essay writing ) and computer science, this resonates strongly with me and is a great addition to my toolbox for thinking about code.

I'm wondering how useful it would be to deploy among my colleagues who don't have similar backgrounds.

Have you tried that?


Not yet. I was working up to it at my last job, but I was laid off. What I’d love to do is something like John Ousterhout’s software design class. He admits that he based the format on an English writing class. People would write code, then their classmates would read it and make comments and then they’d revise it. I’d love to give this a shot in the real world.

If you’re up for discussing this, I’d be happy to talk about it more. My email is on my profile.


They're similar because they are both written by humans looking to project meaning into the page/screen. You're analyzing the authors intentions and perspective, not just what was written.


'literature' is something written by people for people. That's exactly what a computer program is.


Not too sure about this part. Lot of program are written then used, but never revised. Code is a tool and not an end in itself. Honestly, do you want to revise your code on and on ? I didn't. I still don't want to. Then when I have to, I'm sad that I didn't add more comment. Or better code. Like code I don't have to improve. Or come back to... Well. F* ;)


Sure, everybody likes greenfield projects the best.

But compare this with the consensus wisdom on rewriting important projects. :-)


It's primarily written for a computer, though.

But there's more to literature than just being written. A list of ingredients isn't literature. The time table for the train isn't literature. Newspaper articles aren't literature.


manuals are uncontroversially literature




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

Search: