-3

Maybe this question is not going to mean a lot if C and C++ are put into context, but I kept wondering why later languages such as Java and specially C# haven't been made simpler in regards of their syntax?

That's why I was wondering if there's some important reason for this, because for me it looks like these languages - C# being my pick - would be slightly (or even a lot) more productive if:

1.Drop semicolons.

2.Case sensitivity was dropped - it's very annoying and I see not benefit in using it in modern languages.

3.Logical operators where just and and or instead of && and || (faster typing? - at least I find letters faster to be typed).

4.If there was a way you didn't have to type classes' names every time you call a method within it(i.e allowing one to type only WriteLine instead of Console.WriteLine)

And there could be many others - it's interesting to notice I have myself figured out more efficient ways (more efficient = less typing) to declare methods and variables without changing functionality, thus the reason why I keep wondering why things weren't made differently (not just about programming).

So, in the end, is there any technical or historical reason why languages are kept so similar and more productive syntax aren't adopted (which seems to be the case for C like languages).

  • 6
    How is the syntax going to be *less* complex if you add *more* options? I.e. optional semicolons will pretty much by definition make the syntax *more* complex, see ECMAScript or Scala for examples. Scala is a particularly good example, because (unlike ECMAScript) it wasn't designed in a hurry, and it had the benefit of being able to learn from ECMAScript, and yet, Semicolon Inference in Scala can still lead to hard-to-track-down bugs and surprising non-sensical behavior, and (most importantly relating to your question) significantly complicates the syntax. – Jörg W Mittag Aug 05 '16 at 23:54
  • 3
    #3 is a wash: if you exchange one token for a different token, the syntactic complexity stays exactly the same. #4, I simply don't understand. – Jörg W Mittag Aug 05 '16 at 23:55
  • Yes, syntactical complexity would remain basically the same, but it would be faster to type. But I'll respect your opinion on that, you're probably more experienced than me. For the semicolon, I think Ruby does it that way, the semicolon is optional, but I'll edit it so the question says "Drop the semicolon" – Ezequiel Barbosa Aug 05 '16 at 23:57
  • Possible duplicate of [Does syntax really matter in a programming language?](http://programmers.stackexchange.com/questions/30135/does-syntax-really-matter-in-a-programming-language) – gnat Aug 06 '16 at 00:01
  • For the semicolon, I think Ruby does it that way, the semicolon is optional, but I'll edit it so the question says "Drop the semicolon". Now, explaining #4. I few months ago I wrote a program in which I had to call ´Console.WriteLine´ hundreds of times. If C# allowed me, I could import all the methods within the ´Console´ class, so that I'd only type the methods' name. – Ezequiel Barbosa Aug 06 '16 at 00:03
  • 3
    Ruby is probably not a good example. Its syntax is so insanely complex that the only parsers that have ever been able to properly parse it are either created by extracting the parser from the original implementation into a C library (e.g. the melbourne parser used by Rubinius) or hand-translating the parser from C into another language (e.g. JRuby's parser is more or less hand-translated from YARV's). Or, to put it another way: in the 24 years of Ruby history, nobody has managed to write a parser for it other than the original parser (which is at the same time also the specification). – Jörg W Mittag Aug 06 '16 at 00:04
  • 1
    Re #4, that doesn't sound like a syntax issue, but a name resolution issue. Java has `import static`, which does exactly that. You could probably get the same semantics in C♯ without changes to the syntax, you just have to change the semantics of `using System.Console` to also put all `static` methods in scope. If you do it right, that should even be backwards compatible. – Jörg W Mittag Aug 06 '16 at 00:08
  • @gnat No, not a duplicate. The other question whether syntax is or not important. Mine is different, I'm asking why some languages have a kind of syntax while others diverge, and if there's technical reason behind (the use of case sensitivity, for example). These points I didn't make explicit, but they could imply my question isn't the same. By the way, that question doesn't answer my doubts. – Ezequiel Barbosa Aug 06 '16 at 00:09
  • 4
    @EzequielBarbosa: "*These points I didn't make explicit, but they could imply my question isn't the same.*" Then maybe you should. Because your question comes off as an opinion-based, "Why don't these languages do the things I think are easier to write?" With no real facts to back up its assertions. – Nicol Bolas Aug 06 '16 at 00:23
  • @NicolBolas Hey, come on. That's the problem with stack exchange. There's always someone trying to make your question seem useless, just like there's always someone answering questions only for points. Now, anyone with normal brain capabilities will read both the questions and see they're quite diverse. The other one explicitly asks for opinions - again, opinions - about "whether syntax matters or not", a silly question that has very little to do with what I asked here. Plus, I read instructions before posting, so I know how I'm supposed to post things. – Ezequiel Barbosa Aug 06 '16 at 00:41
  • 2
    What makes you think languages that subscribe to your 4 proposals are automatically more productive? – whatsisname Aug 06 '16 at 01:10
  • @whatsisname The question wasn't originally supposed to stick to those 4 proposals, as I mentioned them only as examples that C like languages have more complex syntax compared to newborn languages and that what I wanted to know exactly was not how the application of these 4 ideas would change anything, but why languages can't be more simplified. But the fact is, SE is becoming even worse each day, so that critics and comparisons to off topic high voted bullshit questions forces you to edit your question while not having anyone even barely interested in give some real answer. – Ezequiel Barbosa Aug 06 '16 at 01:16
  • @whatsisname Oh, beautiful, I thought it was just me, but seems like more people are seeing how SO at least is becoming one of the worst Q&A platforms I've ever seen. The difference here is that they are professional developers seeing the big holes that are growing in SO (SE, in this case): https://sergworks.wordpress.com/2012/09/26/why-stackoverflow-sucks/ https://medium.com/@johnslegers/the-decline-of-stack-overflow-7cb69faa575d#.lx9ruixtq These guys should see how SO in Portuguese works, and they would be ashamed. There people at least care about answering the questions. – Ezequiel Barbosa Aug 06 '16 at 01:20
  • If the language changes its syntax, what happens to the billions of lines of code already written in that language? – GrandmasterB Aug 06 '16 at 03:58
  • 1
    @EzequielBarbosa: If you want to blather forever about mindless topics, there are better places for that on the Internet than Stack Exchange. If, however, you want a real answer to a real question, Stack Exchange is pretty much the only place on the Internet where you can consistently get one. – Robert Harvey Aug 06 '16 at 05:52
  • @JörgWMittag FWIW, C# 6 has `using static`. – Dan1701 Aug 06 '16 at 06:13
  • There is or was a trend where where languages (even non-programming languages as well) have version with different syntax (+ some additional features). Examples: CSS > Less, Erlang > Elixir. – Darek Nędza Oct 29 '19 at 20:19

2 Answers2

2

To answer your direct question: Why didn't C# adopt these four syntactic changes?

As for #4 - they did. In C# 6.0 with using static you can indeed write WriteLine which saves you some typing. So you get your wish granted!

But for the other 3 points - these we not adopted because C# descends from languages with a different style of syntax, and there would be no clear benefit to changing this syntax. Despite what you claim, there is no evidence your suggested syntax is more productive in general.

You can compare with BASIC (and the various derivatives like Visual Basic and VB.Net) which has the features you request:

  • No semicolons, line breaks are used instead
  • Not case sensitive
  • The logical operators are called and and or
  • A print statement.

Python also almost conforms, except it is case sensitive. BASIC was designed for beginners. Python also emerged from an attempt to create a teaching language for beginners, and usability studies were actually used to determine the simplest syntax.

Java and C# has a different style of syntax because they are derived from C++ and C, so it all comes down to C (which in turn was based on B and BCPL). Neither of these languages were intended for beginners or for teaching. They were systems programming languages intended for hard-core developers.

C++ built on C syntax because it started out as an extension of C. Java built on C++ syntax because it started out as an extension of C++. C# copied Java syntax, because they wanted to lure Java and C++ programmers.

That said, there is no proof that BASIC or Python syntax is more productive as you seem to take for granted. They are designed to be easier to learn but this is not the same as more productive in general use by a competent developer. (Note: there is no proof of the opposite either. It is notoriously hard to measure developer productivity and compare it across languages.)

For example or is clearly easier to understand than || for non-programmers which know basic logic. But if you already know the language by heart, I have a hard time believing one should be significantly more productive than the other. The reason C has the shortcut operators && and || is for symmetry with the bitwise operators & and |. VB.Net has both, and calls them Or and OrElse - certainly not simpler or easier to type!

There are many factors which make a language more or less productive and syntax is just a single superficial factor. For example the C-style languages are all statically typed while BASIC/Python are dynamically typed, which is a much deeper difference.

One thing you mention, case insensitivity, definitely does not improve productivity for competent developers. Case sensitivity may be confusing for beginners, but any competent developer would always be consistent in casing for the sake of readability. Never mind the difficulties of case folding when using Unicode characters from various scripts and languages.

JacquesB
  • 57,310
  • 21
  • 127
  • 176
  • 1
    Java did very definitely *not* start out as an extension to C++. In fact, pretty much the only influence C++ had on Java was in what *not* to do. Java was predominantly based on Objective-C (which is basically C + Smalltalk, and since Java removes almost everything inherited from C except static types, Java is really Objective-C - C + types, which reduces to Smalltalk + types). C++ heavily relies on punctuation characters, e.g. `:` for inheritance, Java seems much more in the Algol/Pascal/Modula/Oberon tradition with its use of verbose keywords (`extends`, `implements`). – Jörg W Mittag Aug 06 '16 at 08:43
  • @JörgWMittag: I read somewhere that Java started out as an attempt to simplify `C++` called `C++--` which turned into Oak which turned into Java. But honestly I cant remember where, so I can't provide a reference. But it is clear that Java inherits a lot of syntax from the C/C++ family, and the surface syntax is *much* closer to C++ syntax than pascal syntax. – JacquesB Aug 06 '16 at 08:59
  • @JörgWMittag: To be clear I'm talking about surface syntax. Semantically Java was probably more influenced by Objective C and Smalltalk. – JacquesB Aug 06 '16 at 09:20
  • 2
    @JörgWMittag: OK, found a reference: http://tech-insider.org/java/research/1995/07.html *Gosling began by extending the C++ compiler. Eventually, however, he realized that even with lots of extras, C++ would not suffice. Thus, Oak was conceived in mid-1991.* – JacquesB Aug 06 '16 at 15:39
  • I knew C# 6.0 offered string interpolation, but not #4. – Ezequiel Barbosa Aug 06 '16 at 20:22
  • @JacquesB: interesting. Patrick Naughton strongly disliked C++, so much that he was about to leave Sun in order to move to NeXT to work on Objective-C (which he considered vastly superior), when he accidentally bumped into Scott McNealy at a hockey game, who asked him to write down what he thought was wrong with Sun. The result of that write-up is Java. Some time later, when NeXT started dwindling, several of the NeXT Objective-C guys came to Sun to work on Java. James Gosling was a big Lisp guy (he wrote the very first port of Emacs that didn't run on a Lisp OS, for example). – Jörg W Mittag Aug 07 '16 at 01:51
  • 1
    All of that makes it highly unlikely that Java is based on C++. Patrick Naughton himself wrote as much in a newsgroup posting: [*Java Was Strongly Influenced by Objective-C … and not C++ …*](https://cs.gmu.edu/~sean/stuff/java-objc.html). I find it interesting that James Gosling actually started out by extending a C++ compiler, I had never heard about that before. – Jörg W Mittag Aug 07 '16 at 01:54
1

Why do I see this phenomenon? Or: why do the few languages I am learning share the C-like syntax?

Let's decompose this question into several parts.

  • Why did the original designer(*) of the language adopt a C-like syntax?
  • For each element of syntax design (such as those mentioned by the asker), are there legitimate reasons or arguments favoring such use?
  • Why do such languages become popular? Does C-like syntax lend to the popularity of a programming language?
  • Why aren't there languages with syntax crossovers from two or more languages, i.e. between a C-like syntax and another non-C-like syntax?

Why did the original designer(*) of the language adopt a C-like syntax?

A lot of programming languages have just one original designer in the beginning; some have a few; very few programming languages were designed by a committee from the beginning.

You can find interviews of these language designers on the internet. Often they will explain why the decision was made.


For each element of syntax design (such as those mentioned by the asker), are there legitimate reasons or arguments favoring such use?

The semicolon question has been asked before. If anyone has something to add, please go over the existing answers, and add a new one if your contribution is new.

The case sensitivity question has been answered by Microsoft.

For logical operators, in the early days it was widely believed that a language should provide both non-short-circuit (evaluate both) and short-circuit evaluations for and and or.

Example (Pascal):

  • Both operands evaluated: and, or
  • Short-circuit evaluated: and_then, or_else

The opinion on short-circuit evaluation has shifted in the last few decades.

The Console.WriteLine question is a result of being an object-oriented programming language. In short, in order to make a function call, it is necessary to specify whether the function is a member of the class (if it is a static method) or a member of an instance (if it is an instance method).

Aside from Console, there are several text outputs that are commonly used in C# programming:

  • System.Diagnostics.Debug
  • System.Diagnostics.Trace

If you look at the Visual Studio project configuration page, you can find that Debug and Trace can be independently enabled or disabled in debug builds.

From a language design point of view, one can argue whether WriteLine should belong to a text output, or to a string. Consider these alternatives:

  • "Hello world\n".WriteTo(Console.Out);
  • Console.WriteLine("Hello world");

The first alternative can be implemented by defining a C# extension method that has a TextWriter as its second argument; the first argument is the string.


Why do such languages become popular? Does C-like syntax lend to the popularity of a programming language?

I will let others answer this part.

It is suffice to say that C-like syntax is not the only factor that determines popularity. Plenty of popular languages, e.g. Python, Ruby etc., do not have C-like syntax.

It is also suffice to say that the business world does not discriminate programming languages on the basis of syntax. Plenty of large corporations use Python, for example.


Why aren't there languages with syntax crossovers from two or more languages, i.e. between a C-like syntax and another non-C-like syntax?

or, alternatively,

Why aren't there languages with configurable syntax normalizations, such that two programmers working on the same source file can choose two different syntax normalizations, and perform on-the-fly syntax conversions whenever the source file is handed over?

I will let others answer this part.


rwong
  • 16,695
  • 3
  • 33
  • 81
  • You captured it. I wish I could have been able to structure like you have structure your answer. Especially the first two topics you raise while answering. One other interesting point is about the possibility to output text to the console by means of a method belonging to the string class. That really makes sense as well. That's what I was looking for. – Ezequiel Barbosa Aug 06 '16 at 20:15