Alex Rivera | Logout

Objective advantages of C-style syntax

Asked 2009-05-16T11:29:07.633
10

There is a really big number of programming-languages that are heavily influenced by C-style syntax (curly-braced, semicola, etc.), maybe more than by any other syntactial style. And till this day, many modern and successful or even newly invented languages use this syntax - just think of Java, C++, C#, PHP, JavaScript, C, Perl etc.

Are there any objective reasons that could explain the great spread and success of this syntax? Are there certain advantages over the syntax of other languages?

Edit
Report

2 Answers

16

IMHO, the only thing that makes C-style syntax popular is that most people know it. And thus, using C-style for a new language makes it possible to apply old habbits (like naming conventions). This is a good thing! Although I think, the syntax is the least concern for learning a new language. But a good syntax can help to avoid errors.

Microsoft did a lot of effort to make VB.NET as important as C# (remember all the "null (Nothing in Visual Basic)" in the MSDN, which quite annoys me), but still C# is the dominant language for the .NET platform. It seems that VB.NET has a problem with the bad reputation of its predecessors. And still, using C-style seems to make a more professional look.

After all, one of C's design goals was to make the compiler easy to implement. It was easier to use a preprocessor than defining a new language construct for constants. Or the semantics of a[5]. This does not apply to C++, which is very difficult to implement, partly because it tries to stay compatible with C.

Examples:

  • Case sensitiveness, although case insensitivity is more natural to humans (NOT to computers). This doesn't mean that you should spell identifiers differently than they have been declared (beware!), but can lead to confusion. Real-world example (Java): getWhiteSpace() or getWhitespace()?

EDIT: Another nice example: What is the worst gotcha in C# or .NET?. But of course, once you are used to it and with the help of an IDE, this isn't much of a problem anymore, sometimes even more natural because it resembles better how computers actually work.

  • Operator precedence

  • = for assignment and == for comparison. if (a = b) anyone? Similar, the && and &, || and |, (!

    answered 2009-05-16T17:22:39.860
0

Afaik the popularity of C is directly linked to Unix' popularity, and not to its syntax. There are multiple facets to that point; its lowlevel language(*) and thin mandatory library suitable for kernel development, the availability of compilers, the relative early attempts at cross-system compatibility.

If I had to name a second reason it would be the relative loose build model (compilation units only meet at the linker, only the linker sees the (mostly digested program) complete for the first time), which is great for low memory systems.

Code density is often said, but that is later revisionism. As for later languages adopting the syntax, that is more in the hope that it would make an upgrade path easier than superiority of syntax. This is clearly visible in something as C# which is quite far from C, except for the blocksyntax and name.

(*) I'm hinting more on the absense of lots of compiler helpers. IOW more or less the contents of libgcc if you cut it down to K&R level.

answered 2009-05-16T11:54:43.737

Your Answer