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

AstonJ
Which screen resolutions do you frequently use? Note: not the resolution the display is capable of mind, but the resolution you’re using...
New
wolf4earth
Inspired by this thread about arcade games - which I initially misread as favorite arcade game soundtracks - I wanted to ask about your f...
New
chasekaylee
Just like the title says :smiley: which courses you find that have had the most impact in the span of your career as a developer?
New
AstonJ
Always interested in seeing what apps people use and how they organise their phones/home screens! Here’s mine…
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
I hate having mandatory semicolons in a language, no matter how beautiful the language is otherwise. What about you?
New
AstonJ
Maybe a specific language or framework? Or a book or tool perhaps? What’s made your life easier and what do you think could make the live...
New
chaptuck
I am thinking about getting a fitness tracker of some kind (probably one from Garmin). Have any of you developed your own widgets, watchf...
New
AstonJ
00:00 The Year 2022 00:38 Web3 03:28 Metaverse 05:05 AI 06:22 Databases 07:31 JavaScript 09:58 Other Trends to Know WDYT - what wi...
New
jaeyson
Hi!, hope everyone’s ok. Sorry if this question is ambiguous (i’ll remove this if i break some rules here). This is more like a self-ques...
New

Other popular topics Top

DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1143 25816 759
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
New
PragmaticBookshelf
Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New