News for hackers. Stuff that matters.
Re:Leveraging the Go Type System by shadowgovt on Tuesday February 09, 2021 @12:00PM (#26079791)
One of Go's strengths is that it should make it easier to swing between the optimized abstraction and the less-optimized abstraction. If you start with that data represented as strings and then find yourself backed into a performance corner and need to change the representation, Go types and type-based compile-time method selection can make it a bit easier to make that change.

Even in this era of fast computers and preposterously large storage, one sometimes hits a situation where the way to get the improvements you need is to start number-representing your strings.

Re:Leveraging the Go Type System by mhh__ on Tuesday February 09, 2021 @12:31PM (#26080235)
Is this compared to a good language or (say) server-side JavaScript because the languages I tend to use allow me to do that and Go looks looks very Algol-68-y from that perspective as opposed to some hyper abstract wonder-language.
Re:Leveraging the Go Type System by shadowgovt on Tuesday February 09, 2021 @02:43PM (#26081657)
What languages do you tend to use?
Re:Leveraging the Go Type System by mhh__ on Tuesday February 09, 2021 @04:45PM (#26082756)
I work for the D foundation, so mainly D for things I get to choose.
Re:Leveraging the Go Type System by corylanou1 on Tuesday February 09, 2021 @12:03PM (#26079836)
That's a great point. Anyone who has spent significant time with Go knows how easy it is to do a large refactor (or even a minor one) due to it being a types language.

And yes, you may not start with ints, but you could easily add code for the marshal/unmarshal later on to convert those strings to ints for serialization purposes. And it wouldn't require a change to any of your other code, not to mention that if you stored these values in a database already you don't need to perform a migration either.

Re:Leveraging the Go Type System by gher-shyu3i on Tuesday February 09, 2021 @01:49PM (#26081142)
Go has many shortcomings that make it difficult and extremely annoying to do refactorings. Things like no constructors where types are declared as follows

    A {
        Field1: field1,
        Field2, field2,
    }
Now adding a new field to A would require ensuring that all code paths initialize Field3, otherwise you're going to have silent errors at runtime. This has been solved ages ago in Java and C# and similar languages by means of constructors.
Re:Leveraging the Go Type System by shadowgovt on Tuesday February 09, 2021 @02:09PM (#26081332)
A constructor is just a function though... If I add a new field to a Java class and fail to add its initialization to the constructor, I have the exact same problem because Java initializes the field to its default value when the constructor is called.

You are correct that every situation where the struct in Go is initialized "bare" would need to be addressed if a field is added, but Go considers this a feature, not a bug (and, conversely, considers "bare initialization" of structs at dozens of places in your code to be bad practice if that struct could ever grow new fields). If you're bare-initializing structs, you're comfortable using them in a "loosey-goosey" context where zero-initialized fields are permitted (or, better, useful... https://www.youtube.com/watch?v=PAAkCSZUG1c&t=6m25s). In Go, the issue of required structure is addressed by wrapping the struct in an interface and then providing a function in the package that can create an instance of the interface. Used in that way, you get something very similar to a Java class (though Go doesn't force you into the "everything is a class" paradigm that Java demands).

Re:Leveraging the Go Type System by gher-shyu3i on Tuesday February 09, 2021 @05:38PM (#26083399)
> but Go considers this a feature, not a bug

I see this dismissive philosophy in golang a lot (I'm not saying you're doing it, mind you). The entire language is full of arbitrariness. I've seen enums being dismissed by the golang team just because, without providing any meaningful arguments. Same with how nullability was not addressed in the language, contrary to how proper modern languages have tacked the issue. The excuse? "that's how the underlying machine operates". Quite meaningless and dismissive really.

Time and time again, it's been shown that the goal is to have a simplistic (not simple) language that also makes it easy to write the compiler for. This breaks down at larger scales because reality is complicated.

Re:Leveraging the Go Type System by saagarjha on Tuesday February 09, 2021 @02:26PM (#26081494)
Usually you would create a constructor without that parameter which sets the field to something backwards-compatible.
Re:Leveraging the Go Type System by stouset on Tuesday February 09, 2021 @01:06PM (#26080642)
This perspective ignores the fact that there is no shortage of typed languages that don’t have all the—in 2021—inexcusable downsides of golang.
Re:Leveraging the Go Type System by morelisp on Tuesday February 09, 2021 @02:22PM (#26081464)
There is unfortunately a shortage, still in 2021, of languages that have a null set of inexcusable downsides.

I will trade - unhappily - ADTs for value types, automatic memory management, some language-level concurrency support, a compiler that builds our largest project in under two minutes, and a community large enough I can spend my time training new hires on fundamentals and business problems and not tool onboarding.

Re:Leveraging the Go Type System by pjmlp on Tuesday February 09, 2021 @05:04PM (#26082978)
.NET Native, OCaml, Eiffel, Common Lisp, D, Nim just for starters.
Re:Leveraging the Go Type System by kaba0 on Wednesday February 10, 2021 @08:50AM (#26088968)
Value types are almost there in Java, but without deliberately trashing the GC you can get away without them, and it has all the other qualities (and will have ADTs as well, sealed classes are already in preview)