4 ms·
What is the reason for using overly minimalistic, assembly style keywords like fn, str etc? Even C++ doesn't go that far (I think string is more pleasant to rea
by shmerl 13y ago
What is the reason for using overly minimalistic, assembly style keywords like fn, str etc? Even C++ doesn't go that far (I think string is more pleasant to read than str). It's not like it's saving much, and it only worsens readability.
- nrc 13y agoIt was a design decision made long ago and seems to have stuck (although is slightly less extreme than it used to be). I also used to hate the abbreviation, but I find you get used to it quickly and after a few weeks it doesn't impact readability at all.
- jfager 13y agoIt's a matter of taste. I personally feel that your specific examples make Rust more readable, because of how little space gets wasted on those frequent, unambiguous names. Ubiquitous boilerplete-ish things that show up everywhere should recede a bit, imo; let me spend my line width budget on what's unique and important about my code. But again, it's just a matter of taste and not really worth wasting a lot of time worrying about. The important thing about Rust is its semantics (speed, safety, control), not its syntax.
- bjz_ 13y ago> The important thing about Rust is its semantics (speed, safety, control), not its syntax. Agreed. I love Haskell syntax above all else, but I like Rust's semantics too much to let that get in the way of me using it.
- shmerl 13y agoSure, I didn't want to sound dismissive, I'm very interested in Rust semantics.
- Derbasti 13y agoif `str` is too short, surely `int` is, too: function fibunacci(integer index) { if (index <= 1) { return 1; } else { return fibunacci(index-1) + fibunacci(index-2); } } compared to: fn fib(int n) { if (n <= 1) { return 1; } else { return fib(n-1) + fib(n-2); } } Personally, I prefer `fn`, `int`, and `str`. I actually think that the short names are a nice way of distinguishing between built-in keywords (abbreviated, like `str`), and user-defined names (typically whole words). Also, short names are useful since they can be used as pre/post-fixes to function names like `strsplit`.
- gmjosack 13y agoyour comparison isn't fair. you're making an argument against fn/int vs function/integer but the largest difference in the code is between index and n. I prefer the version with a longer variable name despite the length. also shouldn't the returns be unnecessary here since the conditional is an expression?
- oscargrouch 13y agoi think 'fn' is too much minimalism.. better 'fun' or even 'func' .. but maybe they wanted to distinguish the sintax from Go's 'func' int -> int (ok) str -> string but anyway.. nothing that can prevent someone to enjoy the language.. but the 'fn' for me is the most odd.. getting used to it
- bjz_ 13y agoErgonomics. More commonly used things should be shorter and easier to type. Less used, potentially dangerous stuff should be longer - `unsafe` for example. It looks weird at first, but you quickly get used to it.
- alkonaut 13y agoCompletely agree. Some language constructs that are "almost symbols" such as fn certainly works well to abbreviate, but for function names and types it feels outdated and hard to read. If a common function name is too long to spell out like iterate() then that is a candidate for sugaring out completely, not cutting in half. Even in good C codebases that run static analysis, there are errors due to mixing up "memcpy()" and "memcmp()". UT4 is one example where this happened.
- pcwalton 13y ago> If a common function name is too long to spell out like iterate() then that is a candidate for sugaring out completely, not cutting in half. We can't sugar it out completely because there are multiple types of iterators: ".mut_iter()" and ".move_iter()" for example just on arrays. > Even in good C codebases that run static analysis, there are errors due to mixing up "memcpy()" and "memcmp()". UT4 is one example where this happened. Well, that particular error would be unlikely to happen in Rust because the return types are different, and there aren't the implicit coercions that there are in C.
- Alphasite_ 13y agoI'm perhaps missing the issue completely, but isn't the argument about sensible defaults?
- stormbrew 13y agoOn this syntactic readability level I find the semicolons, in terms of both the fact that they are usually necessary and that the final semicolon in a statement group has meaning based on whether or not it's present, much worse than any terse keywords. If anything the terseness of keywords seems almost necessary because rust expressions seem to tend towards the wordy whenever type annotations come into play, and I'm just glad it didn't devolve into haskell-style symbolics for everything.