5 ms·
Why did rust not go with standard c syntax
by blargmaster33 7y ago
Why did rust not go with standard c syntax
- steveklabnik 7y agoThere are features Rust has that aren't in C, and so have no precedent. So it's not really possible. We did take a lot of influence from C, though.
- pornel 7y agoRust did copy C syntax to a large degree. It didn't copy some of the mistakes such as type declarations, which are hard to parse (typedef makes AST depend on itself) and hard to understand ("array of function pointers" is a head-scratcher in C, easy in Rust).
- masklinn 7y agoAside from the feedback loop, C-style decls also make the language less regular in the presence of type inference as you need an "inference pseudo-type" to take the place of the type you're omitting. Also prefix casts have similar issues as prefix type + typedef.
- therein 7y agoI appreciate the ability to avoid having to enclose my conditions in parenthesis, and the main operand of statements like match, switch etc. to not be wrapped in parenthesis.
- heavenlyblue 7y agoI am sorry, but if you think language syntax “beauty” is something to be considered while picking the language to develop in, then you’re probably bot senior enough to make decisions which one of them to use for the project. There’s only one true answer to this: “it doesn’t matter at all - I’ll learn it in a week@.
- orf 7y agoBeauty is a proxy for several related properties (including productivity, expressiveness and safety), which absolutely do matter and are factors to consider.
- heavenlyblue 7y agoWell, but by this definition C++ is a bad language :) Don’t get me wrong, but if it’s hard to write an algorithm to parse it - then how do you expect humans to?
- ncmncm 7y agoSimply: humans do not like to write code that compilers find hard to parse. So in practice it doesn't matter very much. Natural languages are enormously harder to parse than any programming language, and people delight in expressing just the constructs that are hardest to parse, yet people do not usually have difficulty communicating with one another. When they do, syntax troubles are vanishingly rarely the reason.
- TheCoelacanth 7y agoHumans aren't able to correctly parse C++. There are numerous examples, but a common one is that humans will usually parse `T x();` as constructing an object of type T with the default constructor, but it actually is a forward-declaration of a function returning T.
- reificator 7y agoThe obvious counterpoint to this is brainfuck. A few examples: ,+[-.[-]-,+] >>[-]<<[->>+<<] >++++++++[-<+++++++++>]<.>>+>-[+]++>++>+++[>[->+++<<+++>]<<]>-----.>->+++..+++.>-.<<+[>[+>+]>>]<--------------.>>.+++.------.--------.>+.>+. So. Now that we've established that syntax "beauty" matters in an extreme case, can we agree that people can have different opinions about where the line is? Can we then agree that having an opinion different than your own does not make someone an inherently less senior(???) or capable developer?
- nightcracker 7y agoActually, Brainfuck has excellent syntax. The language is very limited, but within those limits the syntax is as clear as can be.
- heavenlyblue 7y agoNo, we won’t agree here because brainfuck is clear and concise. There’s no duplicity in what the operator may mean depending on the context so it most perfectly fulfils this role - is it the emojis you’d like to see there? I have a strong opinion that you should like everything. Are you going to make a point that your genetic makeup somehow prefers tabs over spaces? :)
- bsder 7y agoBecause we now have several decades of evidence of how C and C++ syntax make compiling difficult. If you look at Rust in the context of other languages, you see that most of the languages designed in the last 10-15 years have made similar syntax choices.