r/linguistics • • Dec 16 '20

MIT study: Reading computer code doesn't activate brain's language-processing centers

https://news.mit.edu/2020/brain-reading-computer-code-1215
965 Upvotes

111 comments sorted by

View all comments

247

u/jcksncllwy Dec 16 '20

This makes sense to me. If code were comparable to human language, we wouldn't be writing comments alongside all our code.

Code doesn't say anything about purpose, meaning or intent. Code describes a process, a series of instructions, a chain of cause and effect. If you want to know why that code was written, what the point of it was, who cared about it, you'll need to read documentation or talk to it's authors using actual language.

16

u/tomatoaway Dec 16 '20 edited Dec 16 '20

Depends on the language I would say.

Lisp-like languages follow very simple forms (verb object subject) that allow for intuitive nested structures that are very easy to resolve.

For example, (verb1 (verb2 object) subject) would collapse into the simple form described above, where at a glance you could immediately tell from the context that the result of collapsing the (verb2 object) statement will result in an entity that should be treated as an object.

These simple forms makes lisp a very elegant and easily-extensible human readable language, which places an emphasis on actions, rather than objects (compared to most object-orientated programming languages)

Anecdotally I would say in Lisp dialects, it is often more illuminating to read the code than it is to read the docstrings

12

u/Shirley_Schmidthoe Dec 16 '20

It's more that due to a historical accident Lisp is to this day written in a straightforward representation of what originally was meant to be the parse tree—it was kept that way for all this time because many programmers liked it that way though many also hate it and the syntax is definitely very divisive.

I don't think that has much to do with how close it is to human language: it's simply coding inside of the parse tree of another hypothetical language directly and the same could be done with English:

(comma-disjunction 
  (conjunction 'or (infinitive 'be) (infinitive 'be))
  (finite 'be '3rd 'sing 'indicative (determiner 'distal 'proximate) (determiner 'definite (noun 'question)))

Hypothetical English parse tree.

5

u/tomatoaway Dec 16 '20

Well, I guess my argument was that the parse/syntax tree scales really well for complex sentences, whereas the more abstracted imperative languages require elaborate constructs (such as object-oriented, model-view-controller) to be able to scale so elegantly.

I do take your point though, as I cannot seem to mentally evaluate your parse tree :-)

0

u/[deleted] Dec 16 '20

[deleted]

42

u/lawpoop Dec 16 '20 edited Dec 16 '20

I've heard many a tale about this fabled self-documenting code; I've never seen any actual example of it.

Usually I hear about self-documenting code from people who refuse to write comments, or have a difficult time writing comments. When I sit down with them to go over their code, I find that they have a really hard time talking about it. Usually it ends with something like "you'll just have to read it yourself" or "Well if you can't understand it, I can't explain it to you."

What I think rather is the case is that talking about code is a different skill from writing code. Teaching is not doing, and teaching is itself its own, valuable skill. It's one more programmers should develop.

18

u/Delta-9- Dec 16 '20

"Self-documenting" is how you get whack class names like AbstractGeometricProgressionFactoryGeneratorInterface. Which, by the way (for all you self-documenters), may as well be Chinese if you don't write some comments telling me why the hell we have an abstract factory that's also a generator and an interface and why mashing together five different patterns was superior to plain old class.

Self-documenting code is undocumented code, plain and simple. It's a good guideline for helping a dev keep clarity and readability prioritized, but ultimately if your class name is a five paragraph essay it's still not going to help me understand how the damn thing works. Especially if you change some implementation detail that should be reflected in the class name but isn't: now I'm confused why AbstractGeometricProgressionFactoryGeneratorInterface is performing linear progression on the side--is it supposed to do that?--and when I fix it I have to refactor 25,000 lines of code because I'm changing the name of a class and an interface, and ...

Oh god, I hate Java

Anyway. tl;dr is that self-documented code is undocumented code.

0

u/[deleted] Dec 16 '20

[deleted]

2

u/Delta-9- Dec 16 '20

I can agree with that. I certainly don't intend to say that every for-loop and helper function needs to have an essay of comments.

In my own code I tend to over-comment, mostly because I have the memory of a goldfish and code that's "obvious" at the time will make no sense to me in a week, particularly if it's calling out to some library or using a language feature I don't reach for all that often.

I think it's the whole "obvious" standard that gets kicked around in these conversations that's the problem: what's obvious to one dev won't be obvious to another or even to the original author at a later date. I've written many an "obvious" for-loop that I later had to read through five other modules to understand. (This is where commentary on structure like you mentioned is extremely helpful.)

It's the same as saying something is "common sense." Common sense is not common, so appealing to it is meaningless.

4

u/selinaredwood Dec 16 '20

For here (writing mostly in c), a big part of "readable code that doesn't require comments" is using short variable and function names consistently. Like how i and j are always used for loops, a reliable set of names, buf, tok, <struct_name>_get() <struct_name>_free(), sort of extending the grammar and vocabulary. It lets people offload to intuition and not have to work through everything line-by-line. It also helps a lot when the standard lib is lain out consistently that way as well (like elixir or janestreet's ocaml. C maybe not so much 😅).

The giant-strings-everywhere java approach feels kind of the opposite, forcing you to pay more attention.

0

u/[deleted] Dec 17 '20

[deleted]

→ More replies (2)

3

u/goldfather8 Dec 16 '20

Maybe if you are working with code academics wrote lol. If I said something like that in a code review I'd get a talk from management.

→ More replies (1)

0

u/[deleted] Dec 16 '20

[deleted]

2

u/lawpoop Dec 16 '20

but I can match your anecdotes regarding self documenting code with my own

Proponents of self-documenting code could provide links to public repositories, or just plan old copy-and-paste this mythical code.

I think it would be really helpful to have actual examples of self-documenting code, to help more people write it. Then we could start talking about what is actually is that makes code self-documenting, instead of just claiming that such code exists (or not).

0

u/[deleted] Dec 16 '20

[deleted]

2

u/lawpoop Dec 16 '20

I'll read it over, but let me clarify my understanding going in: is this a blog post that shows problems with comments, or one that shows what self-documenting code is, with examples?

→ More replies (6)

11

u/[deleted] Dec 16 '20

Exactly right; good code should be fairly readable, using common colloquialisms in the programming language to make the intent of a bit of code clear, along with descriptive naming for variables/functions. Comments should only be used where the intent is not clear, but the first step should be to write code where the intent is clear.

That's not to say that "reading" good code will be anything like reading human language. It will be closer to reading a well made flow chart, perhaps.

0

u/[deleted] Dec 16 '20

[deleted]

→ More replies (1)

0

u/[deleted] Dec 16 '20

[deleted]

17

u/Charphin Dec 16 '20

Or more likely it's expecience of the ones who claim their code is understandable are the ones writing unreadable unmaintainable code because what they are doing is obvious. Treat your code like the next person to read it is a moron don't assume anything is basic.

0

u/Styro20 Dec 30 '20

Literally all code, no matter how bad, tells you exactly what the fuck it does. Great code adds comments so you don't waste your time back-solving the reasoning

→ More replies (1)

-44

u/[deleted] Dec 16 '20

Natural language text very often requires footnotes. It's almost impossible to read something like Shakespeare or the Bible without half a page of explanation of additional context.

→ More replies (10)