Live data from Hacker News

Open-sourcing MonkeyType – Let your Python code type-hint itself

engineering.instagram.com

151–160 of 237 posts

Re: Open-sourcing MonkeyType – Let your Python code type-hint itself

#151
post #112

Earlier quoted context omitted.

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.

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…

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 itself

#152
post #127

Earlier quoted context omitted.

> 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-h…

>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…

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 itself

#153
post #150

Earlier quoted context omitted.

>(i.e. matrices of compatible dimensions) What language do you use where you can get these kinds of guarantees? As far as I know very few languages provide those kinds of dependent types statically.

In graphics programming, you have specific types for lots of small vectors and matrices (for vectors, there are separate types for every sizes 4 and below, and matrices usually comes in a variety of sizes as well, at the very least 3x3, 3x4 and 4x4). Typechecking is very useful here: if you try to transform a point in space represented by a Vector3 by a general 4x4 matrix, it fails compilation because you have to con…

I'm aware of that, I was more thinking in the general case, as comes up in machine learning for example, where you have sizes like 128, 192, and odd shapes like 12x3x100x100 4-tensors, etc.

That is, generalized matrix types, not simply rotation matrix types or whatnot for special cases.

Re: Open-sourcing MonkeyType – Let your Python code type-hint itself

#154

Earlier quoted context omitted.

>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…

No it's absolutely not. In Haskell and F# you don't need to write types annotations to get that guarantee.

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 itself

#155

Earlier quoted context omitted.

No it's absolutely not. In Haskell and F# you don't need to write types annotations to get that guarantee.

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.

"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 itself

#156
post #121

Earlier quoted context omitted.

The first language I learned (after Applesoft BASIC) was C. I wrote C for a long time. About 6 years ago I picked up Python. Today I find it much easier and much more pleasant to spin up a new idea in Python, to the point that it is my default choice for new projects with fuzzily defined goals. None of my ideas have become companies, but I could totally see just sticking with Python even past the point that it became…

Between c and Python there is an ocean of languages...

True enough. I've dabbled in several. These are just the two I happen to have the most experience in and the ones that seemed relevant to my point.

Re: Open-sourcing MonkeyType – Let your Python code type-hint itself

#157

Earlier quoted context omitted.

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.

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…

Does this mean I have to return all the money I made?

Re: Open-sourcing MonkeyType – Let your Python code type-hint itself

#158
post #103

Earlier quoted context omitted.

Most of the c++ and c# code I see lately has so many things declared as auto, it's hard for me to figure things out too.

Are you using notepad to write c#? If you hover on the var you will see the tooltip with the type.

When I was writing c#, I did use visual studio, but since I'm used to developing in a terminal editor, all these tooltips and things are a little tricky -- sometimes they disappear, and then I can't get them back, etc.

But more often, when I'm looking at c# or c++, it's not code I wrote, it's not code I intend to change, it's code that's interacting with my code (written in another language) that I'm trying to see why it's misbehaving, so I can get the owner to fix it. I could be reading the code on GitHub or some other web view, I might have checked it out, but I have no interest in setting up a (probably new) IDE to look at it as the author would; I dig into too many projects to learn that many tools -- and deal with the upgrade cycle for them.

Sure, it would be useful to hover and get more information, but I'm used to loosely typed languages, so it's not awful. It's just jarring to see that the type information is apparently not important enough to write down the name in c++ or c# anymore.

Re: Open-sourcing MonkeyType – Let your Python code type-hint itself

#159

I come from a statically typed background (C++), but have been doing a lot of analytics in python in the past two years. It is frustrating not to have compile time guarantees when dealing with mathematical programs, because some things have to be a particular type (i.e. matrices of compatible dimensions). The result is a copious use of asserts, but it feels bad when you know that if you did this in a functional langu…

>(i.e. matrices of compatible dimensions) What language do you use where you can get these kinds of guarantees? As far as I know very few languages provide those kinds of dependent types statically.

Eigen (a popular matrix library) does it in c++.

Re: Open-sourcing MonkeyType – Let your Python code type-hint itself

#160

I come from a statically typed background (C++), but have been doing a lot of analytics in python in the past two years. It is frustrating not to have compile time guarantees when dealing with mathematical programs, because some things have to be a particular type (i.e. matrices of compatible dimensions). The result is a copious use of asserts, but it feels bad when you know that if you did this in a functional langu…

>(i.e. matrices of compatible dimensions) What language do you use where you can get these kinds of guarantees? As far as I know very few languages provide those kinds of dependent types statically.

C++ makes this possible via templates. Generally the size is moved to a template argument, which allows the compiler to check this at compile time (of course, this restricts you to statically sized matrices).
Post reply on HN