Hacker News new | ask | show | jobs
by TazeTSchnitzel 3800 days ago
Having type annotations that are ignored at runtime would cause problems when you interact with code without type annotations, no?

PHP has a (unfortunately quite limited) set of type annotations, but the interpreter actually enforces them.

2 comments

Having type annotations that are ignored at runtime would cause problems when you interact with code without type annotations, no?

I seem to be doing this a lot in this thread, but...

This is your obligatory reminder that several statically-typed languages actually run on dynamic-language runtimes, because programmers don't like to think about the cost of polymorphism/generics, but implementers have to think about that.

How could adding ignored type annotations cause problems? Any problems that arise would have to be there without the type annotations...?
Without the type annotations, you're expected to handle dynamic type checks yourself. With type annotations, you might think that tooling does it for you, so you might omit the dynamic checks. But the tooling doesn't necessarily check all your callers, and you end up with unexpected input.

This is partly what the Typed Racket writers mean when they say that most gradual typing systems like this one are not sound.

http://www.cs.cornell.edu/~fabianm/tpls/papers/20151110.shtm...

http://www.ccs.neu.edu/racket/pubs/popl16-tfgnvf.pdf

It can make debugging harder because "impossible" things happen - when a variable is annotated as a string you may not think to consider the possibility that it's actually an integer. But yes, optional typing is mostly just useless rather than actively harmful.