News for hackers. Stuff that matters.
Re:Twelve Years of Go by jrockway on Wednesday November 10, 2021 @01:59PM (#29178852)
A good twelve years. Go really changed the way I think about programming. I used to be excited by programming language features instead of what problem I was actually trying to solve with programming. I'd spend hours condensing 10 lines of perfectly working code into 1 line of the most concise text possible; huffman encoded better than even gzip could imagine. And I'd feel great about it. I'd imagine people reading it and thinking "wow, there's no way I'll ever be as smart as jrockway, I should nominate him for Extreme Excellence And Awesomeness award!" Sadly, there is no such thing. Go taught me that it's just structs, for loops, and if statements, and if you want someone to be impressed, they should be impressed by what the program does for them, not what language features you used to implement it.

It has also ruined other programming languages for me. "go get" doesn't print 30 lines of text telling me that a new minor version of "go get" is available, and that I should stop what I'm doing, rm -rf node_modules, upgrade it, and then resume what I'm doing. It just pauses for a bit, and then I have the library. (I also love reading about the node community's push to make installing libraries not run arbitrary code on your machine. Yeah, I've been doing that for years with Go. It's great. I can use a library and it can't print a "hire me!!!" ad at install time. What an innovation!)

I also remember struggling for years with not being able to run other people's software. There was an RPM package, but not a Debian package, so I have to build it from source. ./configure; make; oh no, the c compiler I have can't compile this code. With Go, you can just emit a binary for every supported platform dump the binary somewhere, and everyone in the world can download it and run it. No installing packages, no finding the right version of Go (that doesn't exist in your Linux distribution because they never ship up to date versions of programming languages). Just software, running, forever.

It's really good stuff. Go is the tool that lets me make software, and not worry about bullshit. And that's revolutionary, even 12 years later.

Re:Twelve Years of Go by throwaway894345 on Wednesday November 10, 2021 @02:51PM (#29179681)
Agreed. It still surprises me that so many other languages fail at the fundamentals (minimal learning curve, static binaries, fast builds, reproducible dependency management, great tooling, great stdlib + ecosystem, etc) and yet many devotees of those languages have positively hyperventilated about Go's error handling and type system for 12 years. Go is finally getting generics and I'm sort of cautiously excited about it (like I was when Apple added the TouchBar to MacBook Pros), but any net benefit is going to be positively negligible in comparison to the degree in which Go raised the bar on the fundamentals.
Re:Twelve Years of Go by kaba0 on Wednesday November 10, 2021 @04:23PM (#29181031)
I’m not arguing that there are languages where the state of tooling is bad to say the least, but how did Go raise the bar compared to something like Java or C#, the actual “blue-collar” languages?
Re:Twelve Years of Go by throwaway894345 on Wednesday November 10, 2021 @04:46PM (#29181361)
There's a lot to like about Java and C#, but here are a few things that Go improved upon that spring to mind. Note that in some cases, Java and C# may have caught up in the interim. Note also that some things (e.g., low-latency GC) understandably weren't available from day 0 in Go, but followed quickly:

* Static binaries by default

* Single, straightforward build system (no DSLs)

* Single, ubiquitous code formatter

* Minimal learning curve

* Zero-work package publishing

* Zero-work documentation generation and publication

* Testing framework out of the box

* Production-grade HTTP server out of the box

* Low latency GC out of the box

More generally, C# and Java have always seemed to have a philosophy of "make everything as abstract and configurable as possible, and make the user understand every configuration option in order to do anything (overwhelm the user with configuration)". Granted, I haven't used C# or Java seriously since Go was open sourced, so it's possible that these are among the things that improved in C# and Java following Go's release.

Re:Twelve Years of Go by sangnoir on Wednesday November 10, 2021 @07:39PM (#29182995)
> how did Go raise the bar compared to something like Java or C#, the actual “blue-collar” languages?

For me, Go being combination of being well-thought-out, opinionated and batteries included took away the futile fanboi flamewars/bike-shedding: JBoss or WebSphere? Tabs or spaces? Struts or Spring?

For these reasons and more, Go is offers a more pleasant experience when working in a team. When reading code other's wrote,I encounter fewer surprises in the logic and project structure. Go codebases are easier to grok, IMO.

Re:Twelve Years of Go by new_stranger on Wednesday November 10, 2021 @02:24PM (#29179281)
> I'd spend hours condensing 10 lines of perfectly working code into 1 line of the most concise text possible

Which is also the hardest part of convincing people to use Go for me: "Why can't I just .map()/.filter()/.find()?" followed closely by "Why do I always have to check for errors?"

What is odd to me is that while yes, my Go code is more verbose than my node services - I always end up writing less Go for the same thing.

Re:Twelve Years of Go by jerf on Wednesday November 10, 2021 @03:36PM (#29180381)
My non-Go code is starting to look more like my Go code.

One of the things Go taught me is that I was not being as careful about my errors as I should be. It can be argued that exception-based handling provides you a nice baseline default, but it makes it way to easy when doing network or system-type programming to thoughtlessly default to that, when you need to be thoughtfully defaulting to that.

With sufficient care, exception-based programming and errors-as-values converge in the end anyhow in "code that treats errors correctly". But my exception-based code is a lot more informed by the errors-as-values approach now; a lot more try statements with catch statements that actually do something.

Even Haskell's very nice Either monadic handling can make it too easy to be in the heat of the moment and not thinking about what the errors actually mean and what I can do about them.

I don't think it's appropriate for every domain, which is why I qualified the code I tend to work on. But in those domains I'm thinking a lot more about how every single line of code can go wrong rather than leaning on default exception-based handling and expecting it all to work out.

Re:Twelve Years of Go by vlunkr on Wednesday November 10, 2021 @03:51PM (#29180577)
> One of the things Go taught me is that I was not being as careful about my errors as I should be.

I identify with this so much. Especially when dealing with external things (file system, database, network) things can go wrong at nearly every step. And yeah, that means you have to check errors at every step, but it forces you to think about how you want to handle them, and what message you want to propagate when they happen. As a result, my Go code has very few unexpected errors in production.

Re:Twelve Years of Go by new_stranger on Wednesday November 10, 2021 @04:08PM (#29180836)
Hard to overemphasize this. Handling errors is similar to the benefits that writing tests provides - slower upfront, but a more stable product gets shipped.

Handling errors everywhere means problems are already solved before they happen. No 1 am pagerduty alerts because we didn't consider what would happen if a DNS server hung until we timed out and thought just wrapping in a try/catch and crashing was a good idea.

Re:Twelve Years of Go by closeparen on Wednesday November 10, 2021 @06:46PM (#29182533)
Things can go wrong at every step, which means each collection of fallible steps carries with it a combinatorial explosion of successes and failures. Do 5 fallible statements in sequence and it's 5+4+3+2+1 = 15 mock expectations you need to write. This tedious enumeration exercise is the majority of the time that goes into writing Go programs, for me at least.
Re:Twelve Years of Go by boloust on Wednesday November 10, 2021 @07:35PM (#29182972)
Most of the time, you'll return early after an error.

To get into a situation where you'd need to handle n! cases, you'd need to keep running the statements after a failure, and then collate and return all the errors at the end.

Not sure why you'd want to do that. You'd definitely need to go out of your way to do something like this, and probably start asking yourself why you're doing this pretty early on. Plus it would flat out refuse to compile in some cases where there are dependencies between the statements.

Re:Twelve Years of Go by closeparen on Wednesday November 10, 2021 @07:42PM (#29183020)
It’s + not * in that example.
Re:Twelve Years of Go by boloust on Wednesday November 10, 2021 @08:07PM (#29183222)
Ah, okay. In that case it becomes

  {n + 1 \choose n - 1}
What code are you writing that results in this set of possibilities?
Re:Twelve Years of Go by jerf on Wednesday November 10, 2021 @09:58PM (#29183965)
I have some code where I use multierrors and collect everything into one big error (I highly recommend this for "validation"-type code, you should generally return all errors not merely the first), but what code are you writing where you're running 5 statements unconditionally but need to handle nearly-arbitrary combinations of them failing, and multierrors aren't what you need?
Re:Twelve Years of Go by closeparen on Wednesday November 10, 2021 @10:09PM (#29184043)
If you have 5 statements like "if err := doThing(); err != nil { return err }" then you need to simulate the success of all 5, success of the first 4 and failure of the last, success of the first 3 and failure of the 4th, success of the first 2 and failure of the 3rd, etc.
Re:Twelve Years of Go by morelisp on Thursday November 11, 2021 @07:46AM (#29187305)
For a total of six cases to deal with. Not 15.
Re:Twelve Years of Go by closeparen on Thursday November 11, 2021 @12:20PM (#29190456)
I said 15 mock expectations, not cases.
Re:Twelve Years of Go by morelisp on Thursday November 11, 2021 @01:47PM (#29191485)
If all five of those things also need to be independently mocked, you're mocking too much and your mocks suck.
Re:Twelve Years of Go by closeparen on Thursday November 11, 2021 @03:51PM (#29192995)
If they're not mocked it's an integration test. Integration tests are welcome as a supplement to unit tests, but unit tests are table stakes.
Re:Twelve Years of Go by morelisp on Friday November 12, 2021 @03:08AM (#29197245)
An automated test suite is table stables. If you can achieve correct, maintainable code better with functional or integration tests than unit tests, you should.

There is no hard technical line between "unit test" and "integration tests", it's a semantic question of how you define your units. Even if do you take a tiny, restrictive definition of your units, you could still use a fake or stub instead of a mock.

https://martinfowler.com/articles/mocksArentStubs.html

To get very specific for Go, we use testify suites, tend to set up fully functional stubs in `SetUp`, and then test cases either use them to verify happy paths, or `s.BreakStep1()` in one test, `s.BreakStep2()` in the next, etc. So in this case we would write a total of five extra lines for the five possible ways to break.

Re:Twelve Years of Go by closeparen on Friday November 12, 2021 @03:05PM (#29203946)
I think that is a fair opinion and my life at work would be better if others shared that opinion. Go however does officially stake out the opposite position: coverage only "counts" if the test is in the same package as the unit under test.
Re:Twelve Years of Go by uncomputation on Wednesday November 10, 2021 @08:21PM (#29183330)
Go’s error handling is a strange this to praise considering it is entirely possible to ignore it without warning and the way to check error kinds was bolted on through type assertions when errors are supposed to be values in Go. Error kinds are important especially in network programming when the error can be dozens of different things. Compare this to something like Rust or Haskell which force you to handle errors and their variants.
Re:Twelve Years of Go by Thaxll on Thursday November 11, 2021 @09:41AM (#29188283)
Once again Rust does not force you to handle errors, you can ignore errors in Rust and it will compile. I can't say for Haskell but I doubt there is a language that forces you to handle error.

let _ = openFile()

Error ignored, it does compile, it will probably ends badly.

As for network error: https://pkg.go.dev/net#OpError

Re:Twelve Years of Go by Karrot_Kream on Thursday November 11, 2021 @12:15AM (#29184670)
Pretty much every form of Go tooling warns you when you ignore an error. If you only choose to run "go build", yes you can ignore it, but a simple "go vet" call and it'll be plain as day.
Re:Twelve Years of Go by kamaal on Thursday November 11, 2021 @01:32AM (#29185077)
Certain things need to be available out of the box.

The whole point of a programming language is to make the programmers life easier.

By now decades of exposure to programming languages have made try/catch the standard way of working with errors. Forcing the programmer to guess issues, when the compiler/runtime could be doing it- IMO is just plain waste of human labor. And for even medium to large applications is a pointless exercise.

Re:Twelve Years of Go by azth on Thursday November 11, 2021 @01:00AM (#29184909)

    a, err := foo() // oops, unhandled error
    err = bar()
    if err != nil { ... }

or

    fmt.Println("...") // oops, unhandled error
or more insidiously

    err1 := foo()
    if err1 != nil { ... }
    err2 := bar()
    if err2 != nil { return err1 } // oops
Re:Twelve Years of Go by Karrot_Kream on Thursday November 11, 2021 @01:25AM (#29185039)
In the first and the last case, it seems obvious to me where the error is. An obvious code smell caught in review. The second error, yeah, but lots of languages don't enforce error handling around printing to stdout, and even though Rust does in theory, in practice everyone just unwraps it and moves on with their day.
Re:Twelve Years of Go by azth on Thursday November 11, 2021 @01:47AM (#29185147)
> but lots of languages don't enforce error handling around printing to stdout

They do, they throw exceptions.

> In the first and the last case, it seems obvious to me where the error is

The last case is especially insidious. I've seen it in production several times now. Very easy to miss. Particularly when refactoring/copy pasting code (which you have to do a lot of in golang).

Re:Twelve Years of Go by ohwellhere on Wednesday November 10, 2021 @03:51PM (#29180585)
This is exactly my experience. Being forced to handle so many more errors showed me how much error handling I was inadvertently eliding in other languages!
Re:Twelve Years of Go by JoelMcCracken on Wednesday November 10, 2021 @03:54PM (#29180614)
I think this is for sure the first time I have ever heard someone say that Haskell makes it too easy to handle error cases.
Re:Twelve Years of Go by Karrot_Kream on Thursday November 11, 2021 @12:12AM (#29184649)
I've used Scala in production codebases and it was common to just "let the EitherTs handle the exceptions". What ended up usually happening was swallowed exceptions that nobody bothered to handle and log because it was much less idiomatic Scala/FP to actually log what happened underneath than it was to return the first error that happened by short circuiting the EitherTs in for/yields (Maybe and do notation, for Haskellers). So we'd get 5xxes and log lines like "row not found" and have absolutely no idea why.

I see a lot of the same issues in Rust code today FWIW. People just keep bubbling up errors and at the toplevel say "fuck it" and dump them, without _actually_ building a reasonable error chain to offer the programmer a story behind how the error happened. The fact is, error handling in any language is tedious. Whether you do it with a sum type, a product type, or Go's error values, either way there's going to be lots of verbosity and boilerplate.

Re:Twelve Years of Go by jerf on Wednesday November 10, 2021 @09:54PM (#29183936)
To be more precise, it is the language that makes error-as-values so easy that it actually strays over into "as easy to forget about errors as exception-based handling".

You can successfully build huge chains of code that are just blindly passing errors up without adding any context about where they happened or anything in a way that even Rust can't compete with.

Haskell mitigates this issue by also having one of the more clever ways of dealing with errors, if you start getting into monad transformers or some of the advanced stuff, so it's not all bad. But it definitely can make it so easy to "handle" errors that you just forget about them.

Re:Twelve Years of Go by initplus on Wednesday November 10, 2021 @03:46PM (#29180522)
I'm a huge go proponent, but I do think the lack of map/filter/find etc. is a big downside to the language. I know how to write for (if item == myItem...) or a for (if item > max...) but it feels like a colossal waste of time every single time I write one of these loops.

Go would benefit a lot more from some basic slice manipulation tools compared to features like generics that have actually made it into the language.

The error handling I don't find so frustrating - it's great that it explicitly marks at the call site which functions can potentially error. It's like a working version of an inverse noexcept from C++. I do wish they would take a leaf out of swifts book though, with the try keyword. In practice error handling flow in my go programs is identical to using exceptions, it would be nice to have some helpers to make this default less verbose without losing the ability to distinguish at the call site which calls are error-y.

Re:Twelve Years of Go by grey-area on Wednesday November 10, 2021 @04:05PM (#29180780)
I imagine they'll add map/filter/find after generics are in. It's pretty easy to define some slice types though which include those in the meantime, type Slice []string and add some functions then just use your new type for collections.
Re:Twelve Years of Go by ohCh6zos on Wednesday November 10, 2021 @07:37PM (#29182985)
I suspect but do not know that multiple return values in a function combined with the inability to write functions against multiple return types like (T,error) will limit the usefulness of traditional iterators in Go. I'd love to be proved wrong as they'd really clean up my codebase though.
Re:Twelve Years of Go by grey-area on Saturday November 13, 2021 @03:11AM (#29208269)
Depends what you're doing I guess, not everything needs to return an error, and errors can be accumulated and stored during certain operations and dealt with at the end.
Re:Twelve Years of Go by fpoling on Wednesday November 10, 2021 @02:56PM (#29179765)
Most perceived verboseness of Go comes not from the language or libraries but from the formater that does not allow to compress 3 lines of the error check down to single

if err != nil { return err }

Re:Twelve Years of Go by stouset on Wednesday November 10, 2021 @04:53PM (#29181436)
Worse,

    if res, err := actually_important_bits(...); err != nil {
        return nil, err
    }
The actually important bits are hidden in the middle of line noise. In the "common case" where `actually_important_bits` is just a simple function call it's not necessarily as bad, but the problem is when you have ten successive instances of this and one is slightly different. It's impossible to notice the important difference at a glance.

For an industry that is just starting to understand that code is read hundreds of times more often than it's written, golang fails at the few things we actually know for certain about what makes it easier to understand code at a glance.

Re:Twelve Years of Go by jrockway on Wednesday November 10, 2021 @07:03PM (#29182677)
If you're using `res`, then you aren't going to scope it to the `if` statement. That is maybe another problem, sometimes you have to do this:

    res, err := actuallyImportantBits(...)
    if err != nil { 
        return nil, fmt.Errorf("actually important bits: %w", err)
    }
And other times you have to do this:

   if err := actuallyImportantBits(...); err != nil {
       return nil, fmt.Errorf("actually important bits: %w", err)
   }
The problem here is that you really don't want "err" to leak to the outer scope, so the second case is preferable from an absolute reliability and least-surprise perspective... but you can only do that in certain arbitrary cases. I think it's a bit of a wart.

You can certainly handle "res" in an else block, or even write "err == nil" and handle it there, but that is surprsing. I would say it's simply not done, ever, but the Go codebase itself does it (src/go/parser/interface.go.ParseDir was the first example I found; but my search returned many screenfuls of candidates so there are probably more cases lurking in there).

The fact that you have a choice is not ideal, basically.

But, having actually important bits in if err := ...; err != nil {} blocks is not detrimental to readability. You will know how to read that after 5 minutes of reading any Go program.

Re:Twelve Years of Go by jerf on Wednesday November 10, 2021 @10:00PM (#29183985)
I almost never use that in my code, I almost always use

    res, err := ...
    if err != nil {
        return nil, fmt.Errorf("...: %w", err)
    }
for that exact reason. This doesn't scan any worse than any other text-based code. (Page in the people selling visual programming here.)
Re:Twelve Years of Go by Zababa on Wednesday November 10, 2021 @04:04PM (#29180763)
> if err != nil { return err }

I'm far from a Go expert, but I feel like this line is a bit pointless, especially if you write it a lot. At this point, why not just not handle the error, or panic?

Re:Twelve Years of Go by boloust on Wednesday November 10, 2021 @07:45PM (#29183041)
Because when you're writing a reusable, self-contained function, you often don't know enough of the context to "handle" the error.

Let's say you've got a function that reads from a file. If the file doesn't exist, what do you do? That entirely depends on the context the function is called in. If it's in a web server, you might return a 404. If it's a background task polling for some data, you might sleep for a while until the file is uploaded. Or you might want to create the file yourself.

Re:Twelve Years of Go by jhgb on Wednesday November 10, 2021 @10:56PM (#29184277)
Common Lispers in the back are excitedly waving their hands and whispering: "Restarts! Restarts!"
Re:Twelve Years of Go by closeparen on Wednesday November 10, 2021 @04:10PM (#29180860)
The community strongly discourages panic.
Re:Twelve Years of Go by Zababa on Wednesday November 10, 2021 @04:13PM (#29180904)
I think a panic is still better than a chain of if err != nil { return err } that bubbles up and does nothing. Of course the best solution would be proper error handling but not everyone does that (and it's not always obvious what to do).
Re:Twelve Years of Go by merb on Wednesday November 10, 2021 @04:49PM (#29181394)
and most of the time you can't handle it anyway. I mean consider you are having a database query and it fails because the connection error'd (network split). what to do know? restart the network switches and wait? of course not in http you will just print a 5xx err and hope it comes back. in go you need to bubble up these errors to your middleware and handle it there.
Re:Twelve Years of Go by Karrot_Kream on Thursday November 11, 2021 @12:07AM (#29184616)
If this is seriously what you do when something underneath you fails, then you aren't writing in the domain of software where errors really matter, and you're probably better off in a language that has a gigantic try/catch handler around everything. In that case you may as well just log (or not) and ignore the error in Go as well then.

At high scale, you want to perhaps try your query a few more times, backing off exponentially, maybe even round-robining (or more complicated load balancing) among different targets. Throwing up your hands and 5xx-ing a request that easily is not something you can afford at high scales of traffic where small outages happen _all the time_.

Re:Twelve Years of Go by merb on Tuesday November 23, 2021 @06:52PM (#29325184)
> At high scale

so basically you mean that this only applies to like 0.001% of all websites/apps.

thus it's stupid to do it. I mean even than you would have an error that you need to bubble up or circuit break it somwhere but probably not at this layer.

also KISS and MVP, never ever overcomplicate something when you do not know anything yet, so most people don't need to built for scale at day 1 and it also is stupid to do it.

Re:Twelve Years of Go by Karrot_Kream on Tuesday December 07, 2021 @03:55AM (#29470360)
You can get off-the-shelf libraries that do this for you with zero-effort sane defaults. Most of them let you tweak the settings. I'm talking about Python's `requests` and Rust's `reqwest` here btw, two of the most popular HTTP client libraries out there. Python's `urlopen3`, which `requests` uses, exposes options for backoff strategies. `aiohttp` has a lot of these parameters as well. Unfortunately Rust's equivalent, `hyper`, isn't nearly as ergonomic/easy to use.
Re:Twelve Years of Go by closeparen on Thursday November 11, 2021 @12:29PM (#29190584)
That’s something new handle as close as possible to the outbound client, which is several layers in from the inbound request. Much of it is in gRPC middlewares, so by the time a gRPC client returns an error to the gateway it’s already over.
Re:Twelve Years of Go by sangnoir on Wednesday November 10, 2021 @07:43PM (#29183025)
At the very least, you have to log that error.
Re:Twelve Years of Go by closeparen on Wednesday November 10, 2021 @10:12PM (#29184062)
Our coding convention (and I happen to agree) is that the outermost layer to touch the error is the one to log it. In this case the HTTP handler, or perhaps a gRPC middleware. You don't want to be logging errors as you propagate them, or the logs will show the same error at a bunch of different call sites vs. one complete picture of what happened.
Re:Twelve Years of Go by ohCh6zos on Wednesday November 10, 2021 @04:37PM (#29181233)
A huge issue with Go is ‘idiomatic’ Go.
Re:Twelve Years of Go by throwaway894345 on Wednesday November 10, 2021 @02:58PM (#29179796)
If this is the case, I think the fault here lies with flawed perception and not the formatter.
Re:Twelve Years of Go by fpoling on Wednesday November 10, 2021 @04:44PM (#29181336)
The formater in many cases essentially doubles the number of lines. That requires to scroll much more frequently than with more compact formatting.
Re:Twelve Years of Go by throwaway894345 on Wednesday November 10, 2021 @04:53PM (#29181440)
I understand, but I take issue with the implication that compression makes code more readable.
Re:Twelve Years of Go by pxue on Wednesday November 10, 2021 @03:50PM (#29180566)
Compressing this into 1 line provides absolutely nothing for the reader, in fact, it absolutely takes away reability.
Re:Twelve Years of Go by The_Colonel on Wednesday November 10, 2021 @03:54PM (#29180621)
Readability absolutely suffers when almost everything you see on your screen is boilerplate.
Re:Twelve Years of Go by thatswrong0 on Wednesday November 10, 2021 @04:17PM (#29180951)
Seriously. I see so many functions in my code see that consist of 1 line of thing I actually care about followed by 3 lines of boilerplate if err not nil… over and over again.

IMO if Go didn’t have its tooling, no one would care about it.

Re:Twelve Years of Go by pxue on Wednesday November 10, 2021 @06:17PM (#29182294)
i have the completely opposite take.

every if err != nil; return err let's me mentally draw a line in the sand and not worry about exception handling for code above that line. It lets me start fresh and restart my mental model with the line of codes below the error handling block.

it doesn't take years of writing Go to understand this, all you need is a open mind to how Go does things.

Re:Twelve Years of Go by thatswrong0 on Friday November 12, 2021 @04:36PM (#29204827)
> It lets me start fresh and restart my mental model with the line of codes below the error handling block.

My code is almost exactly:

err := doThing()

if err != nil {

  return err
}

err = doAnotherThing()

if err != nil {

  return err
}

etc.

There's no need for me to "start fresh". Each line of actual stuff doing might return an error which needs to be returned. That's it. It's a complete waste of space and inhibits readability to absolutely no benefit. And this is extremely common across our code base.

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/

Re:Twelve Years of Go by grumpyprole on Wednesday November 10, 2021 @04:18PM (#29180968)
I'm happy to entertain the idea that Go is a sweet spot for many, but please let's not pretend language features are universally bad. After all, Go benefits enormously from a garbage collector and its language-level support for Hoare's CSP. Two very important features that e.g C and C++ do not have (they do however have structs, for loops and if statements).

IMHO Go certainly chose wisely when it left out many OOP features of questionable value. And perhaps in doing so, it avoided the whole OOP culture, which has produced a lot of over-complicated software and tools. The culture of simplicity in Go is a really good thing and worth defending. However, we should be open to the idea that one or more additional language features might help to further this goal.

Re:Twelve Years of Go by tdeck on Wednesday November 10, 2021 @02:55PM (#29179752)
> I used to be excited by programming language features instead of what problem I was actually trying to solve with programming.

This happened to me too, without using Go. I think I just got older.

Re:Twelve Years of Go by throwaway894345 on Wednesday November 10, 2021 @03:05PM (#29179917)
The nice bit about Go is that this maturity is baked into the philosophy and thus the language, the tooling, and the ecosystem where it benefits even younger developers. For example, your own hard-earned wisdom is great but it doesn't automatically make your language's package manager (or any other software you depend on, including libraries) better. But when that kind of wisdom is idiomatic, everything is better even when it's built by more junior developers.
Re:Twelve Years of Go by tdeck on Wednesday November 10, 2021 @03:11PM (#29179987)
Oh, I'm not necessarily suggesting that my lack of curiosity about new language designs is a good thing. In fact I think it's kind of a mixed bag. I'm only clarifying because I don't want to seem to be implying something negative about younger developers.
Re:Twelve Years of Go by throwaway894345 on Wednesday November 10, 2021 @03:24PM (#29180183)
I didn't think you were implying anything about younger developers, I was noting the rather significant difference between "I've matured as a programmer" and "maturity was baked into the language I use and its idioms, tools, ecosystem, etc".
Re:Twelve Years of Go by tdeck on Wednesday November 10, 2021 @06:06PM (#29182203)
Yeah, my point was that "matured" and "wisdom" are value-laden words and that's not necessarily the connotation I wanted to convey. Ideally I would get excited about both the problem and the tools. I completely understand the point you're trying to make about the ecosystem though.
Re:Twelve Years of Go by adamc on Wednesday November 10, 2021 @03:47PM (#29180539)
I came here to say that. I agree with your analysis.
Re:Twelve Years of Go by caente on Wednesday November 10, 2021 @02:44PM (#29179567)
> I used to be excited by programming language features instead of what problem I was actually trying to solve with programming. I'd spend hours condensing 10 lines of perfectly working code into 1 line of the most concise text possible (...) they should be impressed by what the program does for them, not what language features you used to implement it.

Interestingly, what made me go through similar evolution was the very language in which I was trying to do all those things, namely Scala. After a few years of trying to be "smart", I realized that the problem was usually bigger than the language.

So perhaps, it wasn't Go, nor Scala, who helped us in our realization, but life and experience?

Re:Twelve Years of Go by throwaway894345 on Wednesday November 10, 2021 @02:55PM (#29179751)
Our individual lives and experiences don't make the package manager better, though. Rather, Go's package manager (and its overall philosophy more generally) is good because Go was developed by people who had a lot of "life and experience". And it seems intuitive to me that someone who uses a language with a strong, mature philosophy would influence even more junior users.
Re:Twelve Years of Go by agumonkey on Wednesday November 10, 2021 @04:41PM (#29181294)
I believe he has a point. Go was from day one trying to walk a different path. It was wisely dumb, pragmatic, simple (even though yeah verbose on many fronts). It changes your focus on external value rather than internal value.
Re:Twelve Years of Go by shaan7 on Wednesday November 10, 2021 @03:35PM (#29180359)
> Just software, running, forever.

Until your users realize that if there was a security vulnerability which was fixed, a system upgrade is not enough. They will have to either hope that you haven't moved on, or build things themselves. But then, thats not a problem with Go specifically, thats a general issue with "static link all things".

Re:Twelve Years of Go by msie on Wednesday November 10, 2021 @05:06PM (#29181582)
Ah, but what if the updated shared lib broke other apps depending on the old version? Pros and cons.
Re:Twelve Years of Go by shaan7 on Thursday November 11, 2021 @06:24AM (#29186806)
> Pros and cons

Exactly. Which is why I don't get the "static linking is the best solution for deploying applications". You need to be able to do both. For example when building a C/C++ application you can decide if you want shared libs or static builds.

Re:Twelve Years of Go by uncomputation on Wednesday November 10, 2021 @08:29PM (#29183384)
Go’s package and dependency system is actually the only reason I have never started using it more. The lack of true versioning, unspoken assumption of GitHub, package system, and all of the confusion between god mod, go get, go install, etc. just hurts my brain. I think Rust actually has this perfect. It’s clear. You just specify the name and version and features in the Cargo.toml file and it is pulled from crates.io. No installation-time execution either.

As far as binaries, I think Rust beats it out here too. Take path separators for example. It’s completely possible to have a binary in Go that uses the entirely wrong path separators for the OS. Rust forces you to handle this.

Re:Twelve Years of Go by amscanne on Thursday November 11, 2021 @01:27AM (#29185049)
> The lack of true versioning, unspoken assumption of GitHub, package system,

These aren’t true. There is true versioning and no assumption of GitHub. Shouldn’t this be a complaint about the assumption of crates.io?

> No installation-time execution either.

This is also not true. There is no installation-time execution.

Re:Twelve Years of Go by uncomputation on Thursday November 11, 2021 @02:01PM (#29191659)
There is versioning through Git tags, which I don’t consider true versioning because you can always edit those tags to point somewhere else or remove them entirely. This is breaking. I suppose there is not an assumption of GitHub, but rather Git. I probably got that impression from all of the Go documentation using GitHub as an example (perhaps to seem more familiar to readers).

No, I _like_ crates.io because Rust is very explicit that that is where the packages come from. We can get into the benefits and risks and whatever about centralized vs decentralized package managers, but that’s not what I’m talking about. I just want to know how Go does what it does so that I can code confidently in it. A lot of Go packages are specified like so:

go get -u github.com/username/repo/version

But this is not enforced (you don’t have to specify a version) and this is also not a valid Git repo path and where exactly is this dependency stored and I can go on and on. When you import this package it’s usually

import “github.com/user/repo/version/module”

But then there is not always a <module> directory in the repo and… you get the idea. This sort of stuff hurts my head and I get it that Go is maybe trying to appear simple but this black box handwavey stuff can and will burn you (this very reason is why the Go community is generally against frameworks) so I just want to have a simple, clear answer and it seems no one else in the Go world has any of these questions. This turns me off.

I’m confused by your last bit. Neither Rust nor Go have installation time execution and this is good. I was referring to how you can’t just say “Oh Node has it and this is bad but Go doesn’t and this is good” because Rust doesn’t have it either.

Re:Twelve Years of Go by amscanne on Monday November 15, 2021 @01:43AM (#29224493)
Re: tags, that’s true but builds will detect this and break (since the hash is encoded in the sum file). No one should move tags, ever (for many reasons), and Go is simply requiring this.

Re: git, there is no assumption of git. Go also natively supports svn, hg, bzr and fossil. You also have the option to vendor things.

It’s fine to favor crates because it’s closer to what you’re used to, but I think you’re just complaining about ergonomics. They both have semver and implement satisfiability in similar ways (AFAIK).

It seems like the source control mixin is what’s causing the most frustration, and I get it — that’s where you have ergonomics you’re not used to — however, this is also where Go shines since it essentially gives you supply chain integrity without the need to trust any users uploading code (module owners) or third party vendors (crates).

What is the question for which you are looking for a simple, clear answer? Honestly, the documentation is quite excellent [1], but I’m happy to do my best to point to the best place for answers.

[1] https://golang.org/ref/mod

Re:Twelve Years of Go by pjmlp on Thursday November 11, 2021 @09:06AM (#29187942)
Nope, there is no relation between a package name and where it is hosted, nor any need to create remappings.

As it should be.

Re:Twelve Years of Go by amscanne on Monday November 15, 2021 @01:10AM (#29224302)
I’m not sure I follow. I assume “as it should be” refers to crates, with no mechanism for name ownership other than first-come, first-served.

You name any Go package based on a URL you control (and you can refer to any underlying source control by returning appropriate metadata from that URL). Package names that are URL-based is an arbitrary decision, but it seems like it at least solves that problem. Personally I’m much more a fan of that, since otherwise you need to put far too much faith in a single provider (crates), and enable a whole class of attacks and ownership squabbles. Better to just punt this to the already-solved DNS and web ecosystem. I just can’t agree that a single centralized repository is “as it should be”.

Re:Twelve Years of Go by the_gipsy on Wednesday November 10, 2021 @02:54PM (#29179725)
> With Go, you can just emit a binary for every supported platform dump the binary somewhere, and everyone in the world can download it and run it.

Does this hold true? Don’t you need to switch to musl or something, to build a static binary?

Re:Twelve Years of Go by mdaniel on Wednesday November 10, 2021 @04:09PM (#29180847)
I believe you may be thinking of `CGO_ENABLED=1` which causes golang binaries to fail to run on musl distros

So yes, your comment is probably right, but I get the impression the grandparent was a tiny bit tongue in cheek anyway

Re:Twelve Years of Go by moondev on Wednesday November 10, 2021 @06:23PM (#29182338)
It's actually easier now. On your target platform just "go run <import path>