-
Notifications
You must be signed in to change notification settings - Fork 18k
operator overloading for a better decimal implementation #19770
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
We will consider everything, including this, for any future Go 2. Others have had similar thoughts. If you want to write a formal proposal, see https://github.com/golang/proposal But I've tagged this LanguageChange so we can find it in the future if/when a Go 2 happens. Thanks. |
@maj-o e.g., see https://github.com/griesemer/dotGo2016 for an implementation of operator methods |
@griesemer : Thank You! YES! Exactly as You presented at dotGo2016! @Others: you can see it at dotGo 2016 - Robert Griesemer - Prototype your design! |
(I am disappointed, maybe I am the only one - but it's harder for me to read each letter in each line of code then looking for a common syntax - and the problems are getting bigger with the time) Now we have Go 1.9 with a sync.Map - this is good in the core. But: existing code must be changed and new code invented (for reinitialisation of a map)... How beautefull and usefull this sync.Map could have been with operator methods. |
Go 2 draft design happens. I leave my feedback here: |
It would be GREAT to have operator overloading like this:
operator (a,b MyType) + (result MyType) {
result = a.Add(b) // just to show what it would do
}
This can be used for instance a native or packaged Go decimal type.
res := a + b * (c / d)
is much more readable then
res := a.Add(b.Mult(c.Div(d)))
decimals are hardly needed !
But decimals without operators are unreadable. I can also think of other types like vectors, points, maps and other types like floats or even new types like Number where it also would be great to be able to implement operators. Operators should only be daclarable in the same package or file in which the significant type is declared - so, not overridable.
If somebody wants a comfortable and precise Number type and does not care about performance, this would be easy.
Please, think about it.
Regards,
maj-o
The text was updated successfully, but these errors were encountered: