-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: Go 2: Allow to convert bool to int #63544
Comments
Duplicate of #45320 |
If it is not to much to ask, ¿can you tell me something regarding this? I saw that this is indeed something proposed by others before me... ¿it is really complicated? |
Every language change has costs and benefits. The question is not whether the change is complicated. The question is whether the benefits of the change are worth the costs. This was discussed in #45320 and the decision was that it wasn't worth doing. We aren't going to revisit that decision unless there is new information to consider. |
Thanks @ianlancetaylor... but there are a lot of comments in previous chats and perhaps we could simplified this... let's try make a summary... shall we? Benefits
Cost * To be fill... TD;DR; Regarding performance: I intentionally leave out of the table performance affairs as they are not a primary concern regarding software development unless explicitly stated in the proposal spec. Perhaps doing this on a language could carry some heavy burden, I don't know... you may tell me. I read some comments about performance and I do not get them. |
Respectfully, we have to be able to make decisions and move on. Otherwise we will wind up spending all of our time rehashing old decisions and will be unable to make forward progress. As you say, there are a lot of comments in #45320. We considered them, we decided, and we moved on. We aren't going to return to the issue unless there is some new information that was not previously considered. Thanks for your consideration. |
The main (and only?) reason in favor for a bool to int conversion is optimization as it allows to get rid of conditional instructions which breaks pipelining. It is currently impossible in Go. I however don't think the proposal is good in that it would punch a hole in the typing compartmentalization which is a safeguard against errors. I would consider the addition of an explicit type conversion function like math.Float64Bits a better approach. It would not alter current language specification, and it would make the conversion fully explicit and readable. I expect that its use would then also be limited to where it really makes sense. |
This is easily done in Go today. For instance, this function compiles down to a single zero-extension instruction, no conditionals anywhere:
|
Hi @chmike and @randall77 regarding this proposal I moved the discussion into this golang nuts thread. In my last email there is a recap (with links and references) about this affair. To summarize
|
Proposal: Allow to convert bool expression to int, assuming that false is 0 and true is 1.
Motivation: I think is a common scenario where you have to write
count += cond ? 1 : 0
so allowing to write an expression likeint(<bool expr>)
that yields 1 or 0 will allow, in turn, to writecount += int(<bool expr>)
. I Mean. i'm pretty sure that anyone stomped into a situation where you have to count elements of a collection that fulfill a condition.... and in the concrete case of golang I guess a canonical way to model it is using the "for range" statement.. specially if that collection is a slice.Aditional Context: I ignore the complexity of this, is just a wish and perhaps a nice to have. I read the conversion section of the language spec and nothing is stated about this convertion.
Final words: Keep up the good work.
Greetings
Víctor
The text was updated successfully, but these errors were encountered: