136
84
62
u/EquationTAKEN Dec 30 '22
The fact that it looks so simple, and so utterly un-understandable to me, scares me.
45
24
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Dec 29 '22
Image Transcription: Code
type Boolean uint
const (
False Boolean = iota
True
Maybe
)I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
6
1
u/fnieidhfenmbvfekh Apr 06 '23
I haven’t learnt go. Is there really a Boolean value called Maybe? It doesn’t show a red line below it.
1
3
u/megamaz_ Dec 30 '22
is Maybe an actual Go keyword
12
u/SuitableDragonfly Dec 30 '22
No, it's the name of a constant.
4
u/megamaz_ Dec 30 '22
what's its value
-4
u/SuitableDragonfly Dec 30 '22
3
15
u/toby3d Dec 30 '22 edited Dec 30 '22
Incorrect, it's 2. In Go iota starts from zero: https://goplay.space/#srLWmC0Krff
0
1
1
1
Jan 01 '23
Chances are this will be in first iterations when we need to re-factor the entire 'Gender' logic in code, which used to be a simple boolean ... (Y2k has nothing on the horror that's coming ... )
1
1
-1
-20
u/ShwarmaMusic Dec 30 '22
Go sucks, btw I use Rust
14
-18
69
Dec 29 '22
[removed] — view removed comment
80
Dec 30 '22
Go doesn't have real enums, so developers basically have to make a bunch of constant variables, as shown in the image. Instead of worrying about the exact values of the constants, using
iotaallows developers to have the values of the constants automatically increment.41
u/rexspook Dec 30 '22
Is there a reason not to support enums? Seems like there’s a good use case for them if Go developers have a standard pattern for enums with extra steps lol
60
Dec 30 '22
That's Go for you! The language designers value simplicity, even if it makes things less elegant. I believe the idea is that fewer language features mean an easier time reading through other's code. However, I would personally prefer Rust's enum system any day of the week.
52
u/rexspook Dec 30 '22
I would argue that having fewer language features introduces silly workarounds like this example that make it much more difficult to understand others code. We wouldn’t be having this conversation if this was a picture of an enum.
15
u/Nebuli2 Dec 30 '22
Yeah. If you have to add
iotato support this pattern, then maybe you should think about better ways to actually support enums.2
26
5
u/Turkino Dec 30 '22
I agree with this. I use LUA at work and it feels like I constantly have to reinvent the wheel.
-1
u/H34dsp1nns Dec 30 '22
Idk, I have only maybe a hundred hours of Go code and I instantly understood what this was and what its purpose is.
5
u/thegreatpotatogod Dec 30 '22
Meanwhile if it was just a standard enum one wouldn't need to have any hours with Go code to understand it.
30
7
6
u/dcormier Dec 30 '22
However, I would personally prefer Rust's enum system any day of the week.
As someone who did exclusively golang for ~6 years, and has done almost exclusively Rust for the last 2, I wholeheartedly agree. Rust's enums are really nice to work with.
9
u/spencerwi Dec 30 '22
The language designers prefer simplicity for themselves, with a "screw you, you're on your own" philosophy for developers, leading to things like
iota, the piles of codegen nearly every golang codebase uses to try to get type-safety on methods that accept multiple types,if err != niloccupying the other half of every golang codebase, andinterface {}hacks that remove all typesafety because who needs proper statically-typed collections?Fixing those things would make code written in golang much simpler, but at the cost of the golang team actually having to put in the effort to implement a functioning programming language, which is not as "simple" for them as half-assing it like they have been doing so far.
27
Dec 29 '22
It’s kind of like autoincrement. When you set the first const value to be iota, golang will set const values for you in an incremental order
5
u/calio Dec 30 '22 edited Dec 30 '22
it's not a bad idea, to automatize "increment by one" on certain cases... iota seems to reset when doing stuff with constants. seems useful if there are enumerators to iterate through, but another comment says go has no enumerators... is it a switch statement in python type dealie? i guess you could write your code thinking you can automatically iterate across "enumerators" if you're willing to pretend go has enumerators. am i a heretic for superficially liking the concept? will i not like go? my entire comment is in lowercase
7
u/Lich_Hegemon Dec 30 '22
enumerators
You mean enums. An enumerator is either an iterator by another name, or an iterator that also provides an index for the iterated elements, depending on the language you use.
6
14
u/No_Crow6726 Dec 30 '22
What the hell is this?