Live data from Hacker News

Diving into Go by building a CLI application

eryb.space

21–30 of 124 posts

Re: Diving into Go by building a CLI application

#21
Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python.

It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might be a good choice for prototyping.

I actually started learning Go with CLI applications. I have found that https://github.com/spf13/cobra tends to be one of the better CLI helpers you can get into but https://github.com/jpillora/opts is one I have been meaning to try following a presentation I saw on it once.

Re: Diving into Go by building a CLI application

#22

Is it possible to display images in terminal? Terminal is simultaneously powerful and painful tool. I know a guy that refuses to use anything but CLI and suffers a lot. But most basic apps can be written it in like those BIOS menus from a 2005 dell computer.

It depends on the console/terminal. iTerm has a native ability to do this, the built-in Linux console has some programs like FIM http://www.nongnu.org/fbi-improved/.

Re: Diving into Go by building a CLI application

#23

I had a similar idea a couple of months ago. Make a CLI in golang that allows me to easily open all my favorite timewaster sites at the start of the work day. But it ended up in the "Started, but never looked at again" pile. Maybe I'll have another look at it on the weekend.

By all means write code if it's fun, but couldn't you just make a bookmark folder and right click > open all?

Re: Diving into Go by building a CLI application

#24

Is it possible to display images in terminal? Terminal is simultaneously powerful and painful tool. I know a guy that refuses to use anything but CLI and suffers a lot. But most basic apps can be written it in like those BIOS menus from a 2005 dell computer.

iTerm 2 supports imgcat, which shows images inline in the terminal:

https://www.iterm2.com/documentation-images.html

Re: Diving into Go by building a CLI application

#26

Is it possible to display images in terminal? Terminal is simultaneously powerful and painful tool. I know a guy that refuses to use anything but CLI and suffers a lot. But most basic apps can be written it in like those BIOS menus from a 2005 dell computer.

Are you talking about ncurses like interfaces? I have been using tview - https://github.com/rivo/tview/ (based on another library tcell - https://github.com/gdamore/tcell). Very useful.

Re: Diving into Go by building a CLI application

#27
post #21

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python. It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might b…

Not sure why this is downvoted. Java, C#, and Python all tend to have slow CLIs. This is very much in-line with my experience. Even if the VMs do start up quickly, people tend to do a lot of expensive initialization, class loading, etc before the program starts. Go’s runtime is minimal by comparison and there is much less work done at initialization (by convention) than in Python, Java, etc.

Re: Diving into Go by building a CLI application

#28
post #21

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python. It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might b…

CLIs are sorta my ideal use-case for Go. Goroutines are so error-prone to control since you don't have many options for abstraction, so it's relatively difficult to build long-running highly-stable programs...

But CLIs don't usually need that. They can be ctrl-C'd if they go off the rails, and any dangling goroutines just die when the process dies. The simple distribution, fast startup, simple type system, and yolo-concurrency really pay off in pleasantly small and performant tools. And the stdlib is cross platform, quite capable, and very friendly to use. It's almost exactly what you want when you need to go beyond a tiny bash script, to something that might be a up to a couple thousand lines.

I do wish the built-in flags lib wasn't so abhorrent though. Pulling in a replacement lib is step 1 for any CLI.

Re: Diving into Go by building a CLI application

#29

Is it possible to display images in terminal? Terminal is simultaneously powerful and painful tool. I know a guy that refuses to use anything but CLI and suffers a lot. But most basic apps can be written it in like those BIOS menus from a 2005 dell computer.

Are you talking about ncurses like interfaces? I have been using tview - https://github.com/rivo/tview/ (based on another library tcell - https://github.com/gdamore/tcell ). Very useful.

I am imagining like a gallery app such as Instagram purely in terminal lol never mind the consequences of the user base being primarily sys admins and software engineers. I could imagine browsing a rather weird Instagram clone.

Re: Diving into Go by building a CLI application

#30
post #28
post #21

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python. It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might b…

CLIs are sorta my ideal use-case for Go. Goroutines are so error-prone to control since you don't have many options for abstraction, so it's relatively difficult to build long-running highly-stable programs... But CLIs don't usually need that. They can be ctrl-C'd if they go off the rails, and any dangling goroutines just die when the process dies. The simple distribution, fast startup, simple type system, and yolo-c…

Interestingly my current CLI project https://github.com/boyter/cs/ does need to be stable because I am putting a TUI mode into it... and yes dealing with the dangling goroutines in it for the TUI mode itself is especially painful.

Generally if you just stick to fan-out-in processing though I find goroutines not too bad.

Post reply on HN