Live data from Hacker News

Revenge of the Types

lucumr.pocoo.org

1–10 of 137 posts

Re: Revenge of the Types

#3
Some people may not understand the context of this part:

    So not long ago someone apparently convinced 
    someone else at a conference that static typing
    is awesome and should be a language feature. I'm 
    not exactly sure how that discussion went but the
    end result was that mypy's type module in combination
    with Python 3's annotation syntax were declared to be
    the gold standard of typing in Python.
Ronacher is referring to the fact that Guido van Rossum, the Python language creator and BDFL, recently said he wanted to make mypy's type annotation standard into a standard by making use of Python 3 function annotations.

The original function annotations standard is PEP-3107[1], GvR's proposal is on the python-ideas list[2], and information on mypy can be found at the project's site[3].

I agree with Ronacher's conclusion; I don't think static types -- even if only used at runtime -- are a good fit for the language. As for function annotation syntax, I think we just need to admit that isn't really good for anything.

Great article!

[1]: http://legacy.python.org/dev/peps/pep-3107/

[2]: https://mail.python.org/pipermail/python-ideas/2014-August/0...

[3]: http://www.mypy-lang.org/

Re: Revenge of the Types

#5
The argument seems to be that if the added type system is not perfect, then it will be useless. For a working counterexample, see the Closure Compiler (https://github.com/google/closure-compiler), which adds a bolt-on, underspecified, occasionally-changing type system to Javascript. Similarly to GvR's proposal (https://mail.python.org/pipermail/python-ideas/2014-August/0...), the types are only ever checked at compile time: there's no attempt to use them as runtime assertions and very limited attempts to use them for compile-time improvements. So, yes, because they are imperfect and optional, you don't catch every type error, and you need to add type hints / casts that in a perfect system wouldn't be necessary.

Is this kind of flawed type system worth it? Hell yes. I've maintained large programs in both Python and (closure-compiled) Javascript, and with the former I've wished I had the help of the limited type checking available in the latter.

Re: Revenge of the Types

#7
Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this:

    float drop(float x0, float duration) {
      float x = x0;
      float t = 0;
      float v = 0;
      float g = -10;
      float dt = 0.01;
      while (t /1000);  // abbrev for a cast: (float).001
    }
Then I want the compiler to check that I'm not mixing up my units. It seems like this would be really useful, but I've never seen it before.

Re: Revenge of the Types

#8
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

From what I've read, Ada can do this.

Re: Revenge of the Types

#9
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

In theory you can do that in any language that allows you to override operators. It's definitely being done in Rust. For instance you sleep for `Duration::milliseconds(10)`.

Re: Revenge of the Types

#10
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

Check out F#'s units of measure. http://msdn.microsoft.com/en-us/library/dd233243.aspx
Post reply on HN