News for hackers. Stuff that matters.
Re:Fixing for Loops in Go 1.22 by noelwelsh on Tuesday September 19, 2023 @04:02PM (#37575695)
This was also an issue in Javascript (e.g. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...)

It's somewhat amusing to see Go rediscover old ideas in programming language theory, given the stance against PLT that the Go developers took in the early years of the language.

Re:Fixing for Loops in Go 1.22 by akira2501 on Tuesday September 19, 2023 @04:24PM (#37575993)
Programming languages are an exercise in compromise, not pure application of theory. Well, except maybe Haskell and it's ilk, but this should be your expectation of most languages and generally not a surprise.
Re:Fixing for Loops in Go 1.22 by FridgeSeal on Tuesday September 19, 2023 @04:51PM (#37576380)
I think OP’s point is that given the go devs casual disregard for every development in PL theory and design over the last 30 years, it’s amusing to watch them rediscover half the issues from scratch.
Re:Fixing for Loops in Go 1.22 by skybrian on Tuesday September 19, 2023 @05:16PM (#37576827)
This meme is commonly repeated on HN, but I think it's inaccurate or at least greatly exaggerated.

There's nothing casual about Go's approach to language design, and I haven't seen any evidence that they're unaware of what other languages do.

I also haven't seen much criticism of languages other than C++ or Java.

Re:Fixing for Loops in Go 1.22 by bobbylarrybobby on Tuesday September 19, 2023 @05:38PM (#37577145)
If they're aware of how other languages either handle these issues or suffer the consequences of not handling them, then it sure is odd that they consciously decided to introduce the same issues into their own language, only to fix them down the road.
Re:Fixing for Loops in Go 1.22 by skybrian on Tuesday September 19, 2023 @06:06PM (#37577566)
Given Go’s success, it seems like fixing certain footguns much later actually worked out pretty well for them? That doesn’t necessarily mean it was right, but it was perhaps not as big a deal as some people assume.
Re:Fixing for Loops in Go 1.22 by FridgeSeal on Tuesday September 19, 2023 @05:47PM (#37577275)
Sum/Product types. Generics/type-parameters. Bizarre handling of nil in places. Error handling that’s like some deliberately crippled version of a Result<T,E>. The absolutely unhinged decision about zero-value-defaults for types. I’m sure other people can think of some more, but that’s the ones I can think of off the top of my head.

Non PL theory but related: incorrect implementation of monotonic clocks, and then refusing to fix it because “just use google smear time bro”.

Re:Fixing for Loops in Go 1.22 by skybrian on Tuesday September 19, 2023 @06:09PM (#37577613)
Everyone who disagrees with you is “unhinged.” This is just name-calling.
Re:Fixing for Loops in Go 1.22 by FridgeSeal on Wednesday September 20, 2023 @06:58AM (#37582677)
But they’re like, genuinely wild decisions? Unhinged is a great description!

The error design can return the value, or an error, or both, for some inexplicable reason and you can check it - or not - and if your function returned some indication of severe error, and you happen to not check it, you can totes just continue your program, in who knows what invalid state. Oh and also, because the devs are apparently deathly allergic to abstractions of apparently kind, you’ve got to do this janky little if err != nil check at. every. single. point. Which occludes your fundamentally important logic in pointless line noise, with zero opportunity for streamlining or improving the logic or guarantees.

Re:Fixing for Loops in Go 1.22 by kiitos on Tuesday September 19, 2023 @09:31PM (#37579405)
Go definitely implements monotonic clocks correctly?

https://pkg.go.dev/time#hdr-Monotonic_Clocks

Re:Fixing for Loops in Go 1.22 by FridgeSeal on Tuesday September 19, 2023 @09:48PM (#37579500)
Re:Fixing for Loops in Go 1.22 by kiitos on Wednesday September 20, 2023 @01:21AM (#37580635)
That article is so cringeworthy
Re:Fixing for Loops in Go 1.22 by FridgeSeal on Wednesday September 20, 2023 @06:59AM (#37582682)
I disagree, but the style isn’t for everyone.

However, that still doesn’t mean that it’s wrong.

Re:Fixing for Loops in Go 1.22 by eviks on Saturday September 23, 2023 @05:52AM (#37621885)
Rather illustrative article, especially re the false simplicity where the language just silently does the wrong thing

(though I disagree that ".ext" is not an extension of an empty base name)

Re:Fixing for Loops in Go 1.22 by noelwelsh on Tuesday September 19, 2023 @04:59PM (#37576535)
There's no need for compromise in this case. This issue is something I learned about in the late 90s / early 2000s when I started reading about programming language theory. It's found in introductory textbooks.
Re:Fixing for Loops in Go 1.22 by philosopher1234 on Tuesday September 19, 2023 @04:18PM (#37575915)
What stance against PLT are you referring to?
Re:Fixing for Loops in Go 1.22 by pseudonom- on Tuesday September 19, 2023 @04:47PM (#37576310)
Probably quotes like:

"It must be familiar, roughly C-like. Programmers working at Google are early in their careers and are most familiar with procedural languages, particularly from the C family. The need to get programmers productive quickly in a new language means that the language cannot be too radical."

And not including sum types despite having a sum-type-shaped hole in the language (`if err != nil`).

And some of the discussion about "why no generics" seemed kind of divorced from existing PL knowledge on the topic.

Re:Fixing for Loops in Go 1.22 by tensor on Tuesday September 19, 2023 @05:10PM (#37576731)
These were all intentional tradeoffs though, not any ignorance of theory. Also, it's pretty rich for someone to be complaining about Go while referencing Javascript of all languages. Javascript's design flaws are legendary. And I mean no disrespect to the creators of Javascript, they had to deal with some crazy last minute change requests to the language.
Re:Fixing for Loops in Go 1.22 by TwentyPosts on Tuesday September 19, 2023 @05:41PM (#37577187)
Ehhh, I see absolutely no evidence that the Go developers were particularly aware of theory. It really feels more like they just were used to thinking in terms of C, and built a language which is kind of like C.

Go also has some really weird stuff in it, such as named return values.

Frankly, the lack of sum types hurts the most. The language would just be a lot better with a unifying Result type in the library. And don't give me any of that "oh, they tried to keep the language simple!" stuff.

Intuitively, sum types are laughably simple. Everyone understands "It's one of these possible values, so you need to check which one it is and then handle that situation." They are more simple than enums on a conceptual level! Sum types are just not how C-programmers think about the world.

Re:Fixing for Loops in Go 1.22 by ianlancetaylor on Tuesday September 19, 2023 @08:47PM (#37579098)
As it happens, we considered sum types quite seriously in the early days. In the end we decided that they were too similar to interface types, and that it would not help the language to have two concepts that were very similar but not quite the same. https://groups.google.com/g/golang-nuts/c/-94Fmnz9L6k/m/4BUx...

There is a lot of discussion of sum types in Go at https://go.dev/issue/19412.

Re:Fixing for Loops in Go 1.22 by TwentyPosts on Wednesday September 20, 2023 @11:54AM (#37585776)
When I did research on this topic ages ago I read both of these links, and I'm very familiar with the arguments.

I also vehemently disagree with them, and I think that the way code is factually written in practice is on my side: People who propose sum types commonly refer to the Option<T> or Result<S,E> types in Rust. These are types which are almost exclusively used as return types.

Interface types are the opposite. They're used as input types, and almost never to distinguish between a concrete, finite list of alternatives. They are used to describe a contract, to ensure that an input type fulfills a minimal set of requirements, while keeping the API open enough that other people can define their own instances.

The fact that Go in fact does not use interface types for its error handling is a pretty good argument in favor of that, I'd say.

The thing is, at this point it doesn't matter, sadly. Adding sum-types to the language now would be unsatisfying. You would really need proper integration as the primary tool for error handling in the standard library (and the ecosystem), and that's unlikely to happen, even less likely than a Go 2.0.

EDIT: Just to make it clear, I think not wanting to add sum types to the language is understandable at this point. The real shame is that they were not in the language from the beginning.

Re:Fixing for Loops in Go 1.22 by ianlancetaylor on Wednesday September 20, 2023 @02:12PM (#37587715)
Go made a deliberate decision to use multiple results rather than Option<T> or Result<S, E>. It's of course entirely reasonable to disagree with that decision, but it's not the case that the Go language designers were unaware of programming language theory or unaware of sum types. Although you suggest that you want sum types as the primary tool for error handling, Go made a different decision, not due to accident or lack of knowledge, but intentionally.

(Separately, I'm not entirely sure what you mean when you say that Go doesn't use interface types for its error handling, since the language-defined error type is in fact an interface type.)

Re:Fixing for Loops in Go 1.22 by TwentyPosts on Wednesday September 20, 2023 @04:28PM (#37589714)
Fwiw, I didn't mean to imply that they don't know any language theory, just that the language doesn't seem to reflect it. I don't think this itself should be a controversial statement, by the way, Go aims to be a simple language, and the last thing it needs is monads.

Frankly, I'm just the type of person who doesn't understand why it is possible to silently drop error values in Go (even accidentally), see

  f, err := os.Open("foo.txt")
  g, err := os.Open("bar.txt")

  if err != nil {
      return
  }
while the language is simultaneously very strict about eg. unused imports.

It seems like a pretty severe flaw for a language that takes pride in its explicit error handling, and a deep dive into why this flaw was acceptable to the creators would be really interesting.

For now though, instead of sum types we ended up with features such as named returns (???). I imagine some of the complexity here was about not wanting to introduce an explicit tuple-type, since a Result<S, E>-type doesn't compose with multiple returns. (I feel like there should be some workaround here. Maybe anonymous structs + some sort of struct/tuple unpacking, but I could see it getting gnarly.)

> I'm not entirely sure what you mean when you say that Go doesn't use interface types for its error handling, since the language-defined error type is in fact an interface type.

What I meant is that this specific usecase of sum-types (ie. error-unwrapping) is not something that interfaces in Go are used for. Error-handling in Go is done via multiple return values. This goes against the common claim that "sum types and interfaces are too similar/have the same uses", and should count for something, considering that explicit error handling is a big component of Go.

Re:Fixing for Loops in Go 1.22 by za3faran on Thursday September 21, 2023 @01:00PM (#37600528)
Having worked on large golang codebases, it shows quite quickly how badly error handling is, the example you mentioned being one of them, as well as others not detected by the compiler or linter. Using multiple return values to model errors is fundamentally broken, as with other things they chose with the language, either deliberately or not.
Re:Fixing for Loops in Go 1.22 by ianlancetaylor on Thursday September 21, 2023 @04:22PM (#37603740)
I'm not going to claim that Go has the ideal approach to whether an error can be ignored. In general, in Go, some errors can be ignored, and some can't. For example, fmt.Fprintf to a strings.Builder can never result a non-nil error. It's fine to ignore the error returned by fmt.Fprintf in that case. On the other hand, fmt.Fprintf to a os.File can return a meaningful error, and for some programs it's appropriate to check for that error. (Though the issue is complicated by the fact that complex programs probably use bufio which does its own error handling.)

I'm not personally concerned about examples like os.Open, where the result must be used. Sure, you can ignore the error. But a failure will show up very quickly. I'm not saying that this is not an issue at all, but I believe it's a less important one.

Part of the reason for Go's behavior is the idea that "errors are values" (https://go.dev/blog/errors-are-values). And part of it is that the simple fmt.Println("Hello, world") doesn't require any error handling. And part of it is the desire to make error handling clear and explicit in the program, even if the result is verbose.

Re:Fixing for Loops in Go 1.22 by kiitos on Tuesday September 19, 2023 @09:33PM (#37579413)
> I see absolutely no evidence that the Go developers were particularly aware of theory

Rob Pike and Ken Thompson are theory-unaware. Sure. Yes. This position is good and defensible.

Re:Fixing for Loops in Go 1.22 by hollerith on Tuesday September 19, 2023 @09:36PM (#37579431)
I believe it: Thompson is old enough and Pike is arrogant enough not to have learned the relevant programming-language theory.
Re:Fixing for Loops in Go 1.22 by kiitos on Tuesday September 19, 2023 @09:48PM (#37579498)
Nice joke.
Re:Fixing for Loops in Go 1.22 by hollerith on Tuesday September 19, 2023 @10:15PM (#37579674)
I misspent a few thousand hours of my life on the 9fans mailing list long ago when Pike was very active on it, and my non-joking assessment is that ever since he finished his PhD or shortly after, Pike has probably felt he knows all he needs to know about programming languages.

And Thompson turns 80 this year. In what years does Thompson become old enough that you start to entertain the possibility that not everything he says or does is the result of having learned and understood all the relevant work including the recent work?

And Bell Labs was never good at designing programming languages. Did you know that in the Bourne shell (and possibly in all the other shells) you can have a statement of the form $foo = bar which will assign bar to the variable whose name is the value of foo? (Emacs Lisp, and old language, has the same functionality under function named "set", but most Emacs Lisp programmers know to avoid it.) Well, the plan 9 group think that is an OK thing to do in a workman shell script: i.e., the shell script is not doing anything fancy like interpreting a programming language or defining a new PL feature (not that it is sane to do either of things in a Unix shell).

Re:Fixing for Loops in Go 1.22 by kiitos on Wednesday September 20, 2023 @01:32AM (#37580698)
You're moving the goal posts. The claim isn't that Ken Thompson is flawless. The claim is that he isn't stupid.
Re:Fixing for Loops in Go 1.22 by TwentyPosts on Wednesday September 20, 2023 @12:06PM (#37585936)
The claim wasn't that they are unaware, the claim was that it doesn't seem to show in the design of Go.

I think Go is a perfectly fine language, and I respect the goal to stay clear of complexity, but when looking at any particular Go feature, then it's easier to explain the decision with "They are used to thinking in terms of C-idioms." than with any particular brilliance or awareness of PL-theory.

Re:Fixing for Loops in Go 1.22 by xyzzy_plugh on Tuesday September 19, 2023 @09:35PM (#37579424)
Have you looked for any evidence? There is plenty.

Sum types have been discussed since before the initial open source release of the language, at least according to some of the issue threads such as https://github.com/golang/go/issues/19412

If they're laughably simple, then please contribute a proposal for how to add them to the language. You'll find no one is really fighting against the concept of sum types.

Re:Fixing for Loops in Go 1.22 by TwentyPosts on Wednesday September 20, 2023 @01:18PM (#37586902)
They're 'laughably simple' on a conceptual level. Adding them to the language in retrospect might genuinely be a bad idea at this point.

The thing which I am personally salty about is that they weren't there to begin with, and that the language wasn't built with them in mind.

Re:Fixing for Loops in Go 1.22 by xyzzy_plugh on Wednesday September 20, 2023 @02:36PM (#37588082)
Go development began circa 2007, I do not believe sum types were common place nor do I believe the average developer was aware of them at the time. I'm not saying you're wrong, but given even Scala didn't add support until 2010 they do not seem like something sorely obvious that should have been there from the beginning. In hindsight, sure.
Re:Fixing for Loops in Go 1.22 by kaba0 on Tuesday September 19, 2023 @05:29PM (#37577026)
With all the crazy warts that JS has, it is at least a lisp-like very dynamic language if you squint (a lot) at it. Its greatest fault is probably leaving out integers (I can’t even fathom why they decided on that, floats can’t represent properly ints).

Go is just simply badly designed, relying on hard-coded functionality a lot.

Re:Fixing for Loops in Go 1.22 by Cthulhu_ on Wednesday September 20, 2023 @06:01AM (#37582359)
Which is better, hard-coded functionality or magic? I don't believe it's badly designed, since every design decision is deliberate; bad design would be accidental.
Re:Fixing for Loops in Go 1.22 by za3faran on Thursday September 21, 2023 @01:02PM (#37600560)
This is a false dichotomy. golang is weak that things that should have been in the standard library end up being hardcoded (like maps).
Re:Fixing for Loops in Go 1.22 by anderskaseorg on Tuesday September 19, 2023 @05:03PM (#37576605)
MDN goes into great detail, but the important point is that JavaScript fixed this with let and const.

    > a = []; for (i = 0; i < 3; i++) a.push(() => i); a.map(f => f())
    [ 3, 3, 3 ]
    > a = []; for (let i = 0; i < 3; i++) a.push(() => i); a.map(f => f())
    [ 0, 1, 2 ]
    > a = []; for (i of "abc") a.push(() => i); a.map(f => f())
    [ 'c', 'c', 'c' ]
    > a = []; for (const i of "abc") a.push(() => i); a.map(f => f())
    [ 'a', 'b', 'c' ]
Re:Fixing for Loops in Go 1.22 by zeroimpl on Tuesday September 19, 2023 @05:44PM (#37577243)
In contrast, Java would have a compile error so long as the variable was not declared final.
Re:Fixing for Loops in Go 1.22 by ben0x539 on Tuesday September 19, 2023 @06:49PM (#37578124)
But isn't it completely wild that the `for (let i =`... version works like that? What does the loop 'desugar' into if written as a while-loop?
Re:Fixing for Loops in Go 1.22 by anderskaseorg on Tuesday September 19, 2023 @07:35PM (#37578554)
Before let/const, scopes could only be introduced at function level, so @babel/plugin-transform-block-scoping transpiles it using an extra function:

    var _loop = function (i) {
      a.push(() => i);
    };
    for (var i = 0; i < 3; i++) {
      _loop(i);
    }
The key is that the scoping happens for each iteration, not around the entire loop. That detail is nonobvious, given how many other languages have gotten it wrong, but I wouldn’t say it’s wild.

(If you’re curious how Babel deals with the more complicated cases of break/continue, labelled break/continue, and return, try it out at https://babeljs.io/repl.)

Re:Fixing for Loops in Go 1.22 by ben0x539 on Tuesday September 19, 2023 @09:32PM (#37579408)
Right, the wild thing for me is when you mutate `i` in the loop body. So at the same time `i` is scoped to the iteration so that you can capture it, but also mutating it affects the loop-scoped `i` that is incremented between iterations and checked for the termination condition. The iteration-scoped `i` is assigned back to the loop-scoped `i` at the end of the loop body. So if you have a closure close over `i` in the loop body and mutate it, whether that mutation affects the actual loop variable depends on whether the closure is called during the iteration it was created in or during a later iteration. Kinda spooky, but sure, less of a footgun than the original behavior.
Re:Fixing for Loops in Go 1.22 by biomcgary on Tuesday September 19, 2023 @05:05PM (#37576629)
Is this loop variable problem really a theory issue (if so, does it have a label)? Or, primarily a practical one? Is there a database of known and historical programming language problems that are nicely tagged with "theory problem", "frequent foot-gun", etc?

Could an LLM coupled with a constraint solver create the perfect language (for particular domains, e.g., performance)? Or, just use Rust ;-)?

Re:Fixing for Loops in Go 1.22 by noelwelsh on Tuesday September 19, 2023 @05:11PM (#37576744)
In contrast to the view of many, programming language theory is very closely intertwined with programming practice. It both drives practice and reacts to practice.

In this particular case I imagine the issue was uncovered some time in the 1970s, which is when lexical scoping came to the fore in Scheme (in the US) and ML (in Europe). It's a fairly natural problem to run into if you're either thinking deeply about the interaction between closures (which capture environments) and loop constructs, or if you're programming in a language that supports these features.

Re:Fixing for Loops in Go 1.22 by stouset on Tuesday September 19, 2023 @05:09PM (#37576710)
The entire story of go seems to be learning through repeating the same mistakes as other languages, one at a time.

Nil being another big one. Even more impressively they doubled down on this mistake with typed nils. Even if you explicitly do a comparison with nil you can still shoot yourself in the foot because it was a different nil than the one you compared against.

Re:Fixing for Loops in Go 1.22 by TwentyPosts on Tuesday September 19, 2023 @05:19PM (#37576884)
Wait what? Do you have an example or more information on this?
Re:Fixing for Loops in Go 1.22 by gwd on Tuesday September 19, 2023 @05:29PM (#37577022)
Basic example:

    func foo() *bar {
      // ...
      if something_wrong {
        return nil;
      }
    }
    
    var x interface{}
    
    x = bar()
    
    if x != nil {
      // Dereference x
    }
This will crash if `foo()` returns nil, because it's checking if `x == interface{}(nil)`, which is false. What you wanted to check was whether `x == *bar{nil}` or one of the other nil types that implements the interface; which must be done with `reflect.ValueOf(x).IsNil()`.

https://github.com/golang/go/issues/30865

Re:Fixing for Loops in Go 1.22 by kiitos on Tuesday September 19, 2023 @09:30PM (#37579394)
This is a great example of code that compiles, but would never pass code review at any decent organization. Specifically, you'd never assign a concrete return value like *bar to an interface{} and expect `x != nil` to behave like this code would imply.
Re:Fixing for Loops in Go 1.22 by stouset on Tuesday September 19, 2023 @09:53PM (#37579532)
Yes, it’s a contrived example. But it’s not like this is some obscure thing that no go programmer has ever run into in practice. It’s something I’d wager almost everyone has encountered if they’ve used it longer than a year.

https://dave.cheney.net/2017/08/09/typed-nils-in-go-2

Re:Fixing for Loops in Go 1.22 by kiitos on Wednesday September 20, 2023 @01:51AM (#37580804)
Yes, it's a not-uncommon gotcha or foot-gun. No argument there. But, like many other gotchas and foot-guns, they are not too difficult to spot in code review.
Re:Fixing for Loops in Go 1.22 by gwd on Wednesday September 20, 2023 @05:42AM (#37582262)
...if you have experienced golang developers who have scars on their feet. If you have someone who's an experienced developer but only used golang for a few months, they might not catch it, which means a hard-to-find bug that got into your code.

Furthermore, even for experienced developers, there's a limit to how much context / rules / whatever your brain can keep. This footgun takes up space and intellectual energy that could be used for something else.

All things being equal, a language that doesn't have this kind of footgun is better than one that does: less experienced reviewers will let fewer bugs slip through, and more experienced reviewers will either spend less effort reviewing (meaning the mental energy can be used somewhere else) or will have more review capacity (meaning they'll find more bugs / improve the code more).

Re:Fixing for Loops in Go 1.22 by gwd on Wednesday September 20, 2023 @05:32AM (#37582208)
This is the actual code that caused me to write the ticket above (be warned, I wouldn't consider it amazing code; my first foray into writing a web app as a side project, just trying to get something that works):

https://github.com/gwd/session-scheduler/blob/master/handle_...

Basically, I have several pages I'm rendering, which have common prerequisites regarding checks, and common handling processes (passing some sanitized data to a template). The *GetDisplay() functions take a structure from the "database" layer and sanitize it / process it for handing to the templates. The two *GetDisplay() functions return pointers to two different types, appropriate for the template to which they will be passed; and return nil if there's an issue.

So I have a map, `data` of type `map[string]interface{}` that I pass into the templates; and two different paths set `data["Display"]`; then at the end I want to check if either of the `*GetDisplay()` functions returned `nil`. So naturally, the first version of the code checked `data["Display"] == nil`, which was always false, since it was implicitly checking `data["Display"] == interface{}(nil)`, but the value in case of an error would be either `*DiscussionDisplay(nil)` or `*UserDisplay(nil)`.

I mean, sure, there are other ways to structure this; I could return an error or a boolean in addition to returning nil. But 1) the only reason to do that is to work around this language limitation 2) it's a "foot gun" that it's easy to fall into.

And sure, a golang developer who'd shot themselves in the foot a few times with this would catch it during review; but I don't think a bunch of newer developers would catch it, even if they had extensive experience in other languages.

Re:Fixing for Loops in Go 1.22 by kiitos on Wednesday September 20, 2023 @08:10AM (#37583201)

    data := map[string]interface{}{}
So this is the problem, basically. Go isn't a dynamically typed language, and doesn't really let you create an arbitrary map of keys to objects like e.g. Javascript or Python does. Any time you see `map[something]interface{}` that's a huge red flag that something is fucky. In your case you want to define `data` as a struct type with a Display field (and whatever else).

    if ... reflect.ValueOf(display).IsNil() {
Any use of `package reflect` in application code is a similarly huge red flag. 99 times out of 100 it's a design error that ought to be fixed.
Re:Fixing for Loops in Go 1.22 by gwd on Thursday September 21, 2023 @05:10AM (#37595117)
> In your case you want to define `data` as a struct type with a Display field (and whatever else).

So first of all, the reason things are defined that way is to interact with the golang templating libraries. Secondly, your suggestion wouldn't really solve the issue in this case: content of "Display" is different for each web page, and so the only way to assign both types to the same value is to make it an interface.

> Any use of `package reflect` in application code is a similarly huge red flag. 99 times out of 100 it's a design error that ought to be fixed.

I'm not using reflect for fun; there is literally no other way to check for nil with interfaces (other than manually checking nil for all possible types).

At any rate, I wrote code in a way that's intuitive, at least to a C programmer (using 'nil' value as an indicator that there was an error); the code had a bug. Sure I could have rearchitected the whole function, and if this were a commercial product I may have. But it's a simple webapp to help scheduling discussions at my project's conferences; a quick fix that robustly works around Golang's deficiencies is perfectly reasonable.

EDIT: And honestly, there are exactly three ways of addressing this:

1. Separating the two page paths, duplicating all the logic which is common to the two. This makes it less DRY, which risks checks becoming inconsistent, increasing the chance that there will be a security issue.

2. Make the *GetDisplay() functions return a second value to indicate failure. This is honestly kind of a dumb thing to do to work around a language deficiency.

3. Continue to use 'nil' to indicate failure, and fix the check to be able to properly check for nil. This can be done by listing out the various possible values of 'nil', which is ugly, annoying, and fragile (since it would silently break if we added a third type); or it can be done using reflection.

#3 is obviously the most reasonable thing to do here.

Re:Fixing for Loops in Go 1.22 by kiitos on Saturday September 23, 2023 @09:44AM (#37623154)

    if display := data["Display"]; display == nil || reflect.ValueOf(display).IsNil() {
        <code>
I mean, even ignoring all of the interface{} design errors, the simple fix here is just

    if _, ok := data["Display"]; !ok {
        <code>
Re:Fixing for Loops in Go 1.22 by Spiwux on Tuesday September 19, 2023 @05:33PM (#37577069)
e.g.

  var typeA Interface = (*TypeA)(nil)
  println(typeA == nil)           // false
  println(typeA == (*TypeA)(nil)) // true
Yes really https://go.dev/play/p/sz44kJW8OuT
Re:Fixing for Loops in Go 1.22 by Thaxll on Tuesday September 19, 2023 @05:26PM (#37576978)
op is confused with nil interface.
Re:Fixing for Loops in Go 1.22 by Cthulhu_ on Wednesday September 20, 2023 @05:53AM (#37582315)
And yet, they started off with a language that fixes the mistakes of the main language it tried to replace - c / c++. Mistakes like pointer arithmetic and manual memory management, not zeroing out memory before use, compile times, the list goes on.

And generics is an example of a language feature they took their time for, to avoid making the same mistakes as e.g. Java did, where generics ended up taking up half the language spec and compiler / runtime implementation.

Re:Fixing for Loops in Go 1.22 by doctor_eval on Tuesday September 19, 2023 @05:13PM (#37576772)
It’s also amusing to see someone talk about JavaScript and PLT in the same sentence, given the practical origins of JS.
Re:Fixing for Loops in Go 1.22 by noelwelsh on Tuesday September 19, 2023 @05:20PM (#37576902)
It's not making any claims about the quality of design in JS here. I'm literally not talking about them in the same sentence for this reason. I'm, instead, merely noting that it had the same issue. Looks like it was fixed in 2014: https://nullprogram.com/blog/2014/06/06/ C# also had the same issue, as noted elsewhere in the comments.
Re:Fixing for Loops in Go 1.22 by doctor_eval on Tuesday September 19, 2023 @07:12PM (#37578372)
It simply seems disingenuous to talk about how this was an issue in JS and then go on to say that Go devs have a "stance against PLT". JS is not renowned for being an exemplar of PLT, so why would the Go developers use it as a reference point for their own design? JavaScript can't even take the address of a variable - which is the underlying problem here.

In any case - I seem to remember that they discussed the rationale for the original decision in the release notes for go 1.21, along with additional context.

For whatever it's worth, I don't see any evidence that Go is specifically antagonistic to programming language theory at all - the existence of first-class constructs like channels and closures suggests otherwise. There are always costs and tradeoffs involved in adopting certain theoretical paradigms, and PLT is subject to fashion as much as any other endeavour.

Go focusses on simplicity, and when talking about simplicity I really like this quote from Dijkstra:

    "Simplicity requires hard work to be obtained and education for its appreciation, and complexity sells much better.” [0]
I think Go works hard to be simple, and sometimes that comes across as being simplistic. Indeed, I was sceptical of Go when I set out to learn it, but having spent enough time with it to consider myself a professional Go developer, I also find that enjoy coding more than I have for many years, `err != nil` notwithstanding.

[0] https://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/E...