29 June 2014

Another new syntax?

Ever get the feeling that there's a lot of syntax of different programming languages that could have been kept similar? Having learned a multitude of programming languages, I've seen myself moving from a state of knowing a language very well, to a state of finding it difficult to remember the subtleties of the syntax, a few years after not having used the language.

I also know of a multitude of programmers who go through the same problem. Suddenly, at one point in their careers, it becomes difficult to program, without being able to use a search engine to refer the syntax of the language. Not because they're bad programmers, but just because every different language has been created in a different way.

People who create programming languages: If you're listening, can we please do things a bit differently?

Not that I'm against having new syntaxes. For example, I like the fact that languages like Python don't need semicolons, and I simply love the way MATLAB allows a programmer to write code.
Removing a column from a cell array matrix is this simple with MATLAB:
 
model(:,2) = [];

In any other programming language, you'd have to create a loop to iterate through an array or even create a temporary array and copy relevant content into it. Of course, MATLAB might be doing the same thing internally, but I understand that this is why the people who create languages want to put in their own style (which is often awesome style!) into the language.

But think about the programmer. The person who'd eventually use the language. They'd have to learn an entirely new syntax from scratch. While it is fun to learn a new concept, and a new, easier way of writing a language, the greater fun, is in being able to create awesome software quickly. It isn't really necessary to create a different syntax for the same old for loops etc.

So when I mention "Can we do things a bit differently", I'm asking if we can ensure that when a new language is created, the syntaxes for all basic operations, constructs, containers, imports/includes etc. are kept uniform across languages? If there are abstractions to be created above these basic syntaxes, then sure, go ahead and create something that's specific to the functionality you're creating a new programming language for. But otherwise, for the syntax that serves as the building tool for a software, let the syntax be uniform (perhaps we could select a popular language as a baseline?). Programmers will love you for it!

As for you awesome dudes creating esoteric programming languages, do go ahead, unleash your creativity and surprise us! We won't be using those languages in production code at least ;-) Y'know, I never actually believed it initially, when I heard that Brainfuck was a programming language!!!

p.s.: Not wanting to just leave this as a blog post, I wrote to the creators of some popular programming languages. Mr.Bjarne Stroustrup and Mr.Guillaume LaForge were kind enough to reply and the gist of their replies indicated that this problem is well known, and although there's nothing much that could be done about it, it's important to allow languages to evolve. Although I agree with what they replied, I do hope people get talking about this and at least new languages would be created with familiar syntax.

2 comments:

Anonymous said...

Hello blogger,

on the one hand, I understand the concern. When I do things in VHDL, I noticed, I always need to look up the non-uniform syntax there, even every time, which made me wonder. I still need to commonly look up bash syntax for tests and for-loops and how to write a loop in these numerical programming languages like Scilab and Matlab. But that reason is rather, that I don't use them often.

But on the other hand, I know it sounds mean but, that's software engineering. Usually there are strong reasons why programming languages have different syntax which lie in the language concept.
New syntax sometimes is created for personal taste and for one's own ease of readibility, look at Crystal or Coffeescript for example. Some aspects are made different because the authors wanted to improve on other syntax with a new one (usually). But overall, the syntax is not only meant to support the idea of the language in a possibly reasonable way and make work easier (except for esoteric languages and bad designed languages) but also should adapt to domain and purpose of the language and its paradigms to make better or more productive use of it. If you know and want to use different paradigms like Logic Programming, Constraint Programming, (purely) functional programming (and so much more), you can't get around a different syntax from procedural one.

For anyone reading this, note that syntax is less about choice of operator names, what symbols or token names to use, variable names and not about what complicated or unreasonable things operators or types do. That is semantics. I'm not quite sure though, if operator precedence can be called a part of syntax or rather semantics (different languages can allow the same expression but could technically parse a different syntax tree from it). E.g. PHP has the ternary operator from C but they flawed its associativity so the operator doesn't work like elsewhere.
By the way, the feature in your matlab example is supported by many modern procedural languages like Scilab, Octave, SQL, R, Python, likely Julia, etc. I don't see that modern languages would require the strict iterative way to go through arrays and collections.

And then, there still might be some very clever ingenious syntax which nobody invented before but is very productive and readable when the people get used to it. Requesting languages to be equal (or similar) in syntax would mean to disallow or restrict improvement on syntax in general which would make new programming languages useless. But good programming languages are designed because the author felt a need for a new idea. Procedural programming is not the holy grail and the majority of Javascript programmers' low demand for design is not to trust when finding a "baseline". Javascript terrible design enables the JSFuck dialect and intransitive relational operators (the designer had no clue of computer science theory).

I think, the key point of a good syntax is not its familarity but its uniformity and systematicness. It is better if the syntax allows to be as powerful and expressive as other syntaxes with only few and easier-to-learn rules which allow you to derive systematically advanced syntax features (there is some kind of natural logic behind the syntax). The language still can have a great API and well-designed builtin definitions which are important for productivity and development ease. Languages with many syntax exceptions, additions and complicated rules are not only annoying to read, harder to debug, but also worse for compilers to parse, for example C++. While slight syntax additions can have a worsening effect, I see much more impact by language features like multiple-dispatch, package-system, partial application, overloading / polymorphy, design and functionality of operators and variable/operator names in usability of a language.

Nav said...

Thank you for taking the time to share your views. I agree with everything you mentioned. However, the existing issues should not prevent us from thinking out-of-the-box to find solutions that can make programming simpler. "Don't do the work. Make the computer do the work for you" is what I say. Perhaps Machine Learning could be utilized in this context. There's nothing concrete I can say, but let's not lose hope. Ideas will sprout eventually.