Hacker News new | past | comments | ask | show | jobs | submit login

Some of the things they listed are dubious...

Writing to a file, there’s File.Write([]byte) and File.WriteString(string) – a bit of a departure for Python developers who are used to the Python zen of having one way to do something

Simply because it's not currently feasible to write a function that can have multiple type signatures (via overloading, generics, etc.).

Going between []byte and string. regexp uses []byte (they’re mutable). It makes sense, but it’s annoying all the same having to cast & re-cast some variables.

There are actually two different versions of each regexp function: one for strings, one for []byte. Maybe they're using a different version?

No tuples, have to write your own structs or use slices (arrays)

Actually, you can declare a fixed-length array as a type. So if you need to return a triple of ints, you can declare the return type to be [3]int and have the type system check that you're actually returning an array of ints of length 3.

Similarly, a lot of the other bullet points are natural results of having a static type system.

I was expecting more points like:

* you can't monkey-patch functions into external libraries like you can with Python modules * no generics, so you can't write a generic "map" function, for example * no preemptive multitasking, so one goroutine can wedge the entire program * passing around arrays and structs is by value, leading to unexpected allocation and memory usage * pointers




> Actually, you can declare a fixed-length array as a type. So if you need to return a triple of ints, you can declare the return type to be [3]int and have the type system check that you're actually returning an array of ints of length 3.

That's different from a tuple as it is commonly known in Python and statically typed languages. Tuples can be heterogeneous in languages like Python, OCaml, and Haskell, which Go fixed length arrays can't be. For example, in Go you can't have `(int, float)`.



Not quite. What you have is a single type interface{} that happens to be the super type of all other types. You still haven't solved the issue of having multiple different types in a tuple--you've just thrown all the type information away!

Think of a tuple as an anonymous struct. (Or perhaps think of a struct as a tuple with labels :P.) We want to statically differentiate between a pair of ints, a pair of strings and an int, string pair, which we simply can't do with interface{}.


RTFM! of course you can, just switch on a type

    switch x.(type) {
    // cases
    }


The parent post said "statically".


Does Go really not have tuples? (Aren't multiple return values tuples?)


It has multiple return values and syntax for assigning the results of a function that returns multiple values, but tuple values are not first class and the destructuring form is limited to calling a function and extracting its return values.


you can't monkey-patch functions into external libraries like you can with Python modules

You can add functions to existing types in Golang.

no preemptive multitasking, so one goroutine can wedge the entire program

That's pretty misleading. If all you write is go code, you can't "wedge the entire program" in Golang just from one thread. You could wedge a native thread if you were using C methods. Assuming you don't want to fix your broken code, you can just set GOMAXPROCS to something high and work around even that.

passing around arrays and structs is by value, leading to unexpected allocation and memory usage

Most developers pass pointers. Pointers are not really that hard in Golang, because there is no pointer arithmetic or undefined behavior.


Methods for a type have to be declared in the same package as the type.


Fortunately you can embed other people's types within your own type, thereby extending it.


Sure. But that's not monkey patching, that's inheritance.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: