Live data from Hacker News

Go Replaces Interface{} with 'Any'

github.com

81–90 of 481 posts

Re: Go Replaces Interface{} with 'Any'

#81

Earlier quoted context omitted.

0ver is parody, right?

Well there’s a joke somewhere. Less has my favorite version numbering system. Sequential. Latest stable release: Version 598 https://www.greenwoodsoftware.com/less/

"Tell the user nothing" is your favorite system?

Especially, like, what if you release a bugfix for a significantly old version? Do you give it an up-to-date number? Do you not give it a number at all?

(Also I see a 581.2 on that page.)

Re: Go Replaces Interface{} with 'Any'

#82
post #67

Like it! Now, can they continue to add more “useless” improvements like while-loops and so on.

Doesn't 'for' work as 'while' if you only give it a condition in go? I haven't written much, so correct me if I'm wrong.

Does not Interface{} work as well as Any? I mean, most languages have while-statements cause it is more clear what the intention is.

Re: Go Replaces Interface{} with 'Any'

#83
post #59

I'm not sure I like this change. I liked interface{} since it just works out naturally from Go's relatively simple type system, and anyone could come to the conclusion without actually being told "use interface{} to represent any possible value" just by having an understanding of that type system. Adding what is simply a type alias, multiple words for the same underlying concept, to me just feels like jargon. I admir…

Isn't Any essentially: type Any interface{} ?

[deleted]

Re: Go Replaces Interface{} with 'Any'

#84
post #70

Good, now we just need the ability to declare function parameters and return values non-nullable (Forbid passing nil into a function, and declare a function will never return nil). That would get rid of the "panic: runtime error: invalid memory address or nil pointer dereference" errors. https://wakatime.com/blog/48-go-desperately-needs-nil-safe-t...

I’d kill for union types as well.

… and pattern matching. Maybe just some extensions for `switch`.

… and one of the `try` proposals.

That having been said… I do appreciate that Go has gotten where it is today by being radically simple, and that a lot of extreme care needs to be done to add new features to the language. It’s hard to draw a firm line in the sand. I feel like all of these features would work great together, though; it’d enable Go to do something like `Result` in Rust with few language-level changes.

I even remain somewhat skeptical about generics, but I am hopeful.

Re: Go Replaces Interface{} with 'Any'

#85
post #65

Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them. Reminds of Java 4 (15 years ago or something) where code was full of this crap: List /* */ values; Map /* */ map; Some devs spent a whole week doing nothing other than removing those commented out generic type decl…

You're lucky: Go 1.18 Beta 1 was released today, which has generics.

Craazzyyyyy - ty!

Re: Go Replaces Interface{} with 'Any'

#86
post #50

Earlier quoted context omitted.

I cannot wait for the Result monad. The state of error handling in Go at the moment is embarrassing at best.

Emulating sum types in languages without pattern matching is extremely awkward, to the point of being almost useless. type Result[T] struct { ok: *T err: error } Great, so how do you work with it? * You can have a `ok()` getter that returns `*T`. Now you you need an `if x != nil` * `isOk()` + `isErr()` * `unwrap() T`, which panics on errors * `split() (*T, err)` that splits into separate values, especially awkward si…

The Rust Result type has:

  - map / map_err
  - and_then / or_else
  - unwrap / unwrap_or
And countless of other functions making it very practical to chain computations without having to pattern match anything.

I do the same in Erlang/Elixir.

In Golang, I need to check every function call, and if I want to know where an error come from, I need to wrap it in an errors.New() because no exceptions = no stacktrace

Re: Go Replaces Interface{} with 'Any'

#88
post #63
post #50

Earlier quoted context omitted.

I cannot wait for the Result monad. The state of error handling in Go at the moment is embarrassing at best.

Well it's better than most language with exceptions. People makes it a big deal, in reality it's not.

An exception has a stacktrace. This single piece of information is crucial when you debug and makes handling errors in Golang embarrassing.

I rest my case.

Re: Go Replaces Interface{} with 'Any'

#89

Earlier quoted context omitted.

The root of the Go project with the go.mod file doesn't have to be the root of the repository.

Doesn’t it? Is this new?

As far as I know this was always possible since modules were introduced. You just have to prefix the version tags for Go with the subdirectory in the repo: "my/sub/directory/vX.Y.Z"

Re: Go Replaces Interface{} with 'Any'

#90
post #65

Their code is full of things like: type fileOps []any // []T where T is (string | int64) Go does not have neither generics nor union types. So people have to do this kind of thing :( I feel sorry for them. Reminds of Java 4 (15 years ago or something) where code was full of this crap: List /* */ values; Map /* */ map; Some devs spent a whole week doing nothing other than removing those commented out generic type decl…

> I feel sorry for them.

Oh good grief. There are 32,768 programming languages. People are free to pick the ones they want to use and nobody wants your pity.

Post reply on HN