7 ms·
A lot of the compromises made in Rust syntax were to make it much, much easier for the compiler to reduce passes to compile into a syntax tree. There are certa
by zanny 10y ago
A lot of the compromises made in Rust syntax were to make it much, much easier for the compiler to reduce passes to compile into a syntax tree.
There are certainly some things that should just be obvious now, though. Using the C++ namespace separator of :: is just ludicrously obtuse for an extremely common symbol, using the & for refs is archaic (I mean... you could have just called it a ref. ref T instead of &T. And then just ref(foo) or foo.ref to get a ref to foo.) And the syntax for lifetimes is horrible, with the 'a and the fact that in practice its about as significant as naming parameters in a C++ function definition in a header (ie, pointless - the words are discarded by the compiler every time).
And I certainly would have argued for whitespace significance, at least as an option, instead of classic semicolon spam.
Given all that, Rust is still, IMO, the best programming language we have right now for native performance, period. We can criticize what we don't like but we should at least agree its the best we have.
- kbenson 10y ago> Using the C++ namespace separator of :: is just ludicrously obtuse for an extremely common symbol Obtuse? It's sort of common. Multiple languages use it. Personally I like the namespace separator being distinct from the object/struct element accessor. At least they didn't copy PHP in using backspace... > using the & for refs is archaic (I mean... you could have just called it a ref. ref T instead of &T. And then just ref(foo) or foo.ref to get a ref to foo.) Please, let's not have more cases where things look like functions but aren't. Functions should look like functions. Operators should look like operators. You might have to learn a small set of operators for a new language. This is front-loading some confusion and learning pain for ease of use later. It may make the language harder to read for people that don't know the language, but anyone reading the source code with the aim to make some changes should probably know the operators at least. I'm not sure giving it a slightly more expressive name but making it look like something else actually makes life easier for those people. > And I certainly would have argued for whitespace significance, at least as an option, instead of classic semicolon spam. Optional whitespace significance? That sounds like a recipe for disaster, IMO. I can see a case for one or the other, but mixing of modes like that when it deals with something that is by nature somewhat invisible (or meta), seems prone to problems. Also, examining why Python has had problems with functional style workhorses like map might shed some light on the negative aspects of whitespace dependent syntax.
- johncolanduoni 10y agoLots of languages with whitespace significance have no ergonomic issues with functional style. Haskell and the ML family come to mind.
- kbenson 10y agoActually, looking at Haskell, the optional whitespace (either indentation or braces, newline or semicolon) looks like it solves that problem quite well. I don't have much experience with optional whitespace, so I can't comment on whether it neatly solves the problem, or creates additional problems in readability as close to or greater than the original problem. My gut feeling is still that it might be messy.
- iopq 10y agoBackspace would be amazing in Rust. Imagine: use .\greetings\hello; use ..\foo; use \bar; right now these are: use self::greetings::hello; use super::foo; use ::bar; I think the PHP way would have been way better
- kbenson 10y agoBackslash is almost universally associated with "escaping" the next character in a string. The only place I've ever seen it used as a separator is in Windows, and my understanding is that it causes enough grief when used in strings that people dislike it there as well. The only reason Windows uses backslash is because DOS 1.0 didn't have hierarchies and already used slash for command switches, so they used backslash so it wouldn't conflict. What is wrong with ::? It's visually distinct, isn't easily confused for other things, and unused for anything else, which pretty much hits all the criteria I care about for this feature. I'm seriously asking, why do people dislike ::? Is there an actual basis, or do people just not like the look?
- iopq 10y agoThose paths are actually valid Windows paths. I don't like `super` and `self` instead of `..` and `.` - it's just extra stuff to remember. Also, because of how the metaphor for paths is broken, the relative paths in Rust are not intuitive. That's why you HAVE TO put `self::foo` because the default is not the same as what you'd expect if it were a path. It's overly complicated compared to just letting you use actual Windows paths.
- theseoafs 10y ago> I mean... you could have just called it a ref. ref T instead of &T. And then just ref(foo) or foo.ref to get a ref to foo. Ugh, no. There are references all over the place when I write Rust code -- it would be a serious bummer for me if annotating those types and making those references took up 4 characters for "ref " instead of just the 1 for &.
- zanny 10y agoYou can have both, but you use a lot of vocabulary all the time in rust (clone, let, mut, static) and nobody is harping on how the most common words need to be made glyphs to save 2-3 characters per use.