News for hackers. Stuff that matters.
Re:Go is not an easy language by solosoyokaze on Monday February 22, 2021 @09:56AM (#26225202)
Ruby and Python are notorious for being difficult to read because of all the foot guns in place. Monkey patching, duck typing, metaprogramming... and that's not even talking about structural limitations like the GIL.

Go is definitely more verbose and less "fun" to write, but it's 10X easier to reason what's going on in a large application.

Of course, it's also the correct kind of solution for some types of problems. If you need a compiled language (many do), the competition to Go isn't Ruby and Python, it's C++ and Rust.

Re:Go is not an easy language by cb321 on Monday February 22, 2021 @10:36AM (#26225679)
Or Nim or Zig or ...

Actually, I feel like Zig may be most in the compiled-but-keep-it-simple-like-C headspace as Go. I don't know either Go or Zig super well. From what I do know, Zig seems not quite as stubborn as Go about forcing code to be "simple to reason about" (which is also subjective, though maybe less so than "easy to do things").

Re:Go is not an easy language by dnautics on Monday February 22, 2021 @10:45AM (#26225798)
I would say Zig is interesting in that "safe things are easy and pretty", "unsafe things are difficult and ugly", thus drawing eyes to the code that needs it. It's four lines of nasty looking code for me to convert a slice of bytes to a slice of (f64/f32/i32)... Which the compiler no-ops. This is dangerous because the alignment and byte count must be correct.
Re:Go is not an easy language by solosoyokaze on Monday February 22, 2021 @10:52AM (#26225881)
I would say both of those are interesting languages, but lack the amazing standard lib of Go and definitely the tooling and industry support.

Personally, I find Swift to be a really great language, but can't deal with the Apple eco-system, XCode, raw Linux support...

Re:Go is not an easy language by cb321 on Monday February 22, 2021 @11:22AM (#26226282)
Totally agree Re: Swift drawbacks.

Nim's stdlib is actually quite large (like 300 modules). I am sure there are things in Go's that are not in Nim's (like Go's `big`), but I am equally sure there are things in Nim's that are not in Go's (like Nim's `critbits`, `pegs`, etc).

I doubt there is much in Go's stdlib not available in Nim's nimble package system, but OTOH, I am also sure the Go ecosystem is far more vast. I just didn't want people left with the impression Nim's stdlib is as small as Zig's which it is definitely not. Nim has web server/client things and ftp/smtp clients, json and SQL parsers, etc.

Re:Go is not an easy language by jacobr1 on Monday February 22, 2021 @10:40AM (#26225728)
> If you need a compiled language

I would wager jvm/clr are probably the main competition for Go at least for product/tech companies and enterprise IT.

Re:Go is not an easy language by solosoyokaze on Monday February 22, 2021 @10:53AM (#26225887)
Definitely for server-side software, but not for binaries that need to be distributed to end users.
Re:Go is not an easy language by eeZah7Ux on Monday February 22, 2021 @11:27AM (#26226346)
Python is widely considered to be very expressive and very readable.

You can write unreadable code in virtually any language but that's besides the point.

Re:Go is not an easy language by solosoyokaze on Monday February 22, 2021 @11:30AM (#26226395)
Considered "very readable" by whom? It's pretty well accepted that dynamic/weakly typed languages are more difficult to deal with at scale.
Re:Go is not an easy language by prionassembly on Monday February 22, 2021 @11:47AM (#26226632)
Python is dynamically but strongly typed. “2+True” is a type error; once something has a type, it has a type. There’s no WAT.
Re:Go is not an easy language by dexterlemmer on Friday March 05, 2021 @02:52AM (#26354039)
Python is more strongly typed than JS/Perl, granted. But it is still very weakly typed overall. Here are some examples:

1. if list(): pass # implicit coercion from collection -> None -> bool. (Very uncommon weak typing and a terrible idea.)

2. a = 123; b = 4.5; c = a + b # implicit coercion from int -> float (Common but not universal weak typing. More often hides bugs than helps with ergonomics and readability but sometimes a worthwhile tradeoff.)

3. a = 1 + false # implicit coercion from bool to int (Common weak typing in scientific languages (for masking) and older C-family languages (for bit twiddling). However, that's still bad language design. Libraries/syntax sugar should special case masking and bit twiddling. You should not have global coersion between bool and int.)

4. etc.

Re:Go is not an easy language by solosoyokaze on Monday February 22, 2021 @11:51AM (#26226689)
Variables can change type though. This is working python code:

  x = 1
  y = 2
  print(x + y)

  x = "no "
  y = "types"
  print(x + y)
Whereas this will not even compile in Go:

    x := 1
    y := 2
    x = "no"
    y = "types"
Re:Go is not an easy language by anaerobicover on Monday February 22, 2021 @12:06PM (#26226944)
That's the difference between static and dynamic typing, not the difference between weak and strong. The values cannot be used as if they were another type.
Re:Go is not an easy language by dexterlemmer on Friday March 05, 2021 @02:58AM (#26354107)
It has nothing to do with the difference between strong and weak typing and also has nothing to do with the difference between weak and strong typing. It is about Python not disambiguating between variable shadowing and variable reassignment.

Here's a comment of mine that explains why Python is weakly typed: https://news.ycombinator.com/item?id=26354039.

Re:Go is not an easy language by solosoyokaze on Monday February 22, 2021 @12:17PM (#26227108)
So what's the type signature of `print()` then?

I do think my example code demonstrates why Go is easier to reason at scale than Python. Python is conflating assignment and type declaration. Go has = and :=, so it's crystal clear what's going on.

Re:Go is not an easy language by dexterlemmer on Friday March 05, 2021 @03:23AM (#26354303)
> So what's the type signature of `print()` then?

I like the way Rust makes clear what are the different possibilities:

In Rust we use a macro to handle variadic arguments, but if it was just a case of supporting different types, not of supporting an arbitrary number of arguments we would've had three options for the type signature:

1. Monomorphic duck typing: `fn print(arg: &impl Debug)`. Here the compiler simply generates multiple print functions, one for every type the function gets called on. The exact concrete type is known at compile time.

2. Polymorphic dynamic dispatch (with dynamic sizing) duck typing: `fn print(arg: Box<dyn<Debug>>)`. Here the compiler generates a vtable and allocates on the heap. Only a type approximation is known at compile time, not the exact concrete type, but it still counts as static typing.

3. Dynamic typing: `fn print(arg: Box<dyn<Any>>)`. Note `Any` in stead of `Debug`. Full dynamic typing with the type completely unknown at compile time. Juck! But occasionally useful for prototyping or for FFI with dynamically typed languages.

Re:Go is not an easy language by anaerobicover on Monday February 22, 2021 @01:01PM (#26227825)
> what's the type signature of `print()` then?

Dynamic typing doesn't rule out polymorphism.

    void print(PyObject objects...)
where `PyObject` is a base type.

Additionally, you could perfectly well have constants, or require variables to have a fixed type, in a dynamic language. You would just pay a cost at runtime to check the type on assignment.

Re:Go is not an easy language by solosoyokaze on Monday February 22, 2021 @01:10PM (#26227964)
I would argue that you pay the cost at runtime but you also pay a cognitive overhead cost while writing in a dynamically typed language. Refactoring in particular is a lot more difficult.
Re:Go is not an easy language by dexterlemmer on Friday March 05, 2021 @03:24AM (#26354311)
I agree. But this particular example ironically has nothing to do with dynamic typing.
Re:Go is not an easy language by anaerobicover on Monday February 22, 2021 @12:26PM (#26227248)
> what's the type signature of `print()` then?

Dynamic typing doesn't rule out polymorphism.

    void print(PyObject objects...)
where `PyObject` is a base type.
Re:Go is not an easy language by dexterlemmer on Friday March 05, 2021 @02:54AM (#26354058)
This has nothing to do with either dynamic or weak typing in Python. It's just Python not disambiguating between shadowing and reassignment.

Here's a comment of mine that explains why Python is weakly typed: https://news.ycombinator.com/item?id=26354039.

Re:Go is not an easy language by lhjn on Monday February 22, 2021 @07:23PM (#26232436)
Bad example, booleans in python are integer subclasses since forever... 2 + True = 3. Also, False in [1, 2, 0] evaluated to True. But you're still right saying python is strongly typed.
Re:Go is not an easy language by itake on Sunday February 28, 2021 @05:27PM (#26297705)
Companies use golang for web services, which directly competes with Ruby and Python.
Re:Go is not an easy language by Cthulhu_ on Monday March 01, 2021 @04:44AM (#26301105)
And Java, which (I feel like) is used for bigger, long-term projects.
Re:Go is not an easy language by Can_Not on Monday February 22, 2021 @06:55PM (#26232244)
> the competition to Go isn't Ruby and Python, it's C++ and Rust.

Crystal is a pretty solid alternative to golang.