-
Notifications
You must be signed in to change notification settings - Fork 213
Infix function #1087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
After this, make operators proper functions, so, for example |
The big issues here are:
Dart currently combine both for operators. They have special grammar rules that both ensure that If we allow any identifier to be used as an infix operator, then we need to parse Dart is in the C-syntax family (and, e.g., Kotlin is not), which means that adjacent identifiers only occur in declarations. #607 is much more likely. |
I understand the appeal, but I don't think this feature carries its weight. It eliminates some punctuation, but that's really all it accomplishes. In return, it opens the door to what can be very difficult to read code. This is valid Scala code: ape bat cat dog eel fox How many readers at a glance can tell which of those identifiers are receivers, parameters, or methods? One of the nice things about Dart (and most other languages) is that even if you don't know what various identifiers resolve to, you can at least mostly visually parse it and understand the nesting structure correctly. I wouldn't want to give that up. |
Having ability to do something doesn't means encourage use that for everthing. if someone use infix function/operator override to writing code like
that means he/she what that. The author of code should be responsible for what he/she has written not the designer of language. As far as I known Kotlin's ecosystem doesn't appear lots of infix override, ever infix I met is just perfect when it is be used. For more, your |
Being able to add an
infix
keyword before methods in order to be able to use them likea method b
instead ofa.method(b)
would make the syntax cleaner in cases where botha
andb
have the same role/importance in the operation, such as in most mathematical forms.In contrast to #607, this feature request doesn't aim to allow any arbitrary character as operators but instead only the usual method identifiers. Here are some examples of how the syntax could be used:
vec dot otherVec
instead ofvec.dot(otherVec)
.1 to 5
or2 until 5
instead of1.to(5)
and2.until(5)
, just like in Kotlin.The text was updated successfully, but these errors were encountered: