5 ms·
“Significantly less readable” is subjective. It is simpler to parse, and degrades better with type inference. That’s 90% of it, I’d imagine.
by steveklabnik 4y ago
“Significantly less readable” is subjective.
It is simpler to parse, and degrades better with type inference. That’s 90% of it, I’d imagine.
- vasilipupkin 4y agosure, well, it's not subjective if you have to type more characters to basically achieve the same thing. I guess I just don't really understand why you have to fix C++ shortcomings while also changing things that work fine. Is there a C++ developer who is having trouble declaring variables as int x? By making big changes to syntax, you are just making it less likely this ever gets truly adopted.
- runevault 4y agoA language with good type inference lets you type less because you don't need the colon or the type, where as a language with it first you always have to type something like var for a "figure it out" type.
- aardvark179 4y agoSimple types may be easier, complex types are a real pain for both humans and compilers, and they end up hiding the name in the middle of the thing. Brevity is neither the only nor most important thing on which to judge syntax.
- duped 4y agoauto + implicit coercion + pass by value semantics and copy constructors create real bugs and pitfalls in C++ code. Avoiding these semantics and deferring to explicit syntax leads to better code. Optimizing for character count is dead.
- int_19h 4y agoSomething like "int* a, b" not doing what people expect it to do is a very common C++ footgun.
- PaulDavisThe1st 4y agoFrom TFA: // Returns the smallest factor of `n` > 1, and // whether `n` itself is prime. fn SmallestFactor(n: i32) -> (i32, bool) { This is so unlike C++ I cannot see how anyone can consider it a successor language. It might, in fact, be a much better language, but it is not a successor when you're going to change syntax this much, and in a way that will be hard to automate (precisely because of the "most vexing parse" problem(s).
- yoz-y 4y agoSwift is a successful successor to Objective-C and their syntaxes and idioms are worlds apart. It’s about what class of problems you can solve in the language.
- PaulDavisThe1st 4y agoI don't agree with your analysis. But that's fine.
- jack_h 4y agoIs that really so different from the following C++ equivalent? auto SmallestFactor(int32_t n) -> std::pair<int32_t, bool> { ... }
- PaulDavisThe1st 4y agoI guess I don't understand what role the -> plays there. I must be too old school, I suppose.
- alpaca128 4y agoI can't speak for the C++ example, but in your code snippet `->` points to the return type. The function takes an integer argument and effectively turns it into a tuple, so: `f(i32) -> (i32, bool)`.
- int_19h 4y agoIn this particular example, all it does is reverse the order of return type wrt arguments and function name. I still find this syntax more readable with complicated return types because you no longer have to carefully parse it to see where the type ends and the name begins. In the more general case, having the return type follow the function name means that it can reference parameters in sizeof(), decltype() etc.