Comments (5)
Your point is right: I was thinking in terms of good ol' mathematical plus and minuses, when one could actually have the .add
method on their class do a multiplication and the .mul
method do an addition, making my argument pointless.
I wasn't thinking about the fact that the infix operators can have different meanings depending on their uses in the user code, these different meanings making any grouping irrelevant.
Thank you for pointing me this out!
from rfcs.
@EpicEric your point...
Even in our regular math system, they are not the same thing. (a + b + d) - c could have rounding errors with big floats and give a different result than ((a + b) - c) + d, due to an intrinsic limitation of numerical representations in CPUs. Exhibit B.
Is an interesting one. If you are up for it, I think it would be interesting to add the general discussion to the operator precedence section of the tutorial. Would you be up for PRing that?
from rfcs.
I have some points against your first suggestion, which I will express below. As for your second suggestion, it makes perfect sense to me.
TL;DR: There are several cases where infix operators grouping can lead to bugs or confusion.
Grouping different infix operators would implicitly assume that they have the same order of precedence. This would create some arbitration as to whether operators have the same precedence or not, and:
The problem with this is that the programmer has to remember the order and people arenβt very good at things like that. Most people will remember to do multiplication before addition, but what about left bit shifting versus bitwise and? Sometimes people misremember (or guess wrong) and that leads to bugs. Worse, those bugs are often very hard to spot.
This also applies to "+" and "-", which may not have the same precedence to another person in another culture, or even with a different math system. Say that I want to create a module that uses these operators, where they aren't directly reversible operations (let's say, "OR" and "NOR" on U32 instead of booleans, respectively). This would be a case where ((a + b) - c) + d
and (a + b + d) - c
mean two different things, and infix operator grouping would silently cause bugs. Exhibit A.
(Note that this issue doesn't happen when there's only one type of infix operator, because the structure of the code itself already implies left-to-right ordering, and an operator cannot have a different precedence than itself.)
Even in our regular math system, they are not the same thing. (a + b + d) - c
could have rounding errors with big floats and give a different result than ((a + b) - c) + d
, due to an intrinsic limitation of numerical representations in CPUs. Exhibit B.
For these reasons, I agree with the language's design decision to keep any kind of operator precedence out of the syntax, for the sake of avoiding potentially unmaintainable code.
from rfcs.
Please split these into two different issues as they are two different issues. Also please note, that these are issues which means you would be looking for conversation and possibly someone to write an RFC for either issue. Nothing would be done one way or another without an actual RFC.
from rfcs.
Opened a new issue, I guess this issue can be closed
from rfcs.
Related Issues (20)
- Create RFC for collection initializers HOT 2
- #suggest Add uniform coding
- "not match" and "not if" HOT 2
- Reference consumption and field extraction
- Request: Use primitives methods as lambda calls HOT 3
- Request: Add pipeline operator HOT 11
- Hung TCPConnection can interfere with Pony runtime shutdown HOT 1
- Changes to Auth implementation HOT 7
- Mark RFC repository as a release with any implemented features HOT 1
- Expand or extract logging package from stdlib HOT 3
- Missing mechanism to pass/receive struct values into/from FFI C functions HOT 9
- [stdlib] Add an option for thousands separator to package "format"
- Syntax sugar to assigning a constructor argument to an instance variable and to add the keyword this (or self) HOT 3
- implement cond from Elixir as clean alternative to if / elseif / else HOT 9
- Incorrect division by 0 (1 / 0 -> β, in Pony 1 / 0 == 0) HOT 1
- Improve Range and Reverse
- Add StdStream error reporting mechanism HOT 3
- access symbol of private fields is wrong HOT 1
- proposal syntax else ... then for else keyword in conditional branches HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rfcs.