Clear defensive programming with Go using Verifier library
itnext.io
itnext.io
switch {
case transfer == nil:
return nil, ErrInvalidTransfer
case person == nil:
return nil, ErrInvalidPerson
// ...
}
This, to me, is both concise and clear.I can see the appeal of wanting to create a package to manage error checking when you have dozens of conditions but this doesn't bring anything new to the table yet creates code that is arguably less maintainable and certainly less easily read.
Some days I even believe that by promoting developer's mental laziness to not learn new paradigms/more advanced languages/technical systems we are just delaying the progress of humanity.
EDIT: advanced for its age -> advanced for its time
Go's bare-bones practical, opinionated simplicity can eliminate, right from the start, huge numbers of decision points developers might face any given day while using more complex and expressive languages, with plethoras of elegant abstractions to fit every situation. Thats really valuable IMHO, when any one of those decision points can lead to technical debt, or lost time and energy on internal (and external) technical debates.
Its an especially huge win when building software to perform necessarily complex work (like distributed container orchestration).
I would like a citation on that.
I remember there being a study on how several groups of students would solve a problem in C, Go, and Rust. I can't find the link unfortunately, but IIRC, the conclusion was that C was the "buggiest" and Rust the "safest" with Go being in the middle, but the speed of development was much higher for Go and C.
Go is a practical language designed to improve the situation. You aren't going to convince someone who writes socat or curl or whatever in C to use Clojure or Ada instead. They might plausibly use Go though.
Go is awesome for what it is.
Goroutines and channels are best used as concurrency primitives, not parallelism tools.
P.S. I am being a bit too hard on Go, but my whole point is that after seeing really complete solutions for this problem, everything else pales next to them and that we still encounter unnecessary problems.
However arguments about the developer aside, Go has other advantages that drew me to it. Such as
* cross-compiling requiring no additional effort aside setting an env var (It's been a why since I've written C++ but I seem to recall no end of bother there. Again a seasoned developer will argue it's easy but I certainly didn't find it that way)
* It compiles down to a portable executable (there are surprisingly few languages that do that)
* It's not overly verbose. Ok, this is only true if you're not having to work around generics or the "if err != nil" syntax. But for most problems I've found Go to be refreshingly direct.
* It enforces strict code layout guidelines so I can pick up anyone's code and can run with it easily enough.
* Compiler error messages are very easy to understand.
Sure there are other languages that cover some, maybe most of those points. But few cover all. Which is why I often describe Go as "a boring language that's pleasant for just getting shit done". Which is why I tend to favour Go these days despite having learned more than a dozen different languages over the years.
Needless to say a great many of people - both on and off HN - will disagree with me. But that's the beauty of personal opinion. Programming languages really are just the realm of preference.
Because both inexperienced and experienced developers will be prevented from doing the wrong thing more often when using a better language.
I mean if performance Vs C++ was a primary concern then you're limiting yourself to quite a small subset of languages, most of which either have a steep learning curve and/or sacrifice security. This doesnt make sense for the majority of developers out there since very few people really need the performance of C++. That's not to say performance doesn't matter but rather Go's performance is more than adequate for most of the applications it is applied to.
To further that point just look at how I've used Go. I've written two FUSE file systems and a UNIX $SHELL in Go and found the performance to be good enough even on my relatively modest dev machine. I've also written log file parsers that can handle gigabytes or records in seconds. I'm happy with that level of performance because for me developer productivety matters a lot more since I have 2 small kids so hobby projects get very little time allocated to them. This means I'd rather prototype code then optimise later rather than spend comparatively longer building a POC that ultimately might never get enough time to see the light of day.
However you will have your own set of requirements which Go might underperform on and those reasons are as important to you as my requirements are to me.
This is why arguing about how some languages are bad or which are the best is about as worthwhile as arguing which colour is the "best".
This reminds me of Oulipo, a group of writers and mathematicians seeking to create literary work using constrained writing techniques.
Go is the Oulipo of programming: its simplicity stimulates creative programming :-)
Sorry, no thanks.
But the senior developer should catch it in a review before ...
> ...deploy it somewhere where it would explode in runtime.
If that's not the case (and it's not clear from any of the documentation), it seems like this adds no real value, and in my opinion actually makes the error handling ugly and harder to maintain.
Also, use package-defined, exported error types that you can refer to by name, and errors become useful data again like Go intended.
But the other validations are more about contracts. Preconditions, to be precise. Yes, I know that a sufficiently advanced type system (dependent types?) could encode those in the function signature, but I am not entirely sure if the technology is already there.
I’d pay you a lot of money to develop a readable functional language that interoperates seamlessly with Go and shares its runtime.
I don't agree. I'll take if-statements over a validation library 99% of the time.
This is how we validation a message coming into our REST+JSON API: https://github.com/ohsu-comp-bio/funnel/blob/master/tes/vali...