Live data from Hacker News

Diving into Go by building a CLI application

eryb.space

111–120 of 124 posts

Re: Diving into Go by building a CLI application

#111

Is Go a good option to create some background tasks. For eg. monitor which Spotify songs are playing and and store that in a json file, etc. Or is Python more suitable for this?

Python has more libraries to write automation tasks than Go. It really depends on you situation, if I have a lot of time I'll do it in Go because everybody does it in Python :P

Re: Diving into Go by building a CLI application

#113
post #62

Earlier quoted context omitted.

Would you mind sharing some concrete feedback? I'll make improvements for next time.

Sure, I’m on a real keyboard now. You don’t need separate client and models packages. You should have two packages: main (which has only one line) and everything else (call it package xkcd). Your main continues even after it finds an error in fetching the comic. This is because you can’t return err in main and you didn’t use panic/log.Fatal. You also don’t exit with a non-zero code on error. The solution to all of th…

I really appreciate you effort in pointing out the correct way to do things.

In my defence I would like to point that this post was to help beginners get hands on experience writing Go code, adding design patterns or organising the code base to make things "correct" will only confuse a person who has just started to learn Go.

And to be frank, I too don't have much practical knowledge about it. If you don't mind can you point me in the right direction?

Re: Diving into Go by building a CLI application

#114
post #110

Earlier quoted context omitted.

It does have them: https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#...

I'm sorry but that does not look like an elegant first-class language construct, more like a pattern workaround.

What specific problems do you see with it?

Re: Diving into Go by building a CLI application

#115
post #113

Earlier quoted context omitted.

Sure, I’m on a real keyboard now. You don’t need separate client and models packages. You should have two packages: main (which has only one line) and everything else (call it package xkcd). Your main continues even after it finds an error in fetching the comic. This is because you can’t return err in main and you didn’t use panic/log.Fatal. You also don’t exit with a non-zero code on error. The solution to all of th…

I really appreciate you effort in pointing out the correct way to do things. In my defence I would like to point that this post was to help beginners get hands on experience writing Go code, adding design patterns or organising the code base to make things "correct" will only confuse a person who has just started to learn Go. And to be frank, I too don't have much practical knowledge about it. If you don't mind can y…

This was a big influence on my thinking: https://npf.io/2016/10/reusable-commands/

Re: Diving into Go by building a CLI application

#116
post #102
post #50

Earlier quoted context omitted.

Alternative: I'd say Java (or similar), since it has the language abilities and sophisticated static analysis tools are readily available. But startup time is still not interactively-fast, so for CLIs it's sorta a no. For long-running processes tho I mostly like it, and stuff like compacting GCs keeps it running healthier much more easily than Go. Beyond that, dunno - I usually reach for Python since I've written it…

> But startup time is still not interactively-fast, so for CLIs it's sorta a no They're working on it, for example: https://openjdk.java.net/jeps/310

They've been working on it for quite a while, yeah :) I appreciate it and they've made quite a lot of progress... but it's still nowhere near Go, and I mostly doubt it ever will be.

    # time ./hellogo 
    hello world
    
    real 0m0.005s
    user 0m0.001s
    sys  0m0.005s
It's probably "good enough" for many cases nowadays tho, yes, e.g.: https://cl4es.github.io/2019/11/20/OpenJDK-Startup-Update.ht...

Re: Diving into Go by building a CLI application

#117
post #31

I personally love building CLI tools in Node, since I and my co-workers all have it installed. Nice synchronous STD lib for file manipulation and async/await makes for compact async code. If I worked in a Go shop I'd probably use Go, though.

i always find it 'perverse' to start up a whole async event loop for a tool that then transforms a csv or does some other single task :-) also portability quite sucks. if you use features that my node version doesn't support, i screwed. with go (or C, Rust...), I just compile and distribute the binaries. look for instance how easy it is to install nomad.

Most of the tools we have use less than 100mb of ram - and a good number under 50mb. Point is, Node is pretty light for how fast you can build tools with it.

All my co-workers have the same version of Node, since we code in Node, so that argument is mute. My point was it depends on your environment! :)

Re: Diving into Go by building a CLI application

#118
post #113

Earlier quoted context omitted.

Sure, I’m on a real keyboard now. You don’t need separate client and models packages. You should have two packages: main (which has only one line) and everything else (call it package xkcd). Your main continues even after it finds an error in fetching the comic. This is because you can’t return err in main and you didn’t use panic/log.Fatal. You also don’t exit with a non-zero code on error. The solution to all of th…

I really appreciate you effort in pointing out the correct way to do things. In my defence I would like to point that this post was to help beginners get hands on experience writing Go code, adding design patterns or organising the code base to make things "correct" will only confuse a person who has just started to learn Go. And to be frank, I too don't have much practical knowledge about it. If you don't mind can y…

I rewrote your app in my style: https://github.com/carlmjohnson/go-grab-xkcd/commit/3edd1c70...

Re: Diving into Go by building a CLI application

#119
post #116
post #102

Earlier quoted context omitted.

> But startup time is still not interactively-fast, so for CLIs it's sorta a no They're working on it, for example: https://openjdk.java.net/jeps/310

They've been working on it for quite a while, yeah :) I appreciate it and they've made quite a lot of progress... but it's still nowhere near Go, and I mostly doubt it ever will be. # time ./hellogo hello world real 0m0.005s user 0m0.001s sys 0m0.005s It's probably "good enough" for many cases nowadays tho, yes, e.g.: https://cl4es.github.io/2019/11/20/OpenJDK-Startup-Update.ht...

You might want to check out: https://quarkus.io/

Re: Diving into Go by building a CLI application

#120
post #111

Is Go a good option to create some background tasks. For eg. monitor which Spotify songs are playing and and store that in a json file, etc. Or is Python more suitable for this?

Python has more libraries to write automation tasks than Go. It really depends on you situation, if I have a lot of time I'll do it in Go because everybody does it in Python :P

Thanks. If possible can you suggest some good libraries for background tasks in Python?
Post reply on HN