←back to thread

Go subtleties

(harrisoncramer.me)
234 points darccio | 2 comments | | HN request time: 0.001s | source
Show context
valzam ◴[] No.45666643[source]
Great list of why one can love and hate Go. I really did enjoy writing it but you never get the sense that you can be truly certain your code is robust because of subtle behaviour around nil.
replies(3): >>45666654 #>>45667227 #>>45671606 #
valzam ◴[] No.45666654[source]
I guess as a corollary, Go really rewards writing the dumbest code possible. No advanced type shenanigans, no overuse of interfaces, no complex composition of types. Then you will end up with a very fast, resource light system that just runs forever.
replies(5): >>45666706 #>>45666893 #>>45669853 #>>45671891 #>>45672663 #
theshrike79 ◴[] No.45666706[source]
And code with zero ability to do fancy trickery ("expressive" as some people like to say) is easy to read even if the codebase - or even the language - is unfamiliar.

Which is really handy when shit's on fire and you need to find the error yesterday. You can just follow what happens instead of trying to figure out the cool tricks the original programmer put in with their super-expressive language.

Yes, the bug is on line 42, but it does two dozen things on the single line...

replies(3): >>45667256 #>>45672153 #>>45673868 #
spoiler ◴[] No.45667256[source]
I know it's not exclusive to Go or any language, but you can most certainly write incomprehensible code in it. If anything, expressiveness and proper abstractions can save you from this.

I think people often get burnt by bad abstractions in expressive languages, but it's not a problem of the language, but the author's unfamiliarity with the tools at their disposal.

If someone starts being clever with abstractions before understanding the fundamentals, it can lead to badly designed abstractions.

So I guess if there's less things to master, you can start designing good abstractions sooner.

So, in my experience, if we invest time to truly understand the tools at our disposal, expressive languages tend to be a great boon to comprehension and maintenance.

But yes, there's definitely been times early in my career where I abstracted before I understood, or had to deal with other bad abstractions

replies(3): >>45667769 #>>45669041 #>>45669329 #
DanielHB ◴[] No.45667769[source]
I like to say this: "Only my code is allowed to be clever"

But, on a serious note, I agree with you. Go lacks a lot of power, especially in its type system, that causes a ton of problems (and downtime) that in other languages is trivial to prevent statically.

replies(2): >>45672342 #>>45673110 #
ttz ◴[] No.45672342{3}[source]
out of curiosity (not meant snidely), do you have an example of a case where the weaker type system resulted in serious problems?
replies(1): >>45673305 #
1. DanielHB ◴[] No.45673305{4}[source]
Pretty much any null pointer deference error ever?

But it is hardly ever the weak type system that is at fault, just good use of a stronger type system could have prevented the issue.

Once you start to make "invalid states unpresentable" and enforcing those states at the edges of your type system suddenly a lot of bizarre errors don't happen anymore.

replies(1): >>45674948 #
2. ttz ◴[] No.45674948[source]
NPEs are also present in a lot of languages with "stronger" type systems though. Is there a specific language you're comparing against?