Live data from Hacker News

Learning Go by porting a medium-sized web back end from Python

benhoyt.com

21–30 of 207 posts

Re: Learning Go by porting a medium-sized web back end from Python

#21
I can agree with most of the article, but for some it looks like we have not been using the same language ecosystem at all.

Go really feels opinionated around the wrong things, in order to claim "simplicity" as a feature:

- No generics just mean you're going to be handing interface{} all the way in your stack, it makes things more complex and less readable for no reason (and less safe)

- error handling which is essentially string-based, in 2017? Give me a type system, please

- gofmt is a good idea (just like clang-format or yapf), and having it is great, but the maintainers specifically refuse to add simple features, saying "running it in an automated process is not supported", despite all github projects already having it in their automated CI suite

- go test is good, but in the end it is found lacking

- dep, well, if you don't mind dumping the code for all your deps in the source tree, it's probably ok, but it solves a deficiency that the language should not even have (see next point)

- stability: the language itself is fine on that, but the ecosystem really isn't. The fact that they don't even have the package management quality of python (which I find awful already) is baffling. I don't even know how they could think "yeah, github-importing is a good idea, let's do it". Go is eight years old tomorrow and you still have to rely on third-party tooling to do proper imports that don't burn your house.

Re: Learning Go by porting a medium-sized web back end from Python

#22
post #7

Earlier quoted context omitted.

I really wish that there was a language which had these features: - simple (so not Scala, Haskell, Perl 6, etc.; no Rust either, unfortunately) - clean (nice syntax, preferably Python inspired, but consistent) - modern (generics, some functional features, string interpolation, etc.) - decent concurrency/parallelism story - good IDE, preferably supported by the core dev team - compilation to a (possibly static) native…

Other than the compilation to binary, Elixir seems a good fit for what you're looking for

Elixir compiles to bytecode which is not half bad

Re: Learning Go by porting a medium-sized web back end from Python

#23

I can agree with most of the article, but for some it looks like we have not been using the same language ecosystem at all. Go really feels opinionated around the wrong things, in order to claim "simplicity" as a feature: - No generics just mean you're going to be handing interface{} all the way in your stack, it makes things more complex and less readable for no reason (and less safe) - error handling which is essen…

>- No generics just mean you're going to be handing interface{} all the way in your stack, it makes things more complex and less readable for no reason (and less safe)

Depends on what you do. I've written a good chunk of go code and interface{} is the rare exception rather than the rule, usually employed where a user might supply arbitrary types (ie a unmarshaljson like function)

But if you do a website or webapp, 99% of your code is not using interface{} in it's methods.

>- error handling which is essentially string-based, in 2017? Give me a type system, please

You can put anything behind an error:

    type IntErr uint64
    func (i IntErr) Error() string {
        return strvonc.Atoi(i)
    }
The string is only present when you either use the stdlib errors or you output an error.

Additionally, nothing in Go forces you to actually use the error interface (sans stdlib).

You can invent your own Error interface that uses ints. (Won't work with most external libraries but nothing is stopping you)

Panic and Recover can to my knowledge both handle things that aren't errors; recover returns a interface{} that you check for value and type. You can put anything in there.

>stability: the language itself is fine on that, but the ecosystem really isn't.

A lot of projects focus on stability. If the API is breaking a lot they usually use Gopherpit or gopkg.in to ensure compatibility in the future.

In my experience, breaking the API is not something well used libraries do lightly (libraries with no or little use do break it sometimes since they lack the usage to refine it)

If you need more, you can use vendoring.

Re: Learning Go by porting a medium-sized web back end from Python

#24
post #5

I'm at the same spot myself, trying to learn Go by building a simple web app. Your article was a refreshing read to me. One extra thing that is the major motivation for me to go to Go is the ability to deploy as a single God damn binary and not deal with dependancies and pip. pip and counting on OS repositories may be the right thing to do, but it is just too cumbersome. I have an air gapped setup at work, and there…

Coming from a data science background, don't anaconda and environment description files [1] solve this problem with python? Not even sudo is needed to install anaconda and setup / clone environments, also it can manage python versions independently from the system's python. [1] https://conda.io/docs/user-guide/tasks/manage-environments.h...

Thanks for your comment.

I have just started using Conda locally to learn before taking it to work. I'm a new sysadmin and my predecessor maintained a restricted list of python packages on all cluster systems like a dictator. I don't want to be one.

Does conda cloning the environment mean I can just copy the project directory to another server and expect my program to run without it looking for the packages on the internet?

Re: Learning Go by porting a medium-sized web back end from Python

#25
post #10
post #7

Earlier quoted context omitted.

I really wish that there was a language which had these features: - simple (so not Scala, Haskell, Perl 6, etc.; no Rust either, unfortunately) - clean (nice syntax, preferably Python inspired, but consistent) - modern (generics, some functional features, string interpolation, etc.) - decent concurrency/parallelism story - good IDE, preferably supported by the core dev team - compilation to a (possibly static) native…

C# actually already has most of that except for "compilation to a (possibly static) native binary", which is really just a convenience for shipping. It's also not really very cross-platform, it's definitely a "Windows First" language.

> it's definitely a "Windows First" language

C# used to be that but I don't think that's the direction anymore.

Re: Learning Go by porting a medium-sized web back end from Python

#26
post #7
post #3

Recently I have had the opportunity to write a microservice in Go. It was a very refreshing experience switching from Scala. Go is a lot faster to compile and runs with a far smaller footprint. The channels are nice. On the other hand the testing feels wrong because its so annoying to do mocks. And don't even get me started on the dependency management. Overall Go feels to me like some version compiled PHP with bette…

I really wish that there was a language which had these features: - simple (so not Scala, Haskell, Perl 6, etc.; no Rust either, unfortunately) - clean (nice syntax, preferably Python inspired, but consistent) - modern (generics, some functional features, string interpolation, etc.) - decent concurrency/parallelism story - good IDE, preferably supported by the core dev team - compilation to a (possibly static) native…

Kotlin covers all those features

- much simpler than Scala while still being much more expressive than Java

- clean syntax, with a higher consistency than e.g. Java

- Generics, Higher Order Functions, Multiline-Strings, Destructuring, ADTs, Pattern Matching

- Coroutines (experimental but production-ready)

- IntelliJ Community Edition (or Ultimate)

- not yet but will be possible with Kotlin Native

- has its own ecosystem but also has great interoperability with Java

- stable for quite some time, big community

- well, a little bit for reasons of Java-interoperability; on the other hand

Re: Learning Go by porting a medium-sized web back end from Python

#27
post #18
post #7

Earlier quoted context omitted.

I really wish that there was a language which had these features: - simple (so not Scala, Haskell, Perl 6, etc.; no Rust either, unfortunately) - clean (nice syntax, preferably Python inspired, but consistent) - modern (generics, some functional features, string interpolation, etc.) - decent concurrency/parallelism story - good IDE, preferably supported by the core dev team - compilation to a (possibly static) native…

Believe kotlin (especially kotlin-native) should soon relieve all those itches.

Yeah, but Kotlin Native loses all the Java libraries. The more interesting thing would be Java native compilation coupled with Kotlin. So you'd write a Kotlin Java app and pass that through the Java native compiler introduced in Java 9. Unfortunately that's a beta feature right now, I think it only supports Linux x64, that's why I said Kotlin 2019, I assume that by then the Java native compiler will support all Java platforms.

Re: Learning Go by porting a medium-sized web back end from Python

#28
post #7
post #3

Recently I have had the opportunity to write a microservice in Go. It was a very refreshing experience switching from Scala. Go is a lot faster to compile and runs with a far smaller footprint. The channels are nice. On the other hand the testing feels wrong because its so annoying to do mocks. And don't even get me started on the dependency management. Overall Go feels to me like some version compiled PHP with bette…

I really wish that there was a language which had these features: - simple (so not Scala, Haskell, Perl 6, etc.; no Rust either, unfortunately) - clean (nice syntax, preferably Python inspired, but consistent) - modern (generics, some functional features, string interpolation, etc.) - decent concurrency/parallelism story - good IDE, preferably supported by the core dev team - compilation to a (possibly static) native…

Nim has everything nailed down except the ecosystem/commercial backing; It does have some of those, but not to the extent that I would blindly tell you they are there.

It's as fun as writing Python (with a similar syntax), but it has essentially all the goodies you want from Lisp when you need them, runs as fast as equally optimized C, produces standalone native binaries, _or_ standalone JavaScript if that's your thing.

Re: Learning Go by porting a medium-sized web back end from Python

#29
post #28
post #7

Earlier quoted context omitted.

I really wish that there was a language which had these features: - simple (so not Scala, Haskell, Perl 6, etc.; no Rust either, unfortunately) - clean (nice syntax, preferably Python inspired, but consistent) - modern (generics, some functional features, string interpolation, etc.) - decent concurrency/parallelism story - good IDE, preferably supported by the core dev team - compilation to a (possibly static) native…

Nim has everything nailed down except the ecosystem/commercial backing; It does have some of those, but not to the extent that I would blindly tell you they are there. It's as fun as writing Python (with a similar syntax), but it has essentially all the goodies you want from Lisp when you need them, runs as fast as equally optimized C, produces standalone native binaries, _or_ standalone JavaScript if that's your thi…

I wish there was a Go->Nim compiler or a way to simply import stuff from Go :) I'm just half-joking to be honest.

Re: Learning Go by porting a medium-sized web back end from Python

#30
post #27
post #18

Earlier quoted context omitted.

Believe kotlin (especially kotlin-native) should soon relieve all those itches.

Yeah, but Kotlin Native loses all the Java libraries. The more interesting thing would be Java native compilation coupled with Kotlin. So you'd write a Kotlin Java app and pass that through the Java native compiler introduced in Java 9. Unfortunately that's a beta feature right now, I think it only supports Linux x64, that's why I said Kotlin 2019, I assume that by then the Java native compiler will support all Java…

Java compiles to native code since version 1.0, only not for free.

All commercial JDKs had this option in one form or the other, and many of them are still around.

If you want to try this for free on open source projects, Excelsior JET is one option.

Post reply on HN