News for hackers. Stuff that matters.
Re:A Failed Experiment with Python Type Annotations by ggregoire on Tuesday June 11, 2019 @05:16PM (#20159618)
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?
Re:A Failed Experiment with Python Type Annotations by darkr on Tuesday June 11, 2019 @06:36PM (#20160132)
In 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.

Re:A Failed Experiment with Python Type Annotations by pacala on Tuesday June 11, 2019 @07:33PM (#20160474)
Scala: 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.

Re:A Failed Experiment with Python Type Annotations by hermitdev on Tuesday June 11, 2019 @09:42PM (#20161053)
No 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.

Re:A Failed Experiment with Python Type Annotations by pacala on Tuesday June 11, 2019 @11:34PM (#20161563)
Sorry, 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!
Re:A Failed Experiment with Python Type Annotations by joshuamorton on Tuesday June 11, 2019 @09:54PM (#20161097)
> * 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.

Re:A Failed Experiment with Python Type Annotations by pacala on Tuesday June 11, 2019 @11:42PM (#20161602)
Thanks for the tip!
Re:A Failed Experiment with Python Type Annotations by zapzupnz on Tuesday June 11, 2019 @11:04PM (#20161390)
> Swift: Apple lock-in.

Swift runs on Linux and has done since it was made open source in 2015, a year after its initial announcement. Windows support is being worked on but, for the time being, it runs fine in WSL. No lock in.

Re:A Failed Experiment with Python Type Annotations by pacala on Tuesday June 11, 2019 @11:41PM (#20161599)
How's the cross-platform library ecosystem? My distant sentiment is that the bulk of libraries are tied to / provided by Apple, but I'd be happy to be proven wrong.
Re:A Failed Experiment with Python Type Annotations by zapzupnz on Wednesday June 12, 2019 @05:30AM (#20163022)
Cross-platform stuff is mainly non-GUI since the main thrust of the cross-platform scene seems to be server-side Swift, and most of the GUI stuff is targeted to iOS (although with Project Catalyst, that's all implicitly valid macOS code now).

I expect we may see some third-party, cross-platform reimplementations of SwiftUI very soon once the appropriate language features are set in stone and ship with the next version of Swift.

Otherwise, it's fairly healthy — lots of computational libraries, database, web, etc. Plus, Swift pretty much has direct compatibility with C and Python libraries without needing to wrap anything.

Re:A Failed Experiment with Python Type Annotations by jtdev on Wednesday June 12, 2019 @07:34AM (#20163516)
> Plus, Swift pretty much has direct compatibility with C and Python libraries without needing to wrap anything.

Could you please elaborate on this point?

Re:A Failed Experiment with Python Type Annotations by zapzupnz on Wednesday June 12, 2019 @07:44AM (#20163564)
C compatibility is one of the original design goals for Swift and is used extensively for the Linux version, for making Swift wrappers around existing libraries, and the Objective-C bridge on macOS. If using Xcode, one would use a bridging header; otherwise, one can use Swift Package Manager to wrap C libraries for use in Swift projects.

Swift recently gained the features needed to call Python code. You can either use the Python module from Swift for Tensorflow or the PythonKit library, both of which allow calling Python code from within Swift.

The features used to allow calling Python from Swift can also be used for other dynamic languages, so there may be the ability to call Ruby and other languages' libraries in future as well.

Re:A Failed Experiment with Python Type Annotations by swebs on Wednesday June 12, 2019 @05:20AM (#20162987)
>Scala: JVM lock-in

>Kotlin: JVM lock-in

You know OpenJDK has been available for over a decade, right?

Re:A Failed Experiment with Python Type Annotations by dragonwriter on Tuesday June 11, 2019 @05:23PM (#20159662)
> 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.

Re:A Failed Experiment with Python Type Annotations by ggregoire on Tuesday June 11, 2019 @05:26PM (#20159685)
Yep, already removed that part since I was not sure about the historic and it actually doesn't matter who started the trend.
Re:A Failed Experiment with Python Type Annotations by rat9988 on Tuesday June 11, 2019 @05:34PM (#20159737)
> Choose the right tool for the job, no?

The thing is, static typing is never the job by itself.

Re:A Failed Experiment with Python Type Annotations by ggregoire on Tuesday June 11, 2019 @06:18PM (#20160011)
"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…

Re:A Failed Experiment with Python Type Annotations by cwyers on Tuesday June 11, 2019 @08:18PM (#20160709)
A lot of people don't set out to write a million LOC web service, they build a smaller web service and it grows.
Re:A Failed Experiment with Python Type Annotations by JeremyBanks on Tuesday June 11, 2019 @08:55PM (#20160857)
Quite. 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.
Re:A Failed Experiment with Python Type Annotations by Sean1708 on Wednesday June 12, 2019 @07:32AM (#20163499)
Getting 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.
Re:A Failed Experiment with Python Type Annotations by aflag on Tuesday June 11, 2019 @06:22PM (#20160044)
Sometimes the right tool for the job is python + mypy.
Re:A Failed Experiment with Python Type Annotations by cwyers on Tuesday June 11, 2019 @07:50PM (#20160562)
Sometimes the job is "maintaining existing code," and nobody is going to pay for a ground up rewrite.