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.

Popular General Dev topics Top

AstonJ
If you had the ear of a language creator, what would you say - what could they do to make a language that you would use? :upside_down_face:
New
AstonJ
If so, what was the last blog post you wrote… and if not, why not?
New
finner
When you are under pressure to deliver you ideally want your Pull Request to be reviewed, approved and merged as quick as possible. So do...
New
New
jss
What do people think about Data-Oriented Programming, like this book tackles? https://www.manning.com/books/data-oriented-programming Ho...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
OvermindDL1
What shell(s) do you use, why do you use them, and how do you have them configured? Note, this is about shell’s, not terminals, terminal...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1132 25321 748
New
AstonJ
I’ve been watching Prag Dave’s Elixir course and I noticed he uses tree: Tree is a recursive directory listing program that produces a ...
New
DevotionGeo
I am planning to refresh my Ruby knowledge in a month or two, after using other technologies more frequently for a few years. Luckily I w...
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
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
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
New
AstonJ
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: The Ser...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New