25 ms·
> The use of ' as a symbol that has any meaning on it's own has got to be one of the most stupid choices I've seen in a language Can you clarify why you have t
by the_mitsuhiko 2y ago
> The use of ' as a symbol that has any meaning on it's own has got to be one of the most stupid choices I've seen in a language
Can you clarify why you have that opinion? What would your syntax suggestion have been?
- lelanthran 2y ago>> It wouldn't fit the syntax of the language obviously, but why not simply have the developer prefix the variable with the keyword "lifetime", rather than assigning a symbol. ... >> The use of ' as a symbol that has any meaning on it's own has got to be one of the most stupid choices I've seen in a language > What would your syntax suggestion have been? Is the syntax suggestion he provided not applicable?
- Ygg2 2y ago> Is the syntax suggestion not applicable? Lets look at proposed syntax fn list_items<lifetime life0, lifetime life1, lifetime async_trait>( &lifetime life0 self, collection_href: &lifetime life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ItemRef>, Error>> + Send + async_trait>> where Self: life0, life0: async_trait, life1: async_trait, I'm not going to pretend I understood what mrweasel meant fully, so I assume we can either omit generic or in parameter declaration (so I went with omitting lifetime keyword in parameters): fn list_items<lifetime life0, lifetime life1, lifetime async_trait>( &life0 self, collection_href: &life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ItemRef>, Error>> + Send + async_trait>> where Self: life0, life0: async_trait, life1: async_trait, I guess you might be able to omit the "generic part" like so (it might be impossible, lifetime are just generics useful for lifetime tracking): fn list_items( &lifetime life0 self, collection_href: &lifetime life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ItemRef>, Error>> + Send + async_trait>> where Self: life0, life0: async_trait, life1: async_trait, In both cases, you get a huge verbosity increase, and mix between not knowing if a value like `Self: x` is a trait with lower case or a lifetime. So you trade verbosity for more ambiguity and programmer confusion, and possibly worse error reporting (is &a b a lifetime or a missing comma e.g. &a, b).
- mrweasel 2y agoBecause pretty much any other language has '...' for strings, or at least something to do with text. It's also a character that in all other languages (that I know of) must be closed with another '. Now you could say, we don't close it in contractions in English, so there's a case where one ' can just exist on it's own. That's sort of fine, a bit outside of the realm of programming, but fine, but then I think you should remove then '...' usage. It's really confusing that the same character has two different meanings depending on something that happens later. Rust does this with ! as well if I understand correctly, so it's NOT like everywhere else, but something!() is macro expansion... Why not just prefix with "macro" so macro something() So you have something that has a ' in front, is that a lifetime, or a missing ' later? The compiler will catch it, so it not a problem in that sense, it just makes it hard to read the code. Personally I would almost always prefer a keyword. For Rust I think my problem is that the language is a little to happy with symbols and operators being one character picked for the none numbers and letters and the choice of ' makes it seem like they are running out of characters to choose from. Like we just one or two features away from assigning meaning to § and €.
- lifthrasiir 2y ago> Because pretty much any other language has '...' for strings, or at least something to do with text. I think you didn't use that many languages to see other forms [1]. LISP and Scheme don't have single-quoted string literals for example. Double-quoted strings are not really universal either, for example SQL uses single-quoted strings and double-quoted names. [1] https://rigaux.org/language-study/syntax-across-languages.html#Strng https://rigaux.org/language-study/syntax-across-languages.ht...
- GoblinSlayer 2y agoIn rust "macro" would be abbreviated to "mac".
- lifthrasiir 2y agoRust does reserve the exact `macro` keyword for the eventual replacement of `macro_rules!` [1] [2]. But it is unlikely to be used in the invocation syntax because that will be too verbose. [1] https://doc.rust-lang.org/reference/keywords.html https://doc.rust-lang.org/reference/keywords.html [2] https://github.com/rust-lang/rust/issues/39412 https://github.com/rust-lang/rust/issues/39412