Better HN
topnewbestaskshowjobs
Log inSign up

randomdata

8,634 karma · joined Jun 23, 2011 (15y ago) · 7,679 submissions

Submissions

comment 2y ago · link · parent

> Isn't really a good workaround when lacking an enumeration type.

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

Okay, but how does that relate to what was said?

comment 2y ago · link · parent

So you quit the day encoding/json was written?

comment 2y ago · link · parent

    func try(fn func()) { fn() }
    func catch(fn func(any)) {
        if v := recover(); v != nil {
            fn(v)
        }
    }
    func throw(v any) { panic(v) }

    func fail() {
        throw("Bad things have happened")
    }

    func main() {
        try(func() {
            defer catch(func(v any) {
                fmt.Println(v)
            })
            fail()
        })
    }

Sorry.

comment 2y ago · link · parent

> Humans hand wrote binary for a while too hah.

Like, as in flipping toggle switches? Isn't that just an input device? They were still producing machine code from that switching.

comment 2y ago · link · parent

That's a lot of pedantry you've got there for someone who claims it is not welcome. Rules for thee, not for me?

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

> Enums and sum types seem to be related.

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

It doesn't not use exception handlers as a primary way of handling errors either, though. Go doesn't specify any error handling mechanism. Using exception handlers is just as valid as any other, and even the standard library does it, as noted earlier.

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

> That said, suggesting adding exceptions to Go is about as reasonable as adding a GC to Zig.

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

Machine code is intended to be written by humans. That was the only way to program computers at one point in time. Given a machine code target, would you say it is product of transpilation or compilation?

comment 2y ago · link · parent

> my main use case for enums is for APIs and database designs, where I want to lock down some field to a set of acceptable values and make sure anything else is a mistake

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

> In the statement "XYZ is a compiler/transpiler", it does.

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

It looks like something was lost in the middle of your comment. You open with something about it be objectively bad, but then it jumps to something about how it is subjectively bad. What was omitted?

comment 2y ago · link · parent

Thanks for your response, but the Go spec asserts that Go source is represented as UTF-8. UTF-8 is a binary encoding.

We're talking about compilers that produce something other than binary output.

comment 2y ago · link · parent

> The fact that this was a bug at all makes me fear for the rest of the code base.

The fact that the commit was accepted into a release without any changes to accompanying tests is what is most concerning. You should be afraid.

comment 2y ago · link · parent

The casing rules are quite explicit and enforced by the compiler. A build would have immediately failed on whatever mismatch you had. A few hours and you didn't even think to try compiling it?

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

> the majority of the reasons on why people make the distinction.

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

> transpiler just typically means it goes from one language i could write, to another i could write.

What possible compiler target couldn't you write? Compilers are not exactly magic.

comment 2y ago · link · parent

> Result<T, E> is required to be checked before the value can be accessed.

Which is a flaw in Borgo, at least when interfacing with Go code, as in Go both T and E should independently valid states.

comment 2y ago · link · parent

> Bizarre take.

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

> but it makes sense it's really a subset of general compiler functionality, sans binary output.

Tell us more about this compiler subset that does not produce binary output. What do they produce? Ternary? Qubits? Nothing?

comment 2y ago · link · parent

Does that imply that a compiler emits code that nothing can understand? Or are you saying that 'transpile' is just another word for 'compile'?

comment 2y ago · link · parent

All compiler outputs are understandable. I suppose you mean with the intent of it being a one-time translation? As in, like when the Go project converted the original C codebase into Go source with the intent of having developers work in the Go output afterwards and the C code to be never touched again?

What is meaningful about such a distinction?

comment 2y ago · link · parent

> You should familiarize yourself with the actual research on this topic

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

> Some will buy second or third homes

Which, again, merely trades the profit to whomever previously owned the homes. What are they going to do with the profit?

comment 2y ago · link · parent

> I guess you're thinking of people who have no assets.

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

> Buy houses and lots, keep them empty, and speculate on their value.

But then the profit is given to whomever previously owned the property. What are they going to do with it?

> Or just build their 6th mansion

That puts people to work, violating the premise here.

comment 2y ago · link · parent

Right. People will also discuss topics in order to learn.

comment 2y ago · link · parent

For extrinsic financial gain, sure, but that doesn't apply here. The only potential gain here is the possibility of learning something.

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.

1
495051
256