Ask HN: Is coding like speaking another language?

27 points by tbirrell ↗ HN
I'm in a position where I need to describe what coding is like to someone else. I've been programming since I was 13, so I understand it at a level that is hard to put into words, let alone describe to someone else. My latest attempt is as follows:

"Coding is like working in another language. Just like spoken languages, programming language each have their own grammar and keywords. Reading code and understanding it is like having to translate a document."

However, I'm not bilingual, so I was wondering if someone who was could tell me if this is a reasonable simulacrum. Especially the comparison of effort and difficulty between grokking code and successfully translating documents.

72 comments

[ 3.2 ms ] story [ 135 ms ] thread
No, it's not really like that. It's more like preparing an instruction on how to execute some complicated process, say, cook a fancy meal, for somebody who is very dumb (but will follow the instruction precisely).
I think it is very unfortunate that we use the same work "language" for human languages and computer languages. They are nothing alike, except you can write them in textual form and they have some kind of "grammar". It's a bit silly, but if you can't say "I love you", it is not a language to me.

I would rather say, programming is like designing an intricate mechanism, such as a mechanical clock. Some people have compared it to carpentry, or engineering.

> if you can't say "I love you", it is not a language to me.

void declareEmotion( bool isInLoveWith ) { if( isInLoveWith ) { printf("I love you\n"); else printf("I'm sorry, this isn't working out...\n"); } }

In the native dialect of western Austria you can't say "I love you".

Some form of "I like you" is as high as the emotions get there.

"The authorities are desperately searching for a husband of 47 years, who killed his wife in a horrific crime of mild attraction"
I doubt that you can say "I like you" also. Way too direct. "Gut schaust aus" is more typical
While I don't agree with OP, I don't think this is a valid argument. One can say "I love you" in a subset of formal Sanskrit which obey's Panini's grammar and rules.
I don't understand - Sanskrit is a human language (albeit a dead one).

Whereas, you could "write" programs by arranging little pieces of would with symbols on them on a board. You could punch hole cards for a mechanical loom, or you could solder electronic components together. None of that involves communicating with other people.

I think a better analogy than language would be a mathematical calculus - i.e. the way you can write down certain symbols, and manipulate them using certain rules, and you have certain guarantees about the result.

Another analogy would be a "kit" of standardized/conventional elements for construction, e.g. I-beams, windows, tiles, 2x4s, doors, cable channels, ... . You arrange these things, and if you do it properly, you get something meaningful and useful like a house.

It's a series of tools and components required to fit certain related theories?

In carpentry you have many standardized off-the-shelf tools and components (hammers, nails, windows, tiles, dimensional lumber) and you have an almost endless number of ways to combine them. You can also create your own tools and components (which is harder). You also have some pre-determined guidelines that are meant to protect/regulate things so that they're safer and easier for a wider audience to live with, maintain, and edit (building codes).

Any of this stuff will work together as long as you stick to the constraints of individual objects as they fit into the laws of physics (a component can only bear X load in Y configuration).

The concept of "properly" is a bit varied. I can build a house with mud and straw and it's a "proper" house in some parts of the world... but it might kill me in an earthquake. This might be due to a pre-determined assessment of earthquake risk, or it might be because of limited knowledge and resources available (very common in coding, and often OK in small scale scenarios).

Writing a program is different from the concept of what a programming language is. A programming language has an underlying grammar/rules. Through Panini's work, a subset of Sanskrit can also be expressed through rules.

This link on grammar might also interest you- https://en.wikipedia.org/wiki/Formal_grammar

Yes. It's a way of thinking that is communicated by words. Same as speaking a foreign language for me. I wouldn't be surprised to find out that the same parts of the brain are involved.

To elaborate, in some spoken languages you have adjective noun (e.g. blue house), but in others the order is reversed (casa azul). At some point of learning you just subconsciously know which form to use. This is similar to programming when you can use the appropriate idioms in each language. E.g. using duck typing in python vs type checks/conditionals etc. in Java.

As a programmer who is working on a language learning startup, I've thought alot about how and why these two disciplines are different. And I believe that learning a spoken language is actually much harder than learning a programming language for the following reasons:

* In order to strengthen your spoken language skills you must engage in what amounts to a performance in front of experts, akin to getting on stage as an raw amateur and performing jazz music to a crowd of experts. Programming can be learned in the quiet and safety of your home.

* Speaking a language is a synchronous activity, programming is asynchronous. You need full command over an enormous amount of new material when speaking a new language, whereas with programming you can always pause things in order to look something up.

* Learning to speak a language has a slow feedback loop compared to programming. You learn concept or word A, and by the time you first need to deploy that word or concept in the wild, it has been forgotten.

* Learning to speak a language has inconsistent feedback, with native speakers giving contradictory or unclear advice. Compilers, not so much.

* Speaking a language requires relearning muscoskeletal behavior that has been ingrained since birth.

* Speaking a new language badly is an act of courage that often penalizes introverted or perfectionist personality types. These types thrive when learning computer programming.

I could go on... :)

(comment deleted)
I don't think they're similar at all. It's an anecdote and all, but I am terrible at learning foreign languages. Something about the way my brain works. I lived in France for two years and married a French woman and I still couldn't get by for more than a day or two in that country on my own. Yet I picked up programming pretty quickly and consider myself good at it.

I think the best analogy is mathematics, in the sense that you're reasoning about abstract objects and solving puzzles. Unfortunately most people don't think about math that way so it probably doesn't help much.

No. It's more like speaking the same language (English or whatever) aimed at a very specific audience. A bit similar to talking to someone who takes everything literally. Without room for interpretation.

In that sense, it's closer to a method of organizing thought than it is to another language.

Background: software engineer who speaks 5 languages.

Do you feel like learning each of the languages you can speak has affected the way you think in any way?

In other words, does being fluent in different languages cause people to think differently?

Yes, different languages make you think differently. Some things are easier to express in one language than the other.
Combining a few other answers, I'd say it's a lot like writing a goosebumps (choose your own adventure) book in another language.

While I do like the analogy of writing instructions for someone who is very dumb, that analogy doesn't capture the different paths of execution that a program can take.

I think it's more like learning to express yourself in a different style, rather than learning an entirely different language.

The style we are accustomed to allows for an interlocutor with significant ability to fill in the gaps in what you've said or written. To read appropriate context and subtext into your words and interpret them meaningfully despite ambiguity.

The style we must learn when programming is to remove all possible ambiguity and subtext, and explicitly provide a context (arguments, scope, closure, environment, etc.) for evaluation.

When we learn a new language we learn new vocabulary and alternate syntax but we still express ourself in the same style. When we learn a new style we must unlearn and relearn all of our assumptions about how language is interpreted. That's what learning programming is like.

When it comes to code, English speakers like to talk about how good, pure, or expressive a code language is. For example, ask people up in here to describe PHP and you'll get bile. Ask them to talk about Closure and you'll get accolades. Usually summarized as "because the language is bad the result will be bad"

...the irony is that the discussion will be in English. One of the worlds most inconsistent, awkward, written languages. [1] Further more, most code is English. Example: it's usually "if/else" not "si/sinon" or "と/又は"

IMHO I don't think the analogy holds. However, I don't know of a better way to describe it.

PS: I'm bilingual (French/English)

[1] http://aclassen.faculty.arizona.edu/content/english-language...

Well, yeah. English is the JavaScript of natural languages.
Could you explain what you mean by this?
I doubt it.
I am not the original commenter, but - English is full of slang and borrowed concepts. And it has rules, but they aren't really enforced and there are many cases where the rules are explicitly broken. Every generation, we see new additions to the English language and removals of old/out of date phrasing.

When you look at it like that, yeah, it's kinda like JavaScript - not really object oriented and not really functional but borrows concepts from both, loosely typed (rules aren't really enforced), and there's a new library every month that drastically changes the language (slang, evolving with the generations).

I only speak English, so I'm not sure if other languages are like this.

There are a number of polyglots who disagree with your sentiment. Nabokov immediately comes to mind. He preferred english because of its capacity for precision and expressive-ness.
(comment deleted)
As a bilingual person, I wouldn't describe learning to code as being similar to learning a new human language. The fundamental building blocks of programming (loops, variables, functions, etc.) are vastly different from the building blocks of human language (nouns, verbs, adjectives, etc.).

However, I would describe learning a new programming language if you already know one (say, C++ to Python) as similar to learning a new human language (English to Spanish). The languages in both cases may be different, but the fundamental building blocks of expression are mostly the same.

I would say no. It's a shorthand way of writing very explicit instructions. There is far more variety and nuance in human languages than in programming languages.
I'd say it's like writing down very specific instructions to do something, that afterwards can be translated to manipulation of numbers.

The results get to be stored, retrieved and displayed.

Since it's a manipulation of numbers, the set of rules you get to use are all based on logic (if this, then that, etc)

Then you can add an extra step of number manipulation can be boiled down to manipulating binary numbers consisting of 0s and 1s, so the logic used is boolean logic etc.

So I'd say programming is more like learning logic constructs (math) - it's a universal language with rules that are interested in manipulating values in very complex ways.

I think comparing programming languages to natural languages will lead your listener down the wrong path.

Programming is writing instructions for a computer. It's just like how you program your alarm clock to go off at a certain time. But imagine if you could write instructions like, "If it's a weekday ring at 8, if it's a weekend ring at 9. If I hit snooze, ring again in 5 minutes." A programming language is a formal way of writing this down so it's easy for the computer to understand.

Its not just for computers, it's also (usually) for other programmers; people.
Yes but then it would be for other programmers for computers. Or for other programmers for other programmers for computers. Better to say its for computers :)
Programming imperative languages is like giving instructions to a computer. Logic programming is like explaining your problem to a computer. Functional programming feels somewhere in between.
I'd say functional programming could be compared to constructing a mathematical expression (at least, this is what it feels like Haskell is trying to push).
I know several programming languages (e.g. Elixir, Elm, Erlang, Haskell, Ruby, Python, etc.), and I also speak English and Japanese fluently. With programming languages, the fundamentals beneath the syntax are basically the same. For example, whether I use recursion or for loops, all of the programming languages I know support iterating through a list of data. Similarly, they all have some mechanism for making logic decisions, such as if or case statements. So, learning a new programming language is just a matter of mapping new syntax to concepts I already know. If learning a new spoken language were simply a matter of mapping vocabulary words to meanings, then I would say both are the same, but this is not the case.

In spoken languages, there are cultural differences that have to be learned and concepts that just don't translate well between languages, if at all. Idioms are also difficult. Often times, there is no cultural foundation in one language to make sense of the idioms used in another. Unlike computer programming, there is no underlying base that you can use to map new knowledge too. You have to build your entire understanding from scratch.

The authors of SICP draw a distinction between declarative knowledge (facts about the world) and procedural knowledge (instructions for how to do things). Programming, they say, is a way to precisely communicate procedural knowledge.

Most interpersonal communication is both imprecise and not procedural knowledge, and that is the biggest difference between speaking with a person and programming a computer.

No, coding is a series of instruction put on a specific order for a machine to process not an a instrument to communicate with another (computer) entity.

Modern languages are designed to be the most human-friendly possible to express those "commands", even the "lowest" language you could learn (assembly) it's still way to human friendly if compared to real bare bones communicating with the computer hardware.

I don't think so at all. Natural languages evolve with ambiguity built in — any sort of ambiguity is almost always an error in programming.
Programming is about defining requirements in excruciating detail. A business person says "I want this data stored somewhere" and a programmer has to define where it comes from, what the schema is, what transformations happen, how does it get stored, where does it get stored, and what happens if anything in that pipeline goes wrong.
I find that programming feels more like spatial navigation than speech or language.

Cognizing (e.g.) the Eclipse codebase might be roughly equivalent to maintaining a complete mental model of NYC.

No. In my opinion, it's much closer to domain specific jargon. Similar to other specialized fields (e.g., paleontology).
Someone can say "coding is like solving equations" another "coding is like wandering in a (irl) forest." I don't think there is any right or best answer. My take on it is that coding is like sculpturing, but that answer is just as flawed as all the others. Few activities (that I know of) are very similar to computer programming.
Not even a little bit. It's more (but not perfectly) like if we had multiple alphabets to express the same language.
A cogent thought, by which I assume you mean, it's all ultimately bit manipulation.

But in this view can't all the world's languages be seen as multiple alphabets that express and manipulate quantum fluctuations?

Or do different human languages create different underlying realities?

Polyglot here, dont think that it matters tho.

I think of it more as a notation and has more in common with constructs like mathematics than actual spoken language. Yeah we have rules and syntax grammer, but at the end of the day you are expressing it in plain ol English.

Not really. Looking at my code, I'll often see myself writing comments where I refer to functions and the like as "things". I never see written sentences as things, at least not in the same way.

The closest analogy I can think of are magic spells. When I think of, say, a wizard, casting a spell, I don't think of him speaking some kind of magical language, he's uttering some words which have magical consequences. In this way a spell is a thing which results in an action. In the same way I use a programming language to write what I see as discrete blocks of code that cause something to happen. By contrast, "normal" languages are just used for communication.

It's kinda hokey, and you probably won't be able to tell people that programming is like creating magical spells, but you asked.

I would assume it feels that way to those who don't speak English natively. Otherwise, I would say it's more like turning math into a language.