8 ms·
I don't think it is very hard to parse. I think it is very ugly though. Which kind of makes it unreadable. I mean reading fn is not natural for me. Reading func
by rat9988 7y ago
I don't think it is very hard to parse. I think it is very ugly though. Which kind of makes it unreadable. I mean reading fn is not natural for me. Reading function is way more natural. I feel like the language designers didn't pay attention at all to how natural it will look to developers
- pcwalton 7y ago> I feel like the language designers didn't pay attention at all to how natural it will look to developers This is not true. We agonized over syntax decisions. "fn" was actually preferred by most of the Rust community.
- blub 7y agoThen the only reasonable conclusion is that the Rust community has different tastes compared to the mainstream programming community. To put it euphemistically. The Swift team probably also agonized over syntax decisions and they came up with something very different which has won over many people and attracted little criticism.
- pcwalton 7y agoThe only concrete thing I've seen brought up so far is that some people don't like the keyword "fn". Swift chose "func". Is there really a huge difference? (I prefer "fn", by the way.) Swift also doesn't have pervasive use of lifetimes like Rust does. Lifetimes, by their nature, always add some level of "noise".
- blub 7y agoWhen people do make an effort and outline pain points, those are waved away by Rust programmers or deflected by claiming that they like said syntax choice. At the end of the day though, these tiny thing like fn, or the lifetime annotations and the many others add up to an unpleasant experience and less readable code.
- rat9988 7y agoLifetime annotations are an other ugly unreadable quirk. I'm happy to know I'm not the only one.
- pcwalton 7y agoIf Rust were an unpleasant experience, it wouldn't have users. I'm sorry that you disagree with the syntax decisions. We can't please everybody.
- blub 7y agoI'm not an extremist, the language clearly has certain advantages. At the same time I do believe it could have a lot more users if it were a more pleasant experience. If it becomes a mainstream language (like Java, C++, etc), I'd be happy to concede I was wrong. It could be that memory safety will trump ergonomics and it wouldn't be the first time that somewhat painful to use tools become very popular - see Linux, git, etc.
- FpUser 7y agoI would very much prefer function over fn , just for plain readability . Of course it is subjective but whatever.
- rezeroed 7y agofn usually appears at the start of a line following an empty line - how is it not readable? I honestly think even fn serves little purpose, other than compiler parsing. New paragraph == new function.
- FpUser 7y agoWhatever tickles your fancy. To each their own
- gpderetta 7y agoStrupstup law is relevant here: "For new features, people insist on LOUD explicit syntax. For established features, people want terse notation." fn is fine.
- jandrese 7y agoI've had the impression that Rust developers come from a more pure-math background than most language designers. People who read mathematical notation all day probably find Rust to be more natural than a typical programming language. For people coming from a traditional computer language background the number of sigils on each line is a point of pain. IMHO Rust may have tried to roll a little too much into the language. It has the air of the second system effect to it, where every good idea from every language is added together to get something that is less than the sum of its parts and you get code that is hard to decipher until you've learned a full college course worth of syntax.
- pcwalton 7y agoI designed the lifetime syntax and I'm far from having a pure math background. There aren't any sigils in Rust that C doesn't have, other than the lifetime syntax, which needs separate syntax as it's a novel feature. Can you name a specific feature you want removed from Rust?
- jandrese 7y agoI'm not sure I'd want it removed, but generics tend to be pretty horrific looking to people new to the language. An example: fn largest<T>(list: &[T]) -> T { let mut largest = list[0]; for &item in list.iter() { if item > largest { largest = item; } } I'm sure experienced Rust devs look at that and say it's fine, but that's definitely a hurdle for new developers.
- pcwalton 7y agoWhat would you want to see instead? That's pretty much the same syntax as generics in Java.
- slavik81 7y agoYou need to specify the properties of T that you use. So, that first line should be: fn largest<T: PartialOrd + Copy>(list: &[T]) -> T { https://tomtongue.com/docs/rust-wk-20.html#trait-bounds https://tomtongue.com/docs/rust-wk-20.html#trait-bounds
- rezeroed 7y agofn is great. I'm not at all mathematical as suggested by others. When I go back to Go I find myself wondering why I have to type the extra two characters.
- leotaku 7y agoI personally much prefer the smaller "fn" to "function". I started learning programming with python's "def", so maybe it comes from that.
- rat9988 7y agodef is way better than fn. you can read def at least.
- kbenson 7y agoRead def? What the point of that? You might say "def" when you see it, but you think of the concept of a function. You should be translating fn to "function" in your head or if you speak it out loud, the same way you say "plus" when you see +. How do you "read" + otherwise? It's the same for every mathematical symbol, since there is no actual way to read them, since they communicate a concept that you most likely translate into your own language in your head.
- lenkite 7y agoPrevious poster has a small point. Even I am guilty of saying 'f-n' when reading rust code alound. Kotlin is the best - all functions are fun
- saghm 7y agoI'm not convinced that the C++ way is better here; either `fn` or `function` makes it clear that you're looking at a function (and incidentally makes it very easy to search for a function with a given name in a file), whereas just having the return type and then the function name makes it ambiguous until you read further whether you're looking at a variable or a function. If I see `fn size`, I know I'm looking at a function before I get to the parentheses, but if I see `int size`, that's still ambiguous until you go a character further.
- boring_twenties 7y agoUnfortunately, one character further is not enough to disambiguate the C++ syntax: int size(); Am I declaring a function returning an int? Or defining an object of type int and invoking the default constructor?
- bschwindHN 7y agofn vs. function is probably the least of your concerns when reading and writing rust. Lifetimes, generic parameters, and complex where clauses are what will throw you. But if you spend enough time with the language it gets easy enough for these to not be a concern. I personally think it's very much worth learning.