On the Idiocy of Dot Notation of Object Oriented Programing Languages

By Xah Lee. Date: . Last updated: .

The OOP Dot Notation

the syntax of object oriented programing language is commonly like this:


where object is the meat you want to work on, and the part in round bracket option is secondary.

Python Case

For example, in Python you have:


〔➤see Python: String Methods

however, sometimes there's categorical pigeon hole problem, and the OOP language designers have a dilemma: should data be the object or class the object? This particularly happens for {string, regex, math, number} things.

For example, in Python regex, you have:

re.sub(regex, replacement, string)

where the part you really want to act on, becomes the last parameter string, and the prefix the “re”, is the regex class object. 〔➤see Python: regex Example

JavaScript Case

this happens in JavaScript too. Here's some normal examples, where the meat is the first thing:


string.replace(/regex/, replacement)

〔➤see JavaScript String Methods

and now witness this:


〔➤see JavaScript Regex Object Methods

above, the meat is the string, while the /regex/ is the object (a regex string).

and, now, LOOK:

Math.max.apply(context, list)

above, the meat is the list. The “Math” is a global object, and “max” is one of its method, and “apply” is a method inherited from a Function object.

OOP Dot Notation = Complexity Multiplied by Confoundedness

Given x.y(z), there's no way to tell, syntactically, which is the verb, which is the object. Especially so in most languages today, such as {JavaScript, Python, Ruby} , where everything is a object, including function and data, and you can set it to any variable. The bottom line reached complexity multiplied by confoundedness.

solution? ban the fsck of it. Instead, everything should be a function:


The meat is always in the function's parameter spec, while the namespace.function_name uniquely identify its {module, namespace, purpose}. ➢ for example: {math.sin(3), string.trim(" xyz "), regex.match("x123", "/d+"), ….}.

g+ discussion

postscript: we should note that the dot notation isn't the only possible notation for object oriented language. The functional notation as in f(x,y,z) could also work. 〔➤see OOP's Jargons and Complexities

But dot notation helps reading? for example, x.a(…).b(…).c(…) is more readable than c(b(a(x)))

It is postfix notation that helps reading.

Dot notation is just one form of postfix notation.

JavaScript: Method Chaining and Function Composition

Here's some example of postfix or prefix notation.

All of the above, has sequential forms that are not nested.

In the functional prefix or postfix notation, the syntax and semantics has a simple correspondence.

The issue with OOP's dot notation, is the irregular correspondence between syntax and semantics.

In the OOP's dot notation, given a.b.c(d), sometimes “a” is the data, sometimes “d” is the data. It is impossible to know syntactically.

For detail, see: