Live data from Hacker News

Diving into Go by building a CLI application

eryb.space

51–60 of 124 posts

Re: Diving into Go by building a CLI application

#51
I wrote a Go CLI Boilerplate sometime back: https://github.com/pulkitsharma07/go-cli-boilerplate, it addresses some common issue which I faced while developing a full-fledged CLI.

Features (From Readme):

* Unit and Integration test structure for the CLI

* Opinionated directory structure for organizing code for commands.

* Docker-based cross-platform build pipeline

* Travis CI-based release workflow

* Makefile for common tasks like generating documentation and building the binary.

Re: Diving into Go by building a CLI application

#52

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.

iTerm2 on OSX supports inline images. https://iterm2.com/documentation-images.html

Let's you do stuff like this: https://twitter.com/heinrichhartman/status/12655859919282216...

Re: Diving into Go by building a CLI application

#53
post #48
post #37

Earlier quoted context omitted.

> [Go] is forgiving enough that you can do exploratory programming in it. I agree with most of your post, but I’m not sure I would describe Go as “forgiving”. In fact, it’s well known for being strict. For example, exploratory programming would be significantly easier if the Go compiler could (optionally) ignore unused variables and unreachable code. I’ve also found exploratory programming in Go is hindered by needin…

> Maybe I’m doing something wrong, but my Go code is often littered with casts between different integer sizes and signedness. It can actually be a feature, and one of the things that brought me to go, as you can define your own integer (or float, or string, etc.) types, thus making them incompatible with each other: type distance int type speed int func distFor(d distance, t time.Time) speed { ... } ... x = distFor(…

This is probably the biggest thing I wish was easier to do in Rust. You can make "newtypes" by wrapping the value in a tuple (that gets compiled away), but it's a fair amount of boilerplate or macros to make the newtype useful. Once you have what you need, it's fine, but it's even less convenient for exploratory programming ;-)

Re: Diving into Go by building a CLI application

#54
post #48

Earlier quoted context omitted.

> Maybe I’m doing something wrong, but my Go code is often littered with casts between different integer sizes and signedness. It can actually be a feature, and one of the things that brought me to go, as you can define your own integer (or float, or string, etc.) types, thus making them incompatible with each other: type distance int type speed int func distFor(d distance, t time.Time) speed { ... } ... x = distFor(…

This is probably the biggest thing I wish was easier to do in Rust. You can make "newtypes" by wrapping the value in a tuple (that gets compiled away), but it's a fair amount of boilerplate or macros to make the newtype useful. Once you have what you need, it's fine, but it's even less convenient for exploratory programming ;-)

Oh, Rust does not have elegant strong typedefs? Bummer. Are they at least planned? It's such a boon for type correctness/safety.

Re: Diving into Go by building a CLI application

#55
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…

I agree. I think Rust is also excellent for CLI apps. Also better than the other languages you mention.

Re: Diving into Go by building a CLI application

#57
I love using Go for CLIs. Previously, I developed CLIs with JavaScript (NodeGH, something with the same goal as GitHub's CLI), and "kind of" with PHP as well (for internal tasks on a server). Nothing compares with writing one with Go, though.

I used to be the maintainer of a CLI for a PaaS until a year ago: https://asciinema.org/a/192043 https://github.com/henvic/wedeploycli

Re: Diving into Go by building a CLI application

#59
post #54

Earlier quoted context omitted.

This is probably the biggest thing I wish was easier to do in Rust. You can make "newtypes" by wrapping the value in a tuple (that gets compiled away), but it's a fair amount of boilerplate or macros to make the newtype useful. Once you have what you need, it's fine, but it's even less convenient for exploratory programming ;-)

Oh, Rust does not have elegant strong typedefs? Bummer. Are they at least planned? It's such a boon for type correctness/safety.

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

Re: Diving into Go by building a CLI application

#60
post #48

Earlier quoted context omitted.

> Maybe I’m doing something wrong, but my Go code is often littered with casts between different integer sizes and signedness. It can actually be a feature, and one of the things that brought me to go, as you can define your own integer (or float, or string, etc.) types, thus making them incompatible with each other: type distance int type speed int func distFor(d distance, t time.Time) speed { ... } ... x = distFor(…

This is probably the biggest thing I wish was easier to do in Rust. You can make "newtypes" by wrapping the value in a tuple (that gets compiled away), but it's a fair amount of boilerplate or macros to make the newtype useful. Once you have what you need, it's fine, but it's even less convenient for exploratory programming ;-)

> but it's a fair amount of boilerplate or macros to make the newtype useful.

As mentioned in the docs, you can use the Deref facility to have the newtype implement everything that the original type does. Rust just gives you the choice of doing this vs. wrapping with a custom set of impls.

Post reply on HN