Earlier quoted context omitted.
Exactly. Someone could always connect to your program with a debugger and modify the instructions are being run, and that's why you need to regular runtime checks of the validity of your program text. If you want to handle people actively trying to undermine the assumptions your program is making, you can't leave out easy to replicate cases like 'gdb attach', obvious, non-accidental use of the type system, and other…
That doesn't make any sense to me. Most instructions are not atomic, so even if you had runtime checks something like a debugger could still inject invalid state in between your checks, making them ineffective. If real-time code injection is your threat model, I don't see how runtime checks would get you anywhere.
Compile-time safety for enumerations in Go
61–70 of 116 posts
Re: Compile-time safety for enumerations in Go
#62 type ColorWrapper struct {
color.Color
...
}
ColorWrapper will implement color.Color. I don't know what the point would be, but another way to break the compile-time type safety.Re: Compile-time safety for enumerations in Go
#63Re: Compile-time safety for enumerations in Go
#64I would be interested to read bug reports from people who thought they had a complete enumeration but learned in production that their enumeration was incomplete. I've never seen it myself.
Re: Compile-time safety for enumerations in Go
#65Go doesn’t have type-safe enums in the language? That’s wild, even C compilers have this feature now (optionally), and then there’s Rust/Swift’s capabilities.
Re: Compile-time safety for enumerations in Go
#66Go doesn’t have type-safe enums in the language? That’s wild, even C compilers have this feature now (optionally), and then there’s Rust/Swift’s capabilities.
Re: Compile-time safety for enumerations in Go
#67Go doesn’t have type-safe enums in the language? That’s wild, even C compilers have this feature now (optionally), and then there’s Rust/Swift’s capabilities.
Welcome to Go. “Wait, Go doesnt have X?” I’m convinced its an incomplete language masquerading as a simple one.
Unless you mean: is it enough of a language to be useful for its intended usages? In which case my decade of paychecks would like to let you know that it is, in fact, sufficiently complete for many business needs.
Re: Compile-time safety for enumerations in Go
#68Earlier quoted context omitted.
> If your module relies on compile time checks for validity, ...then it's broken, because the Go compiler, factually, cannot (in general) check or enforce the validity of specific values. > there's no reason for you to also include runtime checks. Other developers breaking your defined contract is not your responsibility, it's not even a bug. It is absolutely the responsibility of the function func PrintColor(c Color…
It’s actually not and is one of those Java isms that have made its way into generalized software engineering. If I write a function that takes Foo as an argument. I have a Foo implementation exposed elsewhere in my program. It is absolutely expected that I mean MY Foo, not your Foo. If you pass me your Foo, you will get unexpected results that are not a bug, not a side effect, not my responsibility. It’s yours, the c…
Of course it is! If you provide an API that takes a Color, and you define valid Colors as exclusively Red, Green, and Blue, then you are absolutely responsible for validating input Color values and rejecting anything which is not Red, Green, or Blue. If you delegate that responsibility to the caller, then your API provides no meaningful encapsulation, and isn't a useful abstraction -- it's entirely leaky. No bueno.
Re: Compile-time safety for enumerations in Go
#69Earlier quoted context omitted.
The article is titled "Compile-time safety for enumerations in Go" but my example demonstrates that this is not the case.
It is the case under certain conditions. Casting is by definition an escape hatch.
Re: Compile-time safety for enumerations in Go
#70Earlier quoted context omitted.
> I still feel as though languages without sum types are missing an important data and state modelling tool. That's because they are. jerf subtly shifts the point to one they can criticise, but it does not change the basic fact that sum types are a critical tool which is just... missing. There's probably no tool which can't be misused, even the humble boolean, that's not an issue with the tool, and pointing that out…
Where I'd disagree is that they are a tool, not a critical tool, and they aren't missing from Go, they are simply not the preferred choice. You can cover 75% of the use cases with this approach. It is not 100% of the use cases. But there isn't a language where you can cover 100% of the use cases with 100% effectiveness, which is why we don't have and never will have The One True Language. Moreover, Go seems to attrac…
Which other side? Product types (aka structs)? I don't think there are any languages with Sum types that don't also include Product types.