News for hackers. Stuff that matters.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by ageofwant on Thursday December 21, 2017 @08:09PM (#15984469)
I think the general consensus is that that is not true. Python's dynamic nature is a clear advantage it has over statically typed languages. Add the fact that you can elect to tune down the dynamism when it makes sense to with very little impact on your existing stack makes Python the technological superior choice for the majority of applications.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by tigershark on Friday December 22, 2017 @12:44AM (#15985499)
Absolutely not. Python is not the technological superior choice for the majority of the applications. If you think so then your experience in different domains and application types must be very limited.

The preconcept that dynamic languages are more productive is just an illusion because you can easily take shortcuts that will hamper your progress in the future. A proper typed language with HM type inference has the ability to mostly avoid writing the types with the guarantee that the compiler will catch most of the pitfalls. And if you don't do any logic error pretty much every time your code just works. Saying that in a million line application Python is a better choice than F# or Haskell it's frankly ridiculous in my opinion.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Friday December 22, 2017 @12:56AM (#15985541)
Empirically, there are a lot more million line python codebases than F# or haskell codebases, in fact I can name multiple million line python codebases, and 0 F# or haskell codebases. Given that, logic would indicate some sort of failure on the part of haskell and F#, or they would see wider adoption among the large codebases where they are so useful.

Do you disagree?

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by tigershark on Friday December 22, 2017 @07:25AM (#15986951)
Given how much smaller is the F# community and how much more you can crank in less lines of codes in F# I can believe it. Between C# and F# there is about an order of magnitude of difference in the LOCs for big projects and C# and Python are comparable from this metric.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Friday December 22, 2017 @03:30PM (#15990654)
It appears you missed my point. I can't think of a 100kloc f# or Haskell codebase, so even if they were 10x as terse as python, which they aren't, python comes out ahead. If they're so much better, why don't people use them?
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by kod on Saturday December 23, 2017 @12:18PM (#15995084)
I can think of 100kloc Scala codebases, e.g. Kafka.

People do use ML family languages, and they are better. There are plenty of non-technical reasons they aren't as widespread as dynamic languages or shitty static languages.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Saturday December 23, 2017 @01:32PM (#15995493)
Right, but Scala is different from Haskell or f#. It doesn't use the same kind of type inference (hm) as classical ml derivatives.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by greglindahl on Friday December 22, 2017 @02:14AM (#15985784)
Does this mean I have to return all the money I made?
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by sidlls on Thursday December 21, 2017 @10:03PM (#15984940)
There's nothing here that tunes down the dynamism. Hints aren't statically checked or enforced. It's still possible to pass in an empty list to an int-hinted var and, e.g. have `if not var` evaluate to True (rather than raise an Exception).

Type hints allow external tools to check some things, but at this point you're basically imposing static types so why not use a language with the tooling and optimizations to take advantage of that?

Python is a good choice to prototype, write small (less than a few thousand lines of code) projects with non-trivial complexity, and somewhat larger projects with more boilerplate (e.g. Django webapps). Beyond that its utility diminishes until it starts to become a hindrance.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by ubernostrum on Friday December 22, 2017 @01:10AM (#15985594)
Ah yes, this old chestnut: "(language I don't like) is only suitable for teeny-tiny puny baby child's toy programs, and once you're not writing those anymore you must use a big strong grown-up language like all the other Real Programmers™ do!"

The empirical evidence of reality is against you: there are successful large (in terms both of codebase and contributors/development team) projects in these awful terrible children's languages, and there are unmaintainable failed piles of crap in even the most grown-up of languages you'd care to name. The choice of language, and choice of type system, seem not to correlate with the success or failure in a meaningful way.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by blub on Friday December 22, 2017 @04:31AM (#15986286)
It doesn't correlate with success, but the choice of language does correlate with development speed, number of faults, maintainability, etc.

The interesting thing to note is that a language that's perfectly acceptable at the above at small or medium scale might turn into a hindrance at large-scale. An otherwise fast to develop in language like Python won't be so fast if every change has to be painstakingly reviewed and tested due to the complexity of interactions in the code base.

Using a type system to verify assumptions/requirements is not a recipe for success, but it can improve reliability.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by ubernostrum on Friday December 22, 2017 @12:57PM (#15989438)
won't be so fast if every change has to be painstakingly reviewed and tested due to the complexity of interactions in the code base

You can write spaghetti code in any language, it turns out. Blaming the language for that is not really an indicator of understanding the problem.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by blub on Tuesday January 02, 2018 @04:03AM (#16050789)
Yes one can do a poor job in pretty much any situation, I'm afraid that's not an argument for anything though.

Here we're talking about average or best-effort: large code bases are complex in spite of the best intentions of their maintainers, so using tools that can manage that conplexity in an easier way through e.g their type systems could lead to better results.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Thursday December 21, 2017 @10:31PM (#15985066)
>Type hints allow external tools to check some things, but at this point you're basically imposing static types so why not use a language with the tooling and optimizations to take advantage of that?

Python's type system is, imo, currently better than Java's, and the syntax is cleaner than java's or C++s. You get all the benefits of static typing without having to put `auto` and `List<>` everywhere. And at the same time, you get all of the advantages that python has over statically typed languages that aren't haskell (like comprehensions). And, when you need to, if you're doing something that's especially tricky or dynamic or whatnot, you can fall back to untypedness.

I think the closest parallel I can draw is to something like Rust. You get a huge set of guarantees for free, but can opt to do unsafe things when it's absolutely necessary, and better yet, you can start in unsafe land and then go back later and make sure your code is safe.

I'm curious what tooling you feel that say, Java, has over type-annotated python.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by sidlls on Thursday December 21, 2017 @10:45PM (#15985129)
Hints don't provide any guarantees. It's still possible to silently and unknowingly pass the wrong type of value into any given argument, with or without the checker. The "tooling" the other languages have includes a compiler that performs these checks in a way that Hints + Checker-of-choice is unlikely (or unable) to. "What do you think these checkers do?" you might ask. The answer is: not nearly what a compiler does.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Thursday December 21, 2017 @11:29PM (#15985280)
> It's still possible to silently and unknowingly pass the wrong type of value into any given argument

This is also possible in traditionally statically typed languages. Nothing stops you from doing unsafe casts or using reflection. Much like its exceedingly unlikely that you'll run across this in "normal" java or C++, its exceedingly unlikely for you to run into any issues with this in python. And, in fact, the typechecker has ways to handle unusual things like dynamically created attributes, for when that comes up.

And yes I mean this quite honestly. I've seen a lot of typechecked code, some of it quite ridiculously dynamic. Typecheckers perform absolutely fine.

>The "tooling" the other languages have includes a compiler that performs these checks in a way that Hints + Checker-of-choice is unlikely (or unable) to.

What way is that? Typechecking is static analysis. There's really no difference between how java or cpp does typechecking and how mypy does, other than that the python typechecker isn't installed by default.

>The answer is: not nearly what a compiler does.

This is not an answer.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by sidlls on Thursday December 21, 2017 @11:50PM (#15985347)
> This is also possible in traditionally statically typed languages. Nothing stops you from doing unsafe casts or using reflection.

Neither of those is "silent" or "unknowing".

> What way is that? Typechecking is static analysis. There's really no difference between how java or cpp does typechecking and how mypy does, other than that the python typechecker isn't installed by default.

The typechecker can't handle un-hinted code (or, rather, it chooses something very permissive, like 'Any' for all hints). It's incomplete at best.

> This is not an answer. It is. That you don't like or agree with it doesn't make it not an answer.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Friday December 22, 2017 @12:22AM (#15985435)
>The typechecker can't handle un-hinted code

And in Java or c++, un-hinted code couldn't compile. The python type checker can do more than a java or c++ checker in this regard.

>Neither of those is "silent" or "unknowing".

They're exactly as silent or unknowing as you would get in typed python code. You appear to be comparing untyped python. That's an incorrect comparison. Offhand, I actually can't think of anything I could do in typed python that would get around the type checker, that wouldn't be considered reflection or a dynamic cast, and be very obviously so in python too. If you have an example of a silent or unknowing failure of well typed python code that passes on mypy, you should probably file a bug report ;)

>That you don't like or agree with it doesn't make it not an answer.

You're right. Its not an answer not because I disagree with it (I don't), but because it doesn't actually answer anything, which is why I don't disagree with it.

To summarize this:

Python typecheckers are capable of more type inference than Java, and require less syntax than c++ or Java to get well typed code. A typed python codebase can interact cleanly with an untyped python codebase, and within the typed parts of the code, you get equivalent safety guarantees to what the type systems of Java or C++ provide.

Your appear to be ascribing magical powers to compilers in other languages, when those compilers have exactly the same type information as mypy does.

In other words, going back to your first statement:

>Hints don't provide any guarantees.

Hints provide exactly the same guarantees as any other type system: "Assuming you write reasonable code that doesn't attempt to subvert the type system, the type system will catch any dumb mistakes you make."

That's the exact same guarantee you get in any statically typed language.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by tigershark on Friday December 22, 2017 @01:11AM (#15985600)
No it's absolutely not. In Haskell and F# you don't need to write types annotations to get that guarantee.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Friday December 22, 2017 @01:15AM (#15985615)
Nor do you in python in many cases, it's type inference is quite good, certainly better than c++ or java, which is what I was speaking of.

But you're right, I should have specified "traditional" static language.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by tigershark on Friday December 22, 2017 @01:20AM (#15985623)
"That's the exact same guarantee you get in any statically typed language." You wrote that and f# and Haskell are statically typed
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by tjoff on Friday December 22, 2017 @02:43AM (#15985878)
You don't put auto everywhere. You write out the type in 99% of cases and save auto for 100+ character templated types.

There is no reason to to save the literally 0.2s (you can still spend that time reasoning about your code) it takes to write the type. It is better for yourself writing it and for readability to be explicit.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Friday December 22, 2017 @02:55AM (#15985919)
By everywhere, I mean where it's otherwise obvious:

    auto s = "Hello world";
    for (auto c: s) {
        cout << c;
    }
Those autos don't need to exist, they're completely inferable, otherwise you wouldn't use auto. It's not like you can use auto in function declarations, nor should you, I agree.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by tjoff on Friday December 22, 2017 @04:14AM (#15986220)
I always write std::string etc. in those cases. It is consistent and quicker to read and there is not tangible benefit to using auto.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by joshuamorton on Friday December 22, 2017 @02:22PM (#15990135)
Right, but my point is that there's really no tangible benefit to writing the type at all. In a language with good type inference (Haskell, ml, modern python), the string literal is known to be a string, and you don't need to do any extra work.
Re:Open-sourcing MonkeyType – Let your Python code type-hint... by jsjohnst on Friday December 22, 2017 @12:36AM (#15985478)
> Beyond that its utility diminishes until it starts to become a hindrance.

Tell that to any serious Numpy/Scipy/Pandas user.

Re:Open-sourcing MonkeyType – Let your Python code type-hint... by sidlls on Monday December 25, 2017 @02:33PM (#16005386)
Being the lead on a data science team I am one of those. They're great for exploratory research and prototyping, and for use in the very tiny fraction of code in a production system that deals with machine learning if I must. For everything else, from the data pipeline to delivering results, I'd prefer and recommend something else, like Haskell, C++, go or Rust.