AstonJ

AstonJ

What's all the fuss about static-typing?

If you’re a fan, why?

If you’re not fussed on it, how comes?

Most Liked

Qqwy

Qqwy

To put it very concisely, these are I believe the two most important advantages of static typing:

  1. It removes whole class of potential bugs. Essentially all the undefined is not a function-style bugs are impossible in static type-systems. This means easier testing but also that less ‘defensive programming’ is required.
  2. Knowing that something is guaranteed to e.g. always be an integer allows for extra optimizations to happen.
lpil

lpil

Creator of Gleam

I find this an interesting statement as in my mind Go is a language with a painful lack of inference, types are required everywhere.

Here’s a fully type safe program in Elm:

main =
  let 
    double a = a + a
    twice f a = f (f a)
  in
  { name = ("Louis", "Pilfold")
  , score = twice double 50
  }

And here’s the same program written in Go:

type Name struct{
  First string
  Last  string
}

type Person struct{
  Name  Name
  Score int
}

func Main() Person {
  double := func(a int) int {
    return a + a
  }
  twice := func(f func(int) int, x int) int {
    return f(f(x))
  }
  return Person{
    Name: Name{
      "Louis",
      "Pilfold",
    },
    score: twice(double, 50),
  }
}

The Go version requires many more type annotations, and I would argue that many of them (especially the annotations on anonymous functions) provide no technical benefit at all. If anything they’ll make the code very slightly slower to compile as they need to perform inference inside the compiler to assert that they are correct.

To make matters worse, the Go version isn’t type safe (it lacks null checking and many other features), and it is less flexible (the double function only works with ints).

I like many things about Go, but in my opinion its type system leaves an awful lot to be desired.

dimitarvp

dimitarvp

In addition to what @Qqwy said :

  • The sum types – like Option and Result in Rust – allow for, and mandate, exhaustive pattern matching which is missing in e.g. Elixir, and that leads to a lot of code being written exclusively for the happy path.

Where Next?

Popular General Dev topics Top

dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
chasekaylee
Hi there! I have some old Bose in ear noise cancelling headphones that have worked like a champ for the past 3 years and was maybe due fo...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
DevotionGeo
The Odin programming language is designed with the intent of creating an alternative to C with the following goals: simplicity high per...
New
jamiedumont
This is all going to be a bit hand-wavey and straight off the top of my head, so bear with me, but it’s a thought/debate that’s been ratt...
New
jaeyson
Not trying to add more mess here but, reddit has ELI5 but i wanted to know if it’s okay to ask Elixir-specific (or outside of it) in a si...
New
Exadra37
My brother got a VPS on https://contabo.com hosting provider, but I was not aware of them, and when my brother told me the price and spec...
New
Exadra37
Your users of the two forums are spread across the world, thus I am curious how did you solved it?
New
DevotionGeo
Hi everyone! I bought this domain name when I was planning to create a website like ElixirSchool.com, but that didn’t ever happen. Now ...
New
Margaret
Hello DevTalk Community! Once again, The Pragmatic Programmers are looking for developers who’d like to help shape the future of our boo...
New

Other popular topics Top

PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New