News for hackers. Stuff that matters.
Re:Twelve Years of Go by leoc on Wednesday November 10, 2021 @02:36PM (#29179458)
If you think there's some virtue in writing verbose and inexpressive imperative code, what does Go provide in that department that you couldn't have got from Java 1.44?
Re:Twelve Years of Go by jerf on Wednesday November 10, 2021 @03:41PM (#29180445)
I have often thought that if you could travel back in time and make Java's interfaces work like Go, there would be no Go today. The first-order effects of that change may not seem like much, but the second-order effects of that change is profound. In Java, interfaces must temporally precede their implementations; in Go they don't have to. This turns out to be huge in practice. It turns out that huge swathes of all that boilerplate and frameworkitis that Java is so well known for are just trying to get around the consequences of that mistake, because all the interface-based structure has to be laid down in advance.

It isn't the only difference between the two, but I think it would have consumed enough of the oxygen of the niche Go is currently in that Go might never have been born.

In practice, I find Go to be just slightly harder than working with dynamically typed languages, rather than a huge step, and the benefits I get in return make me prefer it for almost any task above 200-ish lines. I definitely can not say the same about Java, because of this difference and the second-order effects it has on the entire ecosystem.

It is still completely practical to create a production-level Go project by just cracking open a text editor and typing "package main" into your editor and typing away. I get the impression most people would not consider that a practical way to start a production-level Java project.

Re:Twelve Years of Go by kaba0 on Wednesday November 10, 2021 @04:30PM (#29181142)
Java’s nominal typing is both better and worse at the same time - but go is not novel in that area, plenty of similar languages existed before as well, so I don’t think having it contributed to go’s success.

As for your last paragraph, I feel like we often mean something different between a production-level go and java project. Non-IDE java development is entirely possible, but I think a prod project usually means something much larger than it does in case of go.

Re:Twelve Years of Go by jerf on Wednesday November 10, 2021 @09:51PM (#29183903)
"plenty of similar languages existed before as well, so I don’t think having it contributed to go’s success."

I struggle to think of one that has risen to the heights Go has risen.

I'm a computer language polyglot and a bit of a language tourist, though not as much as some people. There's a huge churn of features out there in some language somewhere, that has never manifested in any top-level language like C++ or Java. (For instance, array-based programming has been experimented with quite a bit, but has never been in a top-grade language. The closest that I know of is NumPy.) Whether Go is a top-level language or not at this point is a matter of legitimate debate (depends a lot on your exact definition), but it's certainly knocking on it.

The closest I can name are things like Python, but there is a fundamental difference between run-time duck typing and compile-time interface conformance, although they're certainly related.

Re:Twelve Years of Go by kaba0 on Thursday November 11, 2021 @02:34AM (#29185410)
Half-telling, half-asking: isn’t type-scripts structural typing the same as Go’s, but overall much more powerful?
Re:Twelve Years of Go by jerf on Thursday November 11, 2021 @09:52AM (#29188403)
TypeScript hasn't risen to the level of Go. If you live in the JS world that may not be obvious, but in the general landscape it's not as prominent.

A lot of people make a lot of fuss over how fast the programming world moves, but I'm a bit of a contrarian on that. There's a huge amount of churn at the very small scale, but when you get to that top-level set of languages, we're actually very conservative. For pete's sake, C is still a top-level language in 2021! It's finally on its way down, but it's got a long way to go to fall out of that criterion, unfortunately.

This is why I didn't even necessarily label Go as a "top-level" language. It's only 12 years old, after. It's a whippersnapper of a top-level langauge. 25 years old makes for a young top-level language!

Re:Twelve Years of Go by Zababa on Thursday November 11, 2021 @08:33PM (#29195389)
> TypeScript hasn't risen to the level of Go.

How do you evaluate that?

Re:Twelve Years of Go by ohCh6zos on Wednesday November 10, 2021 @07:43PM (#29183024)
> This turns out to be huge in practice. It turns out that huge swathes of all that boilerplate and frameworkitis that Java is so well known for are just trying to get around the consequences of that mistake, because all the interface-based structure has to be laid down in advance.

I'm a little lost by what you mean here? In my mind the only difference between a Go interface and a Java interface is Java lets you declare them in the class signature.

Re:Twelve Years of Go by jerf on Wednesday November 10, 2021 @09:48PM (#29183878)
Java does not let you declare them in the type signature... Java requires you to declare them in the type signature. That means, the interface must precede the implementation, temporally, as in, it must exist first. In purely local development, you may do the implementation before the implementation, but until you at least have them together, the compiler won't let you claim you've implemented that interface.

That means you can't just take an image class from some JPEG library and declare an interface around its already-existing methods. That means the JPEG library has to know all the interfaces that may be useful, and declare them all first. If some of those interfaces are from other libraries, it must depend on those libraries to do it. This pressures image libraries to get together and have to declare "image processing" frameworks, which creates pressures to create all-singing, all-dancing image frameworks because these new interfaces being declared have to work for everything up front. If you get the interfaces wrong, the end-user of these libraries can't just fix them up on the fly. The framework then is pressured to undergo significant churn as it keys in on the correct all-singing, all-dancing set of interfaces to provide, either breaking backwards compatibility or having to drag along every bad decision it made for extended periods of time.

Granted, if a set of libraries does successfully run this gauntlet, the end result can be quite impressive, but it's a hell of a gauntlet to run!

This is also why it's at least a modestly acceptable Java practice to pre-emptively declare an interface for anything you think you might need an interface for later, because if you don't do it now, you'll have a harder time coming back and doing it later. I have a Java code base where darned near every class is basically duplicated, as both an interface and an implementation. I understand not everyone thinks this is good practice, but the language still pushes you in that direction even so. In Go, it simply neither good practice, nor something the language pushes you towards.

In Go, if I need to parse PNGs, I get a PNG parsing library. It just parses PNGs. The author of the library can make the best PNG library they care to, and the author of the library has no obligations to pre-declare any interfaces. If someone wants to weave this into a metalibrary, they can, and they don't have to fork the PNG library to do it, they can easily declare interfaces as they like, wrap things if they like, whatever. It's all more flexible. You're less likely to end up with that best-of-breed, all-singing, all-dancing awesome framework that is integrated and does everything in the end... but in the meantime you also get to use all the code that would have failed to finish the Java gauntlet.

In Java, because interface declarations must temporally precede all implementations, there's this huge pressure constantly pulling things into huge, all-encompassing frameworks, because all requirements are constantly being pushed up into the interfaces... the same interfaces that also have to exist first, before they can use them.

On paper, this is such a small little difference. It even sounds good... "why, of course we should have to declare conformance to interfaces? What if we accidentally implemented an interface and all hell broke loose? [1]" In reality... it's been a huge mistake.

[1]: My answer to that, BTW: http://www.jerf.org/iri/post/2954

Re:Twelve Years of Go by azth on Thursday November 11, 2021 @01:09AM (#29184962)
Java's interfaces (nominal typing) is superior for both readability as well as IDE performance. Working on a large golang code base, it's always a struggle for both the programmer as well as the IDE to find out what interfaces a given struct implements. Coding is also more tedious as it's not straight forward to add a new function to an interface and get immediate feedback at the struct declaration site about the missing functions. It's just a big mess overall.

This is of course not to mention the dangers of unintentionally implementing and interface and having bad things happen (this happened in the golang stdlib out of all places as I recall).

Languages like Scala with HKTs or Kotlin with delegates (if I'm not mistaken) solve the issue of delegating to interfaces without much boilerplate. It's just that golang authors have not been exposed to other languages since the 70s.

Re:Twelve Years of Go by Zababa on Wednesday November 10, 2021 @02:58PM (#29179807)
Not having to wrap your imperative code in classes is a big plus.
Re:Twelve Years of Go by initplus on Wednesday November 10, 2021 @03:58PM (#29180664)
Go is constantly being improved and refined compared to Java 1.44, there is a strong community of third party packages, you aren't shoehorned into the OOP box by basic language design, you get green threads in the form of goroutines while in Java land you are dealing with native threads & the issues they involve (curiously just learned Java <1.3 actually did use green threads, I suppose they were a casualty in the efforts to improve performance), the Go stdlib is much leaner but simultaneously much more useful compared to the Java 1.44 equivalent (even latest Java stdlib is missing basics like JSON!), date/time handling is sane compared to pre-Java 8 equivalent, etc. etc.
Re:Twelve Years of Go by azth on Thursday November 11, 2021 @01:14AM (#29184987)
Java is getting green threads by means of Project Loom, and value types by means of Project Valhalla.

Not to mention it has sum types and pattern matching, something not available in golang. golang doesn't even have proper enums, quite astounding really.

Re:Twelve Years of Go by kaba0 on Wednesday November 10, 2021 @04:32PM (#29181162)
Comparing a moving thing to a static one is quite meaningless, but regarding third-party packages the JVM is parallel only to the python and node ecosystems.
Re:Twelve Years of Go by ignoramous on Wednesday November 10, 2021 @02:56PM (#29179768)
Well, at some level you could say Go (pre 1.18) is Java 1.44 but with speed as a differentiator. Development speed, build speed, deploy speed, and runtime speed.

If Russ Cox ever proposes to rename Go to JavaScript, I guess no one would complain. ;)

Re:Twelve Years of Go by grey-area on Wednesday November 10, 2021 @04:08PM (#29180828)
Epic troll, but there is life outside The Kingdom of Nouns.
Re:Twelve Years of Go by Andys on Wednesday November 10, 2021 @04:02PM (#29180734)
It is lighter and faster and requires no runtime.
Re:Twelve Years of Go by kaba0 on Wednesday November 10, 2021 @04:35PM (#29181199)
Than Java 1.14? Yes. Lighter is true of current Javas as well, but faster is dependent on the program. Go can often prevent garbage from being generated in the first place, but when creating garbage is a must, Java will happily handle heaps up to a terabyte in size, and its GCs are simply the state of the art.

Also, Go most definitely has a runtime, what runs the GC otherwise?

Re:Twelve Years of Go by Andys on Wednesday November 10, 2021 @04:56PM (#29181472)
But its also faster to compile and use as a developer. And by runtime I mean there's no JVM. If you're used to Java you should probably just stick with it, but using Go is a huge relief to me.
Re:Twelve Years of Go by jhgb on Wednesday November 10, 2021 @06:43PM (#29182512)
> And by runtime I mean there's no JVM

That's an awfully restricted definition of "runtime": https://golang.org/src/runtime/