3 ms·
I'm (very) old school, C is still my language of choice (though it could use some help). I like the syntax, it's pretty simple. I tried playing with Rust and
by luckydude 9y ago
I'm (very) old school, C is still my language of choice (though it could use some help). I like the syntax, it's pretty simple.
I tried playing with Rust and found the syntax to be off putting. I really wonder why each new language feels it is important to come up with a different syntax to say the same stuff. Go did a lot better than Rust in this respect, at least in my opinion.
It may be that appealing to C programmers isn't a thing any more, but if it is, then Rust could have done better. And, yes, I get that the syntax isn't the selling point of Rust, trust me, I get it. I just don't get why make people wade through some weird syntax when you don't need to.
- ufo 9y agoYour comment about syntax sounds like you just want everything to look like C.
- luckydude 9y agoYes, precisely. C, for the most part (function pointers are an exception) has a pleasant syntax. Go didn't like semicolons and other stuff that it found unneeded, but mostly took a lot of syntax from C so it's easy to read Go code even without understanding the language. Rust kind of went in a different direction. Why? Understanding C syntax is pretty basic, there are a lot of C like languages. Why not be another one? Personally, if every language was just a C variant I'd be happier. It would feel like "OK, I've got the basics down, let's go explore this dialect that added garbage collection and strings as real types" rather than "I want strings as real types, darn it, I need to go learn this Tcl language". That might be an extreme way to make my point, but I think it's clear, right?
- jjuel 9y agoWhat about the people that don't like the C style syntax? I think there is room for many different types of syntax. Just stick to the style of languages you like and ignore the ones you don't. Pretty simple.
- ufo 9y agoOther than its ubiquity, there are lots of bad thigns about C's syntax: * Assignment as an expression is bug-prone * The precedence for the binary operators is wonky * Optional braces in if statements make the grammar ambiguous and is also bug prone (the infamous Apple goto bug) * The type-declaration syntax is convoluted and people need tools like cdecl to understand the more tricky ones. * The cast syntax is ambiguous and resolving this ambiguity relies on adding dirty hacks to the lexer to tell the parser about type names.
- p0nce 9y ago> Assignment as an expression is bug-prone Can be fixed without syntax change other than returning void. > The precedence for the binary operators is wonky But that's the precedence everyone is accustomed with. D enhance this by forbidding some non-parenthesized dangerous expressions. > Optional braces in if statements make the grammar ambiguous and is also bug prone (the infamous Apple goto bug) I've definately seen such bugs. > The type-declaration syntax is convoluted and people need tools like cdecl to understand the more tricky ones. This is fixed in languages that still feel C-like in syntax. > The cast syntax is ambiguous and resolving this ambiguity relies on adding dirty hacks to the lexer to tell the parser about type names. Yup.
- p0nce 9y agoWhat is the added value of things not looking like C?
- luckydude 9y agoYeah, exactly the right question. To me, C is like English, everyone has learned how to speak it. Creating some new syntax is a little like switching to a different language. I find that difficult and annoying. Here's an example. When I was doing the GUI tools for BitKeeper 20 years ago I used Tcl because Tk was (and still is so far as I can tell) the best gui toolkit around. But Tcl? Holy moly, what a miserable language (with apologies, and respect to John O, it's miserable). So I got some compiler people to make a second, parallel, compiler that took what looked like C as input and compiled it down to Tcl byte codes. Pingo! All the power of Tk but with a C-like language on top. And you can call the tcl library code and it can call you. All open source at http://little-lang.org http://little-lang.org I wish someone would take the ideas there and make a gcc/clang dialect that had all C stuff but added in a ref counter and real strings, etc.
- wyldfire 9y agoWhen I look at Rust it seems to me to be very much C-inspired syntax. The code-blocks-return-a-value style makes it much easier to understand some conditional paths. "Why would Rust change the syntax to say the same stuff?" Well, Rust is able to meet all of C's requirements while addressing one of C's big old warts: lexical analysis of C code is Very Hard. (e.g. if this particular build added "-DFOO" or "-Ibar/" to the command line then maybe there's a syntactical error or not). This means that writing robust tools to analyze or modify C code is Very Hard. I don't know if this was an inspiration for Rust's syntax but regardless I'm thankful that they didn't try to reuse C syntax. Most other successors to C (save perhaps C++) have taken on features that make them unable to write code that we have been able to write in C (bootloaders, OS kernels, interrupt routines, device drivers, etc). Teams had a really legitimate and mostly sane reason most of the time for saying "we couldn't possibly consider Java/Go/Python/etc because we won't be able to meet our product's latency requirements."
- Ar-Curunir 9y agoWhat is the biggest difference between C syntax and Rust syntax? I can only really think of how types are stated: in C they precede the variable, whereas in Rust you put a colon and then the type (but often you don't need to do this cuz of type inference). This change is much better IMO because there's a clear delineation between types and variables. The same idea applies to function signatures, which are much clearer to me in Rust than in C/C++.
- AYBABTME 9y agoSyntax is a method to express ideas. Ideas at the core of a language should be easy to express with that language's syntax. Some ideas are not possible in C as they are possible in Go/Rust/other languages. With the years, some ideas become more mainstream and then get integrated into the new languages that arise. These new languages need to express ideas that were not expressible in C, and thus may be better served by adopting different syntaxes. In short: the ideas at your disposition and the ergonomic with which you can express them is a function of the syntax used to represent them. Different languages focus on different ideas, and so it follows that different syntax might be warranted.