1

In all programming languages, every command is sorted as command-arguments. For instance, in pygame, the command to draw a rectangle to the screen is:

pygame.draw.rect(surface,color,rect)

This seems rather odd to me thinking about it. Wouldn't a verb-final (or command-final if you prefer) order make more sense? For instance, what if the order of the previous instruction were:

main_window-x-y-location rectangle-green-100-by-100 object draw

First, the data to be utilized is stated, then the location in question, then what should be done with the data. Putting the command at the end like this also clearly indicates to the computer where the instruction ends, avoiding the need for things like tabs or brackets just so the interpreter/compiler won't confuse lines. This is actually one of the practical advantages of such an order in real languages. Inflected verbs always go at the end of a clause, so its obvious where the end of each clause is.

It just seems to me that this would be a better way to give instructions to something. Why then do no languages do this? Even thinking about the lowest level of how programs work, it sorta is verb-final. For instance, to place some data somewhere in memory, first you tell the program to load something into the accumulator, then tell it to transfer it somewhere (there's multiple reasons to load something into an accumulator other than transferring them to a location in memory).

Why is it this order is always chosen? Is it because western languages tend to be subject-verb-object, thus imperatives are verb-object? What about programming languages developed by cultures like the Japanese who do use a verb-final order? What is the syntax of their programming languages? Why is there so much preference for this command-arguments order?

user8600
  • 159
  • 1
  • 1
    Because this syntax disambiguates within 2 tokens that you are looking at a function call (identifier, open parenthesis) which massively simplifies parsers. Keeping arbitrary amounts of state before you resolve what you are actually looking complicates the language. – user1937198 Feb 28 '24 at 00:17
  • Also, all mainstream assembly and a significant number of machine codes are verb-initial. The operation, and then the registers to perform against. Only very simplified machine models have only an accumulator. A common syntax would be add rbx, 8 – user1937198 Feb 28 '24 at 00:21
  • You would likely still need some sort of beginning marker with your scheme for an expression tree based language. Consider how you would distinguish which items do to which function if you wanted to use the result of a function call to supply the rectangle in your example. How would you distinguish preceding args to the outer call from the args to the inner call? – user1937198 Feb 28 '24 at 00:33
  • 3
    There is forth ( https://en.wikipedia.org/wiki/Forth_(programming_language) ), which does follow verb final, but requires the developer to memorize the number of arguments for every function to be able to even determine the data-flow. – user1937198 Feb 28 '24 at 00:35
  • 7
    “Why then do no languages do this?” Postscript. It’s right there in the name. – candied_orange Feb 28 '24 at 03:44
  • In the first example you have a system.subsystem.action. It's much more useful to have all drawing routines grouped into one system (draw), rather than the other way round, grouping things by rect first and draw last. However for other cases, e.g. rect.rotate it makes sense, since rotate is not big enough to be a whole own subsystem. – Kromster Feb 28 '24 at 07:50
  • When you want somebody to bake you a cake, you don't say I want a cake. Bake it. but you say Bake me a cake., so isn't it just natural to put the verb first? – Dominique Feb 28 '24 at 08:46
  • 5
    "In all programming languages […]" – That is a bold statement. How many programming languages have you studied? More than ten thousand? That's still only a fraction. Have you studied Thyrd? Snap!? Scratch? P′′? What about Forth and its hundreds of successors and derivatives like Joy, Cat, or Factor? – Jörg W Mittag Feb 28 '24 at 09:18
  • 2
    You write as you speak. You draw( a rectangle of 100 by 100), you don't a rectangle of a 100 by 100 draw. Unless you're Yoda. – T. Sar Feb 28 '24 at 12:28
  • "Why are there almost no programming languages by non-English speakers that use non-English verb order" is an interesting question that I don't think this site can answer. – pjc50 Feb 28 '24 at 15:04
  • @pjc50: Asked and answered on [langdev.se], incidentally. – Jörg W Mittag Feb 28 '24 at 18:47
  • I'm not sure I understand your point here. The example you give is: noun.verb.noun(noun, noun, noun) which appears to me to be noun-initial as is typical for OO-style coding. – JimmyJames Feb 29 '24 at 15:57
  • "Putting the command at the end like this also clearly indicates to the computer where the instruction ends" - making it easy to the computer is not necessarily the only (or primary) concern – Filip Milovanović Mar 01 '24 at 23:34
  • Well, in SOV languages the verb-final order does help with parsing a lot. Languages that place relative clauses before nouns don't need to use subordinating conjunctions, because the inflected verb makes it obvious. If its noun-relative clause (like about 50% of sov languages), a subordinator is needed but now the end of the sub-clause is clearly marked. I've seen this all the time in German (which isn't really SOV, though its sub-clauses are, its main clause order is kinda complicated so don't ask). – user8600 Mar 01 '24 at 23:39
  • I was just thinking if this helps out natural languages so much, then why not programming languages? As I said, they often have to do things like put brackets or a tab or semi-colon or SOMETHING just to tell the computer where each instruction ends. Why not just use the command itself like how SOV languages use their verbs? – user8600 Mar 01 '24 at 23:40
  • @user8600 Also, I forgot to mention: We've decided colectively as a living beings that Reverse Polish Notation kinda sucks for writing code. – T. Sar Mar 07 '24 at 11:12

5 Answers5

10

In all programming languages, every command is sorted as command-arguments.

That's not true. One comment mentioned Forth. My first idea about this was Reverse Polish Notation, which was popular for a certain period on some programmable calculators. Still, none of these examples managed to stay popular, at least not as popular as the contemporary major languages. In the popularity contest of programming languages, 'verb-initial' has turned out to be more successful.

Why is this the case? I don't think this is objectively answerable, maybe because

  • subject-predicate-object is the regular order in English, on which most programming languages are based (even the ones popular in Japan)

  • the "function metaphor" has proven to be very effective - the fact the function syntax in most modern programming languages is modeled in analogy to mathematical functions like y=f(x)

  • noone likes to speak like Yoda

So I don't think there is just one striking reason, this was simply a historical evolvement.

Doc Brown
  • 206,877
  • There are languages that are verb-final. Yoda's word order is OSV (object subject verb). That is the rarest word order in the world (though it does show up as an alternate word order more than any other strangely). However, the most common word order in the world is SOV. It was more common in the past, with many SOV languages switching to SVO more than the other way around. Linguists often theorize that perhaps the first languages were SOV because of this. Some even think there's some cognitive benefit to it due to how common it is. – user8600 Feb 28 '24 at 23:39
2

Most Japanese programming is done in Western languages; Ruby was developed in Japan, but uses English keywords and the "function()" style.

There is Dolittle, which uses Japanese keywords and is postfix. It was inspired by LOGO. There's a whole category of stack-based languages (FORTH, Postscript etc) which work as you describe, but they have never become popular compared to ALGOL-derived verb-object languages.

pjc50
  • 13,377
  • 1
  • 31
  • 35
1

As well as function names going on the left, there is also the case of assignment targets typically going on the left.

Although I haven't used any language which puts the function name on the right, different languages have had different approaches to assignment.

I think left-sided forms predominate because we read left-to-right, so that leads to function names and assignment targets being aligned on the left.

Experience shows we most often need to scan the source code to find function calls and assignment targets, more often than we need to find the first argument of a function call or the first item in an expression which results in an assignment.

We also don't just refer function call names and assignment target names in their own right, but often as milestones in the mental model we have about the sequence of processing. So being able to see these milestones more easily, helps to visually navigate the source code and zoom attention in on a smaller locality.

There's also the case of when things get spread over more than one line - as might happen with long argument lists or long expressions. Putting something on the left then means that thing then forms the top header for the block, and multiple subsidiary things can then be indented below.

I think this is why programmers tend to prefer certain things aligned on the left, if the syntax requires one consistent choice about the matter.

Steve
  • 8,715
  • "left-sided forms predominate because we read left-to-right" AND because we're English speakers. German or Japanese speakers would naturally put the verb on the end. – pjc50 Feb 28 '24 at 15:03
-2

In imperatively organized machines (what computers inherently are, you have to tell them what to do by feeding them instructions) this is the natural way to go.

It all starts with a program. On a command line you specify a program, which needs to start before it can take any arguments as input.

Any function call encapsulates some behavior that can be steered with arguments.

Object orientation basically meets your desire though. You first state the object and then the operation. Yet arguments remain last. They are details in the operation and they are meaningless without context. The context is the operation. Also to a reader, seeing some arguments first would be useless. One would have to remember the arguments and refer back to them once the operation is known. That is not helpful to the reader.

So both the machine and the human are better off with the common order.

Martin Maat
  • 18,435
  • 2
    I don't think this argument actually holds: stack machines exist and operate in a postfix way as the OP describes. I'm also reminded that there are two different syntaxes for intel assembly that have the registers in different orders. – pjc50 Feb 28 '24 at 15:02
  • @pjc50 What stack machines would that be? PUSH arg, POP arg. Classic. It seems pointless to me to come up with exceptions when the question is "Why all these non-exceptions?" – Martin Maat Feb 28 '24 at 21:12
-4

These kinds of questions always have the same answer: First, someone thought it was a good idea. Then it got implemented. Then others copied it. Then changing it is a lot of effort. A change will only happen if there is something very substantially wrong. And then comes the point where people start thinking something has to be that way and everything else is wrong.

gnasher729
  • 44,814
  • 4
  • 64
  • 126
  • There's already four answers that don't resort to this explanation! I think the point of questions like these, is to try and tease out either why the original design was implemented (if not arbitrary), or why it might have withstood natural selection against alternatives. – Steve Feb 28 '24 at 12:22