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

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
Thought it might be worth having a dedicated thread for standing desk treadmills (for those interested, here’s our general thread on stan...
New
DevotionGeo
As the title suggests, this thread will contain some real wisdom came from experience. Please add something meaningful than fancy looking...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
finner
One of my 2021 resolutions is to read more tech books. As part of this effort I purchased two MEAPs (Manning Early Access Program) which...
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
AstonJ
The dev world doesn’t sit still, in fact it is probably one of the fastest paced industries around - meaning to stay current we are conti...
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
Exadra37
A modern streaming platform for mission critical workloads Redpanda is a Kafka® compatible event streaming platform. No Zookeeper®, no JV...
New
AstonJ
Slightly different to the What does your mobile phone home screen look like? thread, what is your lock screen image?
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1021 17090 374
New
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
AstonJ
Or looking forward to? :nerd_face:
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
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
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