←back to thread

Go subtleties

(harrisoncramer.me)
234 points darccio | 10 comments | | HN request time: 0s | source | bottom
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 #
1. 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 #
2. 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 #
3. kace91 ◴[] No.45669041[source]
>it's not a problem of the language, but the author's unfamiliarity with the tools at their disposal.

If you have to share a codebase with a large group of people with varying skill levels, limiting their ability to screw up can definitely be a feature, which a language can have or lack.

As always, it comes with tradeoffs. Would you rather have the ability to use good, expressive abstractions or remove the group’s ability to write bad ones? It probably depends on your situation and goals.

4. lagniappe ◴[] No.45669329[source]
>most certainly write incomprehensible code in it

I've tried my best to make indecipherable go code and failed. Do you have any examples?

5. ttz ◴[] No.45672342[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 #
6. 9rx ◴[] No.45673110[source]
Formal proof languages are pretty neat, but nobody really uses them in the real world. Among the languages that people actually use on a normal basis, even those that claim to have extensive type systems, they still rely on testing for most everything, and once you're relying on testing anyway the type system isn't any kind of real saviour.

There is, perhaps, some segment of the developer community who believe that they are infallible and don't need to write tests, but then have the type system exclaim their preconceived notions are wrong, and then come to love the type system for steering them in a better direction, while still remaining oblivious to all the things the incomplete type system is unable to statically assert. But that's a rather bizarre place to be.

replies(1): >>45674447 #
7. DanielHB ◴[] No.45673305{3}[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 #
8. tyre ◴[] No.45674447{3}[source]
Typescript’s type system is a huge leap up from JavaScript.

You still need tests for functionality (this function does what it should) but the type system removes many error cases automatically.

replies(1): >>45676595 #
9. ttz ◴[] No.45674948{4}[source]
NPEs are also present in a lot of languages with "stronger" type systems though. Is there a specific language you're comparing against?
10. 9rx ◴[] No.45676595{4}[source]
It is a huge boost in developer ergonomics.

But doesn't change the tests you need to write, and those tests are going to incidentally cover anything the type system is also going to catch, so the type system isn't going to somehow make your software more reliable.

A much more expressive type system can get you there, but you won't find that in any language anyone actually uses on a normal basis.