by xvilka · 5y ago · 0 comments
- Static + Weak = C
- Static + Strong = Haskell
- Dynamic + Strong = Python
- Dynamic + Weak = JS
and, in particular, explicit vs. implicit type casts of those objects.
Examples:
Python: strong, dynamic
PHP: weak, dynamic
C: weak, static
Haskell: strong, static
I expect that everybody doing this job has a CS or equivalent degree and knows the difference between strong / weak and static / dynamic typing. Reading other comments here demonstrates this is not the case. This is not a bad thing (luckily we only need a screen and a keyboard) but hopefully they'll have learned something new today.
Btw, there is a lot I don't know despite my degree. No hard feelings.
https://www.sciencedirect.com/science/article/pii/S147466701...
Practically, untyped languages would include asm and forth.
def comparativeInsult(a,b):
if b>a:
return "try again"
if a>b:
return a/b
else:
return None
The type is, for all practical purposes, a part of the value of a Python object.> "Dynamic typing" The belief that you can't explain to a computer why your code works, but you can keep track of it all in your head.
— Chris Martin (https://chris-martin.org/2015/dynamic-typing)
Here's my response to that quote:
"Static typing": The belief that if your code type-checks correctly, it will do exactly what you intended. (A variant of the belief that if your code compiles correctly, it will do exactly what you intended.)
Of course, taken literally, that's unfair, but so is the quote you gave. Everything you add to your code has a cost. Time you spend writing type specifications is time you're not spending doing something else that might add more value. Sometimes writing type specifications is the best use you can make of that time; sometimes it isn't. Python at least gives you both options: use type annotations if you want, but you don't have to if you don't want to.
No-one claims that typechecking solves 100% of problems. But it has a higher cost-benefit than anything else that's been tried.
> Time you spend writing type specifications is time you're not spending doing something else that might add more value.
So is time you spend thinking about the behaviour of the code in your head - the main difference is that it's slower and more error-prone.
Occasionally you really can do the calculation about what kinds of expressions are valid in which places better than the computer. But that's a rare case that gets rarer every day.
> Python at least gives you both options: use type annotations if you want, but you don't have to if you don't want to.
Not really: your code will almost always be silently unsound. E.g. libraries you're using will usually have incorrect type annotations (because their type annotations aren't checked, and the checker is unsound even if they were).
In contrast if you use say Haskell you genuinely do have both options: you can write code and have it be safely typed, or you can call unsafeCoerce at any point where you don't want typechecking to happen.
I would want to see a lot of data, for a lot of different kinds of programs, to back up this claim.
> So is time you spend thinking about the behaviour of the code in your head
You have to do this anyway; static typing doesn't write your code for you. Even Haskell, which I will freely admit is probably the closest thing to an AI that I've ever seen in a programming language, can't do that. :-)
> your code will almost always be silently unsound
Code that has type annotations has this same problem. That was the point of my response: static typing != sound code.
> libraries you're using will usually have incorrect type annotations
They can't be incorrect if they aren't there. The comparison I'm making is not between code with correct type annotations and code with incorrect ones. It's between code with type annotations and code without any of them at all.
I'm very enthusiastic about static types with global type inference, where I don't have to write a single type annotation if I don't want to. My enthusiasm degrades pretty quickly the more annotations I have to manually clutter my code.
I see way too many code bases that test things that are easy and xfail things that are hard because it turns out that you can’t just test your way to a complex product, but you sure can make yourself feel good by testing the fact that a dict acts like a dict.
I would certainly argue that anyone who writes a library, whose public API will be consumed by hundreds or thousands of people, should always include type annotations.
After working in a TypeScript codebase for so long, it's jarring to return to Python or even vanilla JavaScript where I no longer have breadcrumbs to help me keep track of how the code is organized.
Python's type annotations leave something to be desired, in terms of how easy they are to include in code and how well the tooling supports them. I'd almost rather see something like "Typethon" with better syntax+soundness that compiles-to-Python.
Types are an optional tool, sure, but they're one of the most valuable tools we have to catch (not eliminate entirely) bugs and hasten development (without introducing errors).
With a little care and a sufficiently strong type system it’s surprising how often this is actually true.
> Dynamically typed languages are actually statically typed with precisely one type: hash table.
Because by this definition makes C++ and Java look dynamic with vtables.