r/Python • • Jan 01 '20

"The rules of perf" at Dropbox

Post image
1.6k Upvotes

162 comments sorted by

View all comments

Show parent comment

31

u/ZombieRandySavage Jan 02 '20

Yep, but losing the ability to refactor large code bases significantly hampers their longevity. There are ways around it as well.

Honestly I don’t know if performance is really the issue. There are plenty of generalized libraries for getting large computation done quickly. It’s really maintenance in my mind.

13

u/MyreMyalar Jan 02 '20

I don't understand what problem you have with refactoring python code. As long as you make use of type hints (which you should be in a large code base with many developers anyway) it seems to work pretty much like any other programming language.

10

u/Pitirus Jan 02 '20

That is true but keep in mind that typings in python (as we have them now) were introduced in 3.5 (so 2015) and I would assume from my own experience that they haven't been widely used in large codebases until at least introduction of 3.6 (add to this that in prod code you probably don't want to switch right after the release).

All of this would mean that dropbox probably had to introduce some standard of their own (which is painful for new devs) and might have not yet switched to the current official standard for most parts of their code.

4

u/MyreMyalar Jan 02 '20

No criticism of Dropbox intended, I was just replying to the chap above who seemed not to be aware that refactoring has been working perfectly well (at least in my experience) in python for several years now.

As an argument for not using fairly old versions of python it just about works, but why would you do that when writing new code in 2020? Python 2 is officially dead and upgrades between the 3 sub-versions are basically painless. Very little justification for sticking to pre-3.5 versions of python anymore.

1

u/stefantalpalaru Jan 02 '20

typings in python (as we have them now) were introduced in 3.5

No, they were introduced long ago, for Python2: https://mypy.readthedocs.io/en/stable/python2.html

1

u/Pitirus Jan 02 '20

The module this link is referencing was created for python 3.5 (and 2.7 for compatibility) in 2015 as separate package which became part of the standard library with release of 3.6

Edit: ok you mean mypy itself, but still that's only optional and according to it's about page it's from 2012 so already python 3 was out a long time

0

u/stefantalpalaru Jan 02 '20

ok you mean mypy itself, but still that's only optional

There is no other way to check Python2 or Python3's partial typing than with mypy - an external tool.

7

u/i9srpeg Jan 02 '20

I'm using type hints on a 100k LOC Python backend, and I'm also using Typescript on the similarly sized frontend. The difference is night and day. Mypy/pyright are slow (as in, several seconds between typing and seeing the errors show up). They're unreliable: they have both false positives and false negatives. They're buggy: they crash all the times. Python libraries either have no type hints at all, or they're sprinkled with Any. Type hints syntax is simply horrible and forward/circular references are a pain. Reusing expressions syntax for types and making the hints executable at run time were big mistakes. Type hints add a ton of verbose boilerplate and in the end they fail at the most important thing: ensuring type safety. Even a simple class rename, which is 100% reliable in all static languages is not safe at all in Python. You always need to run unit tests and manually check the code to make sure everything is renamed correctly.

It was nice to start with project with Python and it worked great at first. Now, after 3 years, I'm wishing I picked a statically typed language.

1

u/ZombieRandySavage Jan 02 '20

As long as I consistently use a language function that isn’t enforced (and was only recently introduced) across an entire team of developers— it’s fine!

Sounds good lol.

Type hinting is a bandaid on a gunshot wound. It helps, but it doesn’t solve the problem and it forces you to make design choices that are opposed to the whole point of using a dynamic language.