News for hackers. Stuff that matters.
Re:Incrementally migrating over one million lines of code fr... by lincolnq on Wednesday February 06, 2019 @02:06PM (#19098534)
It's worth noting that Guido van Rossum, creator of Python, is working at Dropbox on this project, and that Mypy is funded primarily by Dropbox (I think).

I'm glad that they are doing it, because it's contributed hugely to the Python ecosystem -- especially making it easier for other companies to make the switch to Python 3.

I highly recommend mypy for new and current python3 users. It's one of the biggest and best reasons to be using python3 (not that you should need any more :) )

Re:Incrementally migrating over one million lines of code fr... by xvector on Wednesday February 06, 2019 @03:15PM (#19099368)
I've never used mypy and I used Python a lot until I recently got my first job.

It kind of looks like a band-aid. Could you elaborate on why I would use, say, mypy as opposed to Golang if I don't need the benefits of a scripting language?

edit: I can understand why mypy would be useful to refactor an existing (large) project to bring forth type safety guarantees as you go forwards, but surely for new projects there are other languages of choice if type safety is what you want?

Re:Incrementally migrating over one million lines of code fr... by setr on Wednesday February 06, 2019 @04:28PM (#19100173)
I believe the general idea with gradual typing is that

1) It's faster to write the initial proof of concept with a dynamic language

2) It's common that the proof of concept becomes sufficiently big/stable that it turns into the final codebase

3) Gradual typing makes the path from PoC to real codebase smoother, instead of re-implementing in another language.

Point 1 is contentious of course, but that argument isn't relevant here. It is believed, and that belief becomes practice.

An example of point 2 might be OSH of the oil shell, which doesn't use mypy I believe, but was originally written in python with the intent to rewrite in C++, and eventually decided it was too costly to rewrite (somehow he decided that ripping apart the python VM would be the more fruitful path... and apparently he's making good progress there).

So basically, the usecase of mypy is when you're making the decision of continuing with python, or rewriting. Sometimes rewriting was part of the strategy from the start, other times a script just grew into a full-fledged program over time, but mypy's primary goal wouldn't be to introduce from the start.

Another usecase I've personally done is having the typing available to me from the start, but not actually making use of it until I reached a particularly nasty section of code. And so that particular chunk becomes (reasonably) statically typed, while the rest of the program remains standard python.

Although in that case I used a library that enforced typechecking at runtime rather than mypy (the library was typeguard iirc), which I only enabled on test runs (it slowed down the program significantly).

Re:Incrementally migrating over one million lines of code fr... by xiaodai on Wednesday February 06, 2019 @04:40PM (#19100307)
If you want gradual typing for a smoother ride and performance then just choose Julia. Seriously.
Re:Incrementally migrating over one million lines of code fr... by happy_man on Wednesday February 06, 2019 @06:55PM (#19101491)
Let's wait a couple of years until Julia stabilizes itself before suggesting is ready for production
Re:Incrementally migrating over one million lines of code fr... by setr on Wednesday February 06, 2019 @10:25PM (#19102742)
Stabilization and proliferation of libraries; afaik its ecosystem is currently only really fulfilled for numpy/scipy/ml workloads
Re:Incrementally migrating over one million lines of code fr... by happy_man on Thursday February 07, 2019 @01:09AM (#19103386)
Seems Julia developers and evangelists main objective is to "kill Python", am I wrong?
Re:Incrementally migrating over one million lines of code fr... by setr on Thursday February 07, 2019 @02:41AM (#19103696)
They can have whatever goals they wish, but regardless, having an ecosystem like .net or python requires a critical mass of users; and once you have that, the language goals don’t even matter; they’ll just have libraries for everything, whether they like it or not.
Re:Incrementally migrating over one million lines of code fr... by xiaodai on Wednesday February 06, 2019 @07:31PM (#19101780)
Sound advice. But i am sure it's fine to gp head first
Re:Incrementally migrating over one million lines of code fr... by joshuamorton on Wednesday February 06, 2019 @04:15PM (#19100042)
If python offers type safety, and language x offers type safety, what reason do I have to pick language x over python?
Re:Incrementally migrating over one million lines of code fr... by rantanplan on Wednesday February 06, 2019 @04:22PM (#19100122)
5x(probably more) reduction on server costs because of less memory/cpu requirements, if you choose Go for example.
Re:Incrementally migrating over one million lines of code fr... by joshuamorton on Wednesday February 06, 2019 @04:28PM (#19100172)
Ah, so your reasons to pick a different language are based not on type safety, but on performance.

Indeed there may be a plethora of valid reasons to pick another language over python for some project. But that wasn't the question.

Re:Incrementally migrating over one million lines of code fr... by rantanplan on Wednesday February 06, 2019 @04:33PM (#19100234)
Type safety of Go is leaps and bounds better than python's will ever be, with mypy or not.
Re:Incrementally migrating over one million lines of code fr... by joshuamorton on Wednesday February 06, 2019 @04:36PM (#19100273)
That's just factually untrue.

Mypy supports generics, protocols, (via extensions) dependent types, and user-defined covariance rules. Its leaps and bounds more powerful than go's type system.

Pytype adds type inference to that list. You end up with a type system that's closer in power to Scala's or Haskell's than Java or Go's.

Re:Incrementally migrating over one million lines of code fr... by rantanplan on Wednesday February 06, 2019 @04:50PM (#19100411)
Mypy's various bugs are just indicative of how much of a band-aid it is.

If you truly believe that a dynamic language like python can have type safety, then imagine what a language like Go can achieve.

Python already has deviated too much from where it started and mypy offers too little to justify the verbosity.

So I guess we'll see what the future holds for them.

Re:Incrementally migrating over one million lines of code fr... by joshuamorton on Thursday February 07, 2019 @12:06PM (#19106532)
>If you truly believe that a dynamic language like python can have type safety, then imagine what a language like Go can achieve.

Literally exactly the same thing, but no more.

Mypy and Go's compiler have the exact same information available at compile time. Python stops being a dynamically typed language when you add Mypy. It becomes statically typed. Calling it "dynamic" is like calling C++ "dynamic" because C++ doesn't have access to run-time type information (usually).

Actually that's not true, due to the increased expressiveness of Mypy's type system, it has more information available. Mypy has more information. It can do stronger analysis. Go has less information, it can't do as much. Go can make language (syntax) changes to improve this. Python has been very smart, and the type system is implemented as normal objects using the normal syntax. Adding new types, even "special" ones (like Union or Interface) doesn't require modifying the language itself, but can be done only with modifications to a fairly nimble standard library module.

This allows python's type system to evolve much more quickly than Go's has shown itself capable of.

>Python already has deviated too much from where it started and mypy offers too little to justify the verbosity.

But python's type system offers more than Go's, and isn't particularly more verbose, so what are you saying here about Go's type system?

Re:Incrementally migrating over one million lines of code fr... by rantanplan on Thursday February 07, 2019 @06:48PM (#19109869)
> Go can make language (syntax) changes to improve this. Python has been very smart, and the type system is implemented as normal objects using the normal syntax

I will leave this tidbit here:

i, found = 0, False # type: int, bool

In any case, I find these new "typing" features very awkward, overly verbose and not the reason that I chose python in the first place. If I am to write all this non-pythonic stuff to be 10x+ slower, less memory efficient, awful at concurrency and still not having solved the packaging/deployment situation... I will just use Go. Or any other language in that league, that offers so many more nowadays.

Re:Incrementally migrating over one million lines of code fr... by joshuamorton on Thursday February 07, 2019 @06:58PM (#19109928)
> i, found = 0, False # type: int, bool

That's actually

    i, found: Tuple[int, bool] = 0, False
in python3. Which as I said, uses normal objects and normal syntax.

As for the rest of your comment, I think that's been well discussed. There are a variety of non-typing reasons to use go over python. But if you are about type safety you're probably better off with modern python than modern go.

Re:Incrementally migrating over one million lines of code fr... by rantanplan on Thursday February 07, 2019 @07:28PM (#19110117)
> normal syntax.

Right. Ok we have a problem with definitions. No this is obviously not normal syntax.

Unless we take it to mean "whatever new syntax python introduces is normal syntax, since it supports it!", which is tautological and not very useful.

I'm gonna say something, strictly so you can understand where I'm coming from, not to offend you.

You sound very young. And by "young", I mean so young to not remember that Python was always about "duck typing" and not about strict types. I still have books on my bookshelf that tried to dissuade you from using "issinstance(foo, sometype)". So no, it's not python or normal syntax.

Yes, Python now is safer than older Python. But I had 99 problems with Python and that wasn't one of them :(

You, speaking as if Python is progressing so fast while Go is standing still, feels disingenuous. Go fixed their dep/packaging woes in a few years, Python is not even close. Go is adding generics. Go becomes faster in almost every release.

Changing Python into something that doesn't resemble python, its values, or the reasons that people chose it in the first place doesn't make sense, nor does it make it "Python".

I don't want Python to become Haskell, Rust or Go. No one ever chose python for its typing system! Rather its lack of it.

Anyway, there's no accounting for taste and to each their own.

Cheers

Re:Incrementally migrating over one million lines of code fr... by viraptor on Thursday February 07, 2019 @06:23AM (#19104507)
> Mypy's various bugs are just indicative of how much of a band-aid it is.

I think you're confusing an idea with an implementation. Bugs can be fixed. If mypy is useful, it will remain useful and slightly more stable.

Re:Incrementally migrating over one million lines of code fr... by tropo on Thursday February 07, 2019 @12:28PM (#19106696)
Go has to be better than that. Java beats Python by a factor of 10, and C beats Java by a factor of 10. C is beating Python by a factor of 100. I would expect Go to be a bit faster than Java.
Re:Incrementally migrating over one million lines of code fr... by rantanplan on Wednesday February 06, 2019 @04:18PM (#19100079)
Because python can't do anything else at this point.

It can't be faster. It can't consume less memory. It can't stay still.

So they add auxiliary features. No matter how much they downvote you, you're right.

For a new project it doesn't make sense to not use Go, or something similar, if you're going down that road.

Re:Incrementally migrating over one million lines of code fr... by DrJosiah on Wednesday February 06, 2019 @11:46PM (#19103065)
You're wrong on every point. Congratulations!

Cpython (every edition gets optimizations)/PyPy/Numba/Cython/... -> faster. Dict optimizations -> less memory.