6 ms·
Why would you keep Python if you want static typing? I mean, there are several modern, performant (more than Python actually) statically typed languages. Rust,
by ggregoire 7y ago
Why would you keep Python if you want static typing? I mean, there are several modern, performant (more than Python actually) statically typed languages. Rust, Go, Kotlin, Scala, Swift… All of them are mature and have a good library ecosystem. So, except if you need some math/AI/ML packages available only for Python, why bother? Choose the right tool for the job, no?
- dragonwriter 7y ago> Seems like all of this (adding static typing on top of Python, PHP, etc) started with the success of TypeScript Mypy is a few years older than TypeScript, so, no.
- ggregoire 7y agoYep, already removed that part since I was not sure about the historic and it actually doesn't matter who started the trend.
- rat9988 7y ago> Choose the right tool for the job, no? The thing is, static typing is never the job by itself.
- ggregoire 7y ago"job" doesn't refer to static typing but the project you are working on. - script of 2,000 LOC to clean data => dynamic typing is fine => Python - web service of 1,000,000 LOC => static typing seems a better choice => Rust, Go, Kotlin, Scala, Swift, C#, Java…
- cwyers 7y agoA lot of people don't set out to write a million LOC web service, they build a smaller web service and it grows.
- JeremyBanks 7y agoQuite. My company is using Go for most new projects, but we have five years of Python code that we can't justify rewriting any time soon. We've been able to add annotations incrementally instead.
- aflag 7y agoSometimes the right tool for the job is python + mypy.
- darkr 7y agoIn general, for a new project of any size, or significance, or where performance/concurrency was a concern; hands down, yes, I would absolutely reach for a strong, statically typed, compiled language. The fact remains though that Python is an excellent general purpose language, easy to learn, almost universally known, has libraries for everything (and that’s just the stdlib). It is well suited to rapid prototyping, scripting, and data wrangling. Adding incremental typing makes it even better.
- pacala 7y agoScala: Python + dataclasses [+ mypy] offers a programming experience close to pragmatic Scala. The tradeoff becomes: * worse performance * lack of immutable vectors, alleviated via style conventions * rarely, awkward lambdas vs. * wide pool of people familiar with the language * lack of JVM lockin: Scala native is not there yet, the library ecosystem is all JVM. * [good] batteries included * much better reflection * access to modern ML * gradual typing * no actors Rust: Manual memory management is verbose and distracting. Go: Manual exception handling is verbose and distracting. Kotlin: JVM lock-in. Swift: Apple lock-in.
- hermitdev 7y agoNo immutable vectors in Python? Are you not aware of tuples? Lambdas in Python are quite limited, but offset by natural nested local functions. Regarding performance, that's not always an issue, and depending on the use case can be addressed with async/await or using a multiprocessing pool. I have had issues with multiprocessing and some DB libs ib the past, but recently have had pretty good success. Multithreading is still an issue because of the GIL (global interpreter lock) and really only useful if you're calling into a C/C++ lib that releases the lock while it does it's native things. I've written a lot of Python in the last 15 years, and Ive written a ton of scripts that are faster than a well written identical C/C++/C# app, and was written in 1/10th of the time. It just depends on the use case.
- pacala 7y agoSorry, I meant persistent vectors. Data structures with type Vector[T] instead of Tuple[T0, T1, ...], amortized O(1) updates and list-like syntax for literals, e.g. i[x0, x1]. It's a minor annoyance, in most cases using vanilla Python lists with the convention 'any list that is part of a dataclass / is passed across function boundaries should never be mutated' is good enough. As u/joshuamorton noticed in this thread, the convention can be enforced with mypy and Sequence[T], which is great!
- joshuamorton 7y ago> * lack of immutable vectors, alleviated via style conventions Note that mypy/typed python fixes this: if you annotate a function as returning (or accepting) a Sequence/Collection/Iterable instead of a List, and attempt to mutate it, you'll get type errors. This is good practice anyway.
- cwyers 7y agoSometimes the job is "maintaining existing code," and nobody is going to pay for a ground up rewrite.
- Sean1708 7y agoGetting a whole team to try out static typing on a language that they already know is far easier than getting a whole team to learn an entirely new language.