It seems that some people conflate static typing with long compilation cycles and dynamic typing with interpreted languages and interactive development.

Those aren't arguments for and against static or dynamic typing!

@clacke I think they are good arguments, if static typing takes 4 hours and boils the oceans to do the same work a dynamic program can do in seconds, then you should prefer dynamic.

The fastest static language I know is Julia, and it has a 4-60s startup time depending on what you load, even in the latest versions which are down from 120s startups by not loading as much; it's not any faster at the static compiling.

Julia's much faster than Python at runtime, but always loses from cold start.

@mdhughes If static typing boils the oceans it's a problem with the implementation, not with the concept of static typing. D can do it quickly. go can do it quickly. mypy is faster than flake8 on our codebase, but that might be because a lot of code is still unchecked.

Slow startup has nothing to do with static typing. Once things are compiled they can just load. They're statically checked, not runtime checked. C and C++ don't have slow startup. I haven't used .NET in over a decade, but I don't remember a slow startup there either.

@clacke Those are pre-compiling, and the static ones (C is not static!) take vastly longer to compile. Swift (very static) takes exponential time longer than Objective-C (very dynamic); a 100-class project in Obj-C can compile in 10s, while the same in Swift will take minutes to hours.

Do a clean build & run to compare languages, not just runtime speed.

@mdhughes In my vocabulary static typing means variables have types and the types are verified before the code runs. The code generally doesn't need to verify types when it runs.

Dynamic typing means only values have types, and nobody will stop you from trying to run a function on a value of a type it can't handle. Only when you run it do you find out that it didn't work.
Statically typed languages like C may have escape hatches and limitations that allow you to break the guarantees, but that doesn't mean they're not statically checked.

A C program where every argument to every function is (void *) and then examined and cast inside the functions, is that dynamically typed? Arguably, but it's not a typical program.

@clacke C compilers have warnings as an option: -Wall (or -Wfoo for specific warnings). If you don't have that, it behaves exactly like a dynamic language, you can pass anything to anything. And even with -Wall, you can cast anything to void and pass it wherever you want.

C's also weakly-typed, in that objects don't know anything about themselves, so you can't interrogate an int or string to see what it is.

@mdhughes The type declarations are there, and I don't think you'll find many people that will defend the terminology that C is a dynamically typed language.

It is weakly typed and the type system is full of escape hatches, but the type checking that is done is static.

Not by coincidence, C is also the language that turned many people off static typing because C, and by extension C++, made it seem pointless, just a performance hack and a way to encode the calling convention. It is only now that mainstream languages offer static type systems that actually help you rather than you helping the compiler.

@clacke And strong-typing people have been claiming it helps you since Ada, maybe earlier. It's never helped anyone, it just wastes build time between runs, flags some trivial errors you'd catch by testing, and discourages testing so the actual logic errors get through. "It compiled, that means it's correct!" says every strong-typing person, just before getting 2.0/0.0=NaN.

Follow

@mdhughes

- "wasting build time" is a shit argument sorry. most dynamic languages just waste that at runtime, exploding spectacularly if they hit an error because there isn't another way to handle things.

- no one in their right mind would say it's correct if it passes the type checker. static typing just removes type mismatch errors, not every error. with good static typing you can _prove_ that you won't get type errors though. if you then define good types, you can prevent many logic errors, not everything of course. 3/4 of programming is to get the data structures right.

- if the only thing you have is testing, everything looks like a testcase.

- i haven't used it extensively, but ocaml doesn't have shit compile times, there is a REPL and it is statically typed.

@clacke

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.