6 ms·
My one-line workaround. (Yes, I ban go fmt.) v := a; if t { v = b } Sadly, this doesn't work well if a is a function call :-(
by networkimprov 7y ago
My one-line workaround. (Yes, I ban go fmt.)
v := a; if t { v = b }
Sadly, this doesn't work well if a is a function call :-(
- _bxg1 7y agoOut of curiosity, what's the motivating case for using Go in 2019's programming landscape? Edit: I didn't mean this as an insult, I meant it as a genuine question. I don't know much about the Go ecosystem, and I meant to find out what Go's killer feature is in 2019, when other languages now have strong and elegant concurrency, C-like performance with higher-level syntax and without manual memory management, etc.
- blablabla123 7y agoWriting any type of network server from scratch is quite straight-forward if you know how to do it. Obviously concurrency is also available to the fullest.
- 886 7y agoyou make it sound like Go is not top tier in the 2019's programming landscape and there is a good alternative. Can you elaborate?
- meddlepal 7y agoYes it's called Java.
- dang 7y agoMaybe so, but please don't post unsubstantive comments here.
- bluquark 7y agoKotlin and Swift are both currently encroaching on Go's server-side use cases. For example, Go's star feature, goroutines, has recently been cloned by Kotlin. They are at least as equally pleasant to program in, and they're hitched to major client platforms which means they improve faster and will definitely have a pool of trained developers in the long term.
- apta 7y agoJava is getting a fiber implementation by means of project Loom, which will make golang even less appealing. The good thing is that because the fiber implementation will be built into the JVM, Kotlin and other languages can use them seamlessly.
- 886 7y agoPoints taken. I am full time on Go since few years ago and before that I was 100% Java. Haven't really kept myself up-to-date with the Java land. But from my experience with Java, Go, and Python, I find Go a very versatile programming language. Being able to compile binaries means it's great for infrastructure deployments and CLI tools. Goroutines, concurrency, and etc make it a great choice for server/micro service use cases as well. Some can say that not having a JVM is a plus as well. However, developers do have to be disciplined with error handling and dependency management. But one can argue that this is the case for software development in general.
- bluquark 7y agoJVM is gaining self-contained deployable package support, and as of recently, Kotlin supports a mode with LLVM-based native code generation. IMO, the fundamental advantages of Go over competing languages in the long run are its fast compile time and its combination of native code+garbage collection.
- lllr_finger 7y agoI'd propose Rust - it's also a static, stack-favoring, non-class-based language with OO features that compiles down to native binaries. Where it differs is a wonderful type system and top tier package management. If you can work through lifetimes and the borrow checker, you might enjoy it.
- 886 7y agoYes, that's true. Rust is good alternative to Go, and probably the closet to Go in terms of feature parity. Definitely worth checking out.
- weberc2 7y agoProductivity. There just aren't other languages that let me build things quickly with confidence that those projects will also scale well into the future. You don't need to employ people to set up the build system, you don't need to recruit for people who already know the language, you don't need to quibble about which features to use or what style to use or what IDE to use, deployment is a breeze, etc.
- mhh__ 7y agoSunk cost (In a good way). I do not like Go the language but I can begrudgingly admire the ecosystem
- LanceH 7y agoI use Ruby and Go in a complementary way. I find myself choosing Go for: - concurrency - memory footprint management - cpu speed - that nebulous feeling I want a program etched in stone (strongly typed) I've written a lot of Api based clients. Read from a queue and update AWS permissions. Receive a callout from something and passing it along to somewhere else. Come to think of it, I've written a lot of queue-reading workers, some replaced existing Ruby workers for CPU or concurrency reasons. I think in the space of having computers talk to computers Go is highly successful because it handles nearly everything with the standard library. So I find a lot of sdk's for specific platforms written in go that can get something going with the standard library and a single package for the platform.
- randallsquared 7y agoGo's star feature is straightforwardness. Some people call this simplicity. The upshot is that it is very easy to use Go within teams of inconsistent expertise. Since there is a fairly low ceiling to cleverness, Go rewards just getting started rather than spending time making the code smaller, or more general. Of course, this is not as good for having fun programming, unless the programmer feels having written something is more fun than writing it.
- _bxg1 7y agoThis seems similar to one of the main virtues of using Java - there's pretty much just one way to do any given thing and there's a "low ceiling to cleverness". Of course, Go's other features stand out much more when we're comparing to Java specifically.
- pdmccormick 7y agoI happen to love the C language, and my brain is very much tuned to how it works and the world view that it embodies. Go feels to me like veteran C language experts made a thoughtful evolutionary step forward. It's certainly not on the cutting edge of programming language theory, but it has solidly moved the baseline ahead. It's a highly opinionated language, but if you approach those opinions with an open mind, you'll find it has a sense of internal coherence that is both tasteful and pragmatic. Fast compilation speed, easy integration with C, and the "one large static binary" are probably my favourite features, although I do wish those binary sizes weren't quite so large...
- holy_city 7y agoTo be fair that's generally good practice since it eliminates a branch in the code, depending on the type of v and overhead of assignment.
- DuskStar 7y agoSounds like the sort of thing your compiler should choose for you.
- DuskStar 7y agoBanning go fmt gets rid of one of the best parts of the go ecosystem, and I am horrified that you would do so. go fmt may not be anyone's favorite code style, but having go fmt is so much better than dealing with everyone else's favorite (incompatible!) styles.
- networkimprov 7y agoThere is no spec for go fmt. Its behavior has changed across releases. It has no switches to disable features. It destroys many nice single-line constructs, e.g. if err != nil { return err } Much of my code would be painful to read without that one. On the bright side, it artificially inflates your line count, so you appear more productive!
- DuskStar 7y agoI think we're going to have to disagree there, then - yes that oneliner might reduce your LOC count and help you win at code golf, but it doesn't actually make things more readable and certainly isn't worth breaking from the rest of the community. The ecosystem-wide consistency of go fmt is its biggest strength. Adding switches to disable features would eliminate that.
- networkimprov 7y agoThere is a lot more to effective code style than whitespace, and most Go code I've seen doesn't consider that, including the stdlib. I've put a lot of thought into my style guide, and anyone who hasn't done the same has no useful insight on whether go fmt is a help or a hindrance.
- _bxg1 7y ago> one of the best parts of the go ecosystem Is it more powerful in some way than the auto-formatters that exist for nearly every other language?
- DuskStar 7y ago