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?
Diving into Go by building a CLI application
111–120 of 124 posts
Re: Diving into Go by building a CLI application
#112Took your code, added a random number generator and threw it into a Go HTTP server and deployed it as a GCP Cloud Function :-) https://us-central1-bookshelf-app-1103.cloudfunctions.net/Ra... Voila!! Serverless Random XKCD..
Re: Diving into Go by building a CLI application
#113Earlier 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…
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
#114Re: Diving into Go by building a CLI application
#115Earlier 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…
Re: Diving into Go by building a CLI application
#116Earlier 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
# 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
#117I 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.
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
#118Earlier 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…
Re: Diving into Go by building a CLI application
#119Earlier 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...
Re: Diving into Go by building a CLI application
#120Is 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