8,634 karma · joined Jun 23, 2011 (15y ago) · 7,679 submissions
comment 2y ago · link · parent
Enumeration isn't a type, it's a numbering construct. Literally, by dictionary definition. Granted, if you use the Rust definition of enum then it is a type, but that's because it refers to what we in this thread call sum types. Rust doesn't support "true" enums at all.
> The compiler can't complain when you use a value that isn't in the list of enumerations.
Well, of course. But that's not a property of enums. That's a property of value constraints. If Go supported value constraints, then it could. Consider:
type Temperature 0..1
const (
Hot Temperature = 0
Cold Temperature = 1
)
Then the compiler would complain. Go lacks this in general. You also cannot define, say, an Email type: type Email "{string}@{string}"
Which, indeed, is a nice feature in other languages, but outside of what enums are for. These are separate concepts, even if they can be utilized together.> Enums are a big thing I miss when writing Go, compared to when writing C.
Go has enums. They are demonstrated in the earlier comment. The compiler doesn't attempt to perform any static analysis on the use of the use of the enumerated values because, due to not having value constraints, "improper" use is not a fatal state[1] and Go doesn't subscribe to warnings, but all the information you need to perform such analysis is there. You are probably already using other static analysis tools to assist your development. Go has a great set of tools in that space. Why not add an enum checker to your toolbox?
[1] Just like it isn't in C. You will notice this compiles just fine:
typedef enum {
Hot,
Cold
} Temperature;
void setThermostat(Temperature temperature) {
switch (temperature) {
case Hot:
printf("Hot\n");
}
}
int main() {
setThermostat(10);
}comment 2y ago · link · parent
But, if you'd kindly come back to the topic at hand:
> That is what the discussion here is about - the way errors are handled in a language in practice, not in theory.
While I'm not entirely convinced that is accurate, I will accept it. Now, how does:
- "That said, suggesting adding exceptions to Go is about as reasonable as adding a GC to Zig."
Relate to that assertion? What does "suggesting adding exceptions to Go" have to do with a common pattern that has emerged?
comment 2y ago · link · parent
They can certainly help solve some of the same problems. Does that make them related? I don't know.
By definition, an enumeration is something that counts one-by-one. In other words, as is used in programming languages, a construct that numbers a set of named constants. Indeed you can solve the problem using that:
type Temperature int
const (
Hot Temperature = iota
Cold
)
func SetThermostat(temperature Temperature) {
switch temperature {
case Hot:
fmt.Println("Hot")
case Cold:
fmt.Println("Cold")
}
}
But, while a handy convenience (especially if the set is large!), you don't even need enums. You can number the constants by hand to the exact same effect: type Temperature int
const (
Hot Temperature = 0
Cold Temperature = 1
)
func SetThermostat(temperature Temperature) {
switch temperature {
case Hot:
fmt.Println("Hot")
case Cold:
fmt.Println("Cold")
}
}
I'm not sure that exhibits any sum type properties. I guess you could see the value as being a tag, but there is no union.comment 2y ago · link · parent
The only error-related concept the Go language has is the error type, but it comes with no handling semantics. Which stands to reason as there is nothing special about errors. Originally, Go didn't even have an error type, but it was added as a workaround to deal with the language not supporting cyclic imports.
Your pedantry is hilarious and contradictory.
comment 2y ago · link · parent
Suggesting the addition of exceptions to Go is as reasonable as suggesting the addition of loops to Rust. Which is to say that it already has exceptions, and always has. Much of the language's design is heavily dependent on the presence of exceptions.
Idioms dictate that you probably shouldn't use exceptions for errors (nor should you in any language, to be fair), but even that's not strictly adhered to. encoding/json in the standard library famously propagates errors using the exception handlers.
comment 2y ago · link · parent
Then what you are really looking for is sum types (what Rust calls enums, but unusually so), not enums. Go does not have sum types, but you can use interfaces to archive a rough facsimile and most certainly to satisfy your specific expectation:
type Hot struct{}
func (Hot) temp() {}
type Cold struct{}
func (Cold) temp() {}
type Temperature interface {
temp()
}
func SetThermostat(temperature Temperature) {
switch temperature.(type) {
case Hot:
fmt.Println("Hot")
case Cold:
fmt.Println("Cold")
}
}comment 2y ago · link · parent
Okay. What important information is lost in "XYZ is a compiler" that would be gained in "XYZ is a transpiler"?
> It doesn't hurt to have a word that is more specific than others.
It can if the intent is not properly understood. And so far I'm not sure we do have that understanding.
comment 2y ago · link · parent
I'm guessing you are talking about something else entirely, like, perhaps, decoding JSON into a struct using reflection and encountering a situation where the field names didn't match? Indeed, implicitness can bite you there. That's true in every language. But, then again, as you prefer explicitness why would you be using that approach in the first place?
comment 2y ago · link · parent
You have provided some defining properties that might allow for distinction, but you have not given any reasons for why people make a distinction.
But perhaps we can suss it out. Given the statement "Borgo compiles to Go", what important information is lost that would be saved if "Borgo transpiles to Go" was used instead?
comment 2y ago · link · parent
Bizarre in what way? If compilers are somehow different, then they mustn't target systems, as that's what your previous comment says transpilers do. Which leaves even your own classical definition to be contradictory, if they are somehow different. What does that leave?
> Yes.
But it seems you do not consider them different, which was the divergent path in the previous comment. But evaluating both the "if" and the "else" statement is rather illogical. The evaluation of both branches is what is truly bizarre here.
comment 2y ago · link · parent
What is meaningful about such a distinction?
comment 2y ago · link · parent
That's why we are here, but, frankly, I'll take ill-informed speculation over whatever the hell this is. What on earth is the point of using a discussion forum if you are going to outsource the useful words to other people? If they wanted to contribute to the discussion, they would do so themselves.
In fairness, perhaps you accidentally hit submit before you were finished?
comment 2y ago · link · parent
Even of those who do. Wealth cannot be extracted from existing wealth.
> What happens to people with no other wealth in an AI economy where labor has little value? That's a scary thought.
Will people with AI be happy to metaphorically scurry off into the forest and life alone with nothing other than their AI? So long as there is value in human-to-human social interaction, there will be value in labour. The labour may not resemble anything we can imagine today, but it will be there in some form.
And even if we assume that those with AI do go off and live life alone in the forest, those who don't have AI will still need other people in their lives, so labour will continue to hold value within that subset of the population.
Alternatively, those with AI may freely share it with all, creating a post-scarcity society. That's probably not so scary. Hell, entire societies have upended everything in hopes of being able to transition into a post-scarcity world. It is generally considered a welcome future, not something to fear.
comment 2y ago · link · parent
Just as you have demonstrated yourself. You are no doubt knowledgeable in the subject, but have completely refused to talk about it, spending all your time focused on my character. Which is to be expected, as what more are you going to learn about the topic at hand? The only thing you might stand to learn something about is me.