News for hackers. Stuff that matters.
Re:Python’s “type hints” are a bit of a disappointment to me by smohare on Friday April 22, 2022 @12:32AM (#31118241)
If you mean “Python programmers” to be random sysadmins that write hack code residing on a random EC2 instance then maybe you’re right. But most I get the sense you haven’t looked at many Python libs lately.

The added productivity of non-typed Python is such a ridiculous myth to anyone who has to maintain significant Python code bases. Sure, it makes you more productive for one-off exercises but the moment you’re having someone else inspect your code the productivity gains vanish. This largely true of dynamic languages more generally except in niche caches (e.g., ORMs) where types are strongly implicit.

I say all this as a mathematician that is used to reading papers full of symbols packed with implicit information. The code I’ve read from gung-ho dynamic typing advocates is some of the most painful drivel I’ve ever had to wade through.

Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Friday April 22, 2022 @12:41AM (#31118283)
Python libraries aren't representative of Python code. The majority of Python programmers (not "just sysadmins" wherever that slur comes from) never publish or contribute to any libraries.

I can compare Python's productivity to other languages, and it beats all of them so far. Another lesson I learned from working with statically typed languages: The quality of the code is more dependent on who writes it than on the language or even the ecosystem. But people are productive much sooner in Python than they are in C# or F#, and then we can work on the foot-gunning.

Python's productivity isn't a myth. This is proven by its popularity and by successful projects across academia and industry alike.

Re:Python’s “type hints” are a bit of a disappointment to me by grumpyprole on Friday April 22, 2022 @03:13AM (#31119103)
You might be more productive in Python versus anything else for the scale and complexity of the software you are involved in, but you cannot make sweeping generalisations like this. I also think you fail to understand that in many situations, static type systems actually improve productivity, especially at scale or for non-trivial domains. This is of course why Python is now trying to retrofit them.

There's also the argument that one is most productive in what they know. As someone who has spent far too long with Haskell and OCaml, Python's semantics and libraries often seem surprising and counterintuitive to me.

Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Friday April 22, 2022 @03:54AM (#31119290)
I "fail to understand" something you actually never did or experienced, right? I know that a lot of companies are maintaining large Python codebases, and the "lack of typechecking" might be one of the biggest pain points, but the total pain is a lot less. That was always my experience and most people who say differently haven't actually used Python that ...

I know that Typescript helped me over Javascript. I don't get that benefit from Mypy yet, but the "pain" just isn't as great as it was with JS. And I've seen what inexperienced programmers do when a static typecheckers try to force or encourage them to do the right thing. It's not necessarily the right thing, just a lot more complicated than it needs to be.

Re:Python’s “type hints” are a bit of a disappointment to me by grumpyprole on Friday April 22, 2022 @05:13AM (#31119620)
> I "fail to understand" something you actually never did or experienced, right?

No, I have worked at a variety of large institutions that have millions of lines of Python. I work with it often. The use of Python is more about it being accessible for non-developers, which is why they also teach it in schools; and the need for a standard. It is the new "Visual Basic". Again, it is not more productive in all situations.

Re:Python’s “type hints” are a bit of a disappointment to me by krageon on Friday April 22, 2022 @05:16AM (#31119640)
If you write more code that is untyped than typed, you are harming whoever comes after you. Untyped code is an absolute dragon even if it is properly documented (which it practically never is). Glorifying "productivity" and putting it above the greater good is essentially everything that's wrong with the world, at every level.
Re:Python’s “type hints” are a bit of a disappointment to me by CraigJPerry on Friday April 22, 2022 @06:01AM (#31119874)
That’s quite a strongly worded opinion. It sounds like it should be utterly trivial in this case to show that typed code causes less harm. I’m happy with whatever definition of harm you’re happy with. So where can i review the data supporting such a strongly worded position?
Re:Python’s “type hints” are a bit of a disappointment to me by oriolid on Friday April 22, 2022 @11:47AM (#31123113)
On a quick search, for example https://link.springer.com/article/10.1007/s10664-013-9289-1. "This paper describes an experiment that tests whether static type systems improve the maintainability of software systems, in terms of understanding undocumented code, fixing type errors, and fixing semantic errors. The results show rigorous empirical evidence that static types are indeed beneficial to these activities, except when fixing semantic errors." is pretty much as strongly worded as scientific journals can accept.
Re:Python’s “type hints” are a bit of a disappointment to me by CraigJPerry on Friday April 22, 2022 @04:36PM (#31127735)
Cool - this paper has 3 conclusions:

- Static type systems are an effective form of documentation

– Static type systems reduce the effort to fix type errors

– Static type systems may not be helpful in preventing semantic errors

It would have been awesome to have evidence for #3 but even just #1 & #2 could be useful, albeit to a much lesser extent. Could we quantify by how much?

It’d be important to quantify because if static types mean a developer can be done sooner, then they have spare time to spend improving the software. So do these differences with static types translate into benefits for the developer?

The author of that paper says no. He published this other paper just after that one: https://www.ics.uci.edu/~jajones/INF102-S18/readings/23_hane...

Re:Python’s “type hints” are a bit of a disappointment to me by oriolid on Saturday April 23, 2022 @01:46AM (#31131746)
For the second paper, looks like the test task is quite small and the language used requires more work from developer than a modern static type system with type inference and generics. Still the difference between static and dynamic typed variants is rather small. I wonder if the situation would change if the project took weeks or months instead of hours, but that would be an expensive experiment. Also, it would be interesting to see if type inference and generics would increase productivity but in the real world we are stuck with Java and Go anyway.

Other take home message is that the famous 10x programmer was found in both groups. The one with dynamic language was faster, just as the argument for dynamic typing goes.

Re:Python’s “type hints” are a bit of a disappointment to me by krageon on Friday April 22, 2022 @06:02AM (#31119879)
You can review it by talking to people that inherit your code, especially if they're still acclimating to it :)
Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Friday April 22, 2022 @09:01AM (#31121078)
So you don't have any hard data either...
Re:Python’s “type hints” are a bit of a disappointment to me by notpachet on Friday April 22, 2022 @08:52AM (#31121002)
programming languages : diehard dynamic typing advocates :: global pandemic : mask mandate protesters
Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Friday April 22, 2022 @09:12AM (#31121165)
There is no conclusive and objective evidence that static typing helps at all. Studies are at best inconclusive, certainly a far cry from confirming the superiority of static typing. Everything else is subjective. To have a recent and complete opinion about the one thing you necessarily need to have less of a recent and complete experience with another.

The benefits of masks against spreading respiratory viruses are easily and objectively proven. Completely different thing.

Re:Python’s “type hints” are a bit of a disappointment to me by notpachet on Friday April 22, 2022 @09:38AM (#31121390)
Well, while you're waiting for that study to ride down from heaven on a white horse clad in gold, the rest of us are going to just quietly get on with being (subjectively) more productive.
Re:Python’s “type hints” are a bit of a disappointment to me by _Algernon_ on Friday April 22, 2022 @04:59PM (#31128048)
Re:Python’s “type hints” are a bit of a disappointment to me by rwmj on Friday April 22, 2022 @04:49AM (#31119502)
The number of times I've stared at some random Python function deep inside a library wondering what does this function return? Even the docs often don't say.
Re:Python’s “type hints” are a bit of a disappointment to me by oriolid on Friday April 22, 2022 @08:07AM (#31120598)
It was very productive for the person who wrote the library.
Re:Python’s “type hints” are a bit of a disappointment to me by CraigJPerry on Friday April 22, 2022 @09:52AM (#31121520)
Would you be able to share an example of this?

I took a random stab in pandas but they’ve adopted type annotations so that defeats the point. So i thought old-school code bases - zope sprang to mind, but that’s not a good example either because they use docstrings and it’s kind of obvious. So i tried gunicorn on a whim and they have even more attention spent on their docstrings.

I just want to sample this feeling of lost confusion in python so that i can figure out how I’d deal with it.

Re:Python’s “type hints” are a bit of a disappointment to me by rwmj on Friday April 22, 2022 @11:29AM (#31122831)
I was actually looking at urllib3 yesterday trying to work out the return value from HTTPConnection.connect which calls this _new_conn function internally:

    def _new_conn(self):
        """Establish a socket connection and set nodelay settings on it.

        :return: New socket connection.
        """
  ...
        try:
            conn = connection.create_connection(
                (self._dns_host, self.port), self.timeout, **extra_kw
            )
  ...
        return conn
(I've chopped it down a bit to emphasise the important bits)

What's the type of "conn"? It certainly wasn't clear to me that it's a socket.

But just now I looked at upstream and I notice they've added type annotations, which do greatly improve things:

https://github.com/urllib3/urllib3/blob/e16beb210c03c6f5ce4e...

    def _new_conn(self) -> socket.socket:
  ...
So a small victory for type annotations there.
Re:Python’s “type hints” are a bit of a disappointment to me by CraigJPerry on Friday April 22, 2022 @04:13PM (#31127443)
When i hover over connection.create_connection i get a docstring that says it returns a socket.

That docstring isn’t enough for the problem you had though, e.g. I wasn’t clear from that if they meant a socket.socket or maybe some special socket derivative type so i hit go to definition and create_connection is a short method - i can see it is indeed a socket.socket being created, configured and returned.

I’m guessing you’re not using any developer tooling, maybe a straight text editor i guess?

This kind of tooling has been around for a long time, i remember using rope and jedi in vim back around the late 2000’s i think. It’s gotten a LOT better since PyCharm appeared mid 2010’s i think - first i recall using it must have been around 2014-ish. These days, it’s even better. I would really strongly encourage adopting some kind of tooling that lets you navigate and has some basic refactoring - rename is usually 80%+ of the value there so it doesn’t need to be complex. A few ergonomics like having the ability to jump to test and call from repl with a keystroke - you’ll turbo charge your comfort and productivity.

That has to be our difference i think because it took one mouse move and one key chord to completely bottom out.

Re:Python’s “type hints” are a bit of a disappointment to me by wheelerof4te on Friday April 22, 2022 @09:50AM (#31121498)
Well, the author of that undocumented function maybe did not mean for it to become widely used.

There are a lot of "libraries" people write for their use only, who then put them on Github as a token of good will.

You as a user of someone else's library can either contribute to it or learn to use it. Otherwise, write your own equivalent.

Re:Python’s “type hints” are a bit of a disappointment to me by oriolid on Friday April 22, 2022 @11:40AM (#31123001)
> Otherwise, write your own equivalent.

And be judged for wasting time reinventing a wheel?

Re:Python’s “type hints” are a bit of a disappointment to me by wheelerof4te on Friday April 22, 2022 @11:58AM (#31123308)
Hey, it is still your wheel, built according to your use-cases.

That is never a waste of time.

Re:Python’s “type hints” are a bit of a disappointment to me by gilbetron on Friday April 22, 2022 @08:47AM (#31120949)
On the small scale, Python is very productive. Once you get to large codebases with a rotating roster of many developers, it becomes a net negative, which is why type specification languages are gaining major inroads. I love Python, but I wouldn't write anything for production at any scale in it anymore. But for small scale stuff, it remains my favorite! (Although, I like static binaries languages, like Go, for a lot of things these days because of the deployment simplicity)
Re:Python’s “type hints” are a bit of a disappointment to me by j4mie on Friday April 22, 2022 @09:24AM (#31121252)
What's your definition of "large codebases" here? My experience is that on Python codebases large (~100k lines) and small, type annotations are generally a net negative, particularly with a "rotating roster of many developers", because of their complexity and detrimental effect they have on readability. As the OP says, incorrect types are worse than no types at all.
Re:Python’s “type hints” are a bit of a disappointment to me by gilbetron on Friday April 22, 2022 @10:11AM (#31121748)
type hinting is a bandaid, I'm not going defend it. My argument is that statically typed languages are better for large scale development.
Re:Python’s “type hints” are a bit of a disappointment to me by j4mie on Friday April 22, 2022 @10:31AM (#31122025)
You still haven't defined "large scale" or "better". And you haven't backed up your argument with any evidence.
Re:Python’s “type hints” are a bit of a disappointment to me by wheelerof4te on Friday April 22, 2022 @09:44AM (#31121431)
How is typing productive in large codebases? If I see a bunch of imports related to typing only, I have to juggle them around in my mind together with stuff that really matters.

Not to mention the notorious circular import problem, that is much more likely in a big codebase.

If I have a custom class, that class has to be passed as a type hint for functions. What If I use that class in another module, but have to import it inside this one that has a type-hint only?

Well, let me introduce you to their genious solution:

  from _future_ import annotations
  from foomod import FooClass

  def myfun(foo: FooClass):
    return foo.bar()
Wonderful, isn't it?
Re:Python’s “type hints” are a bit of a disappointment to me by icedchai on Friday April 22, 2022 @06:20PM (#31128923)
I also find most of the "import typing" stuff to be clutter. I worked at a place that was heavily into adding typing to existing code, some of which was almost a decade old. They spent more than a few person years on that effort, and it's still going on.

Not once did I find the additional typing useful in my actual day-to-day work.

Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Saturday April 23, 2022 @12:30AM (#31131409)
Scaling a code base doesn't start or end with type checking. Some of the answers to what you are implying is: Use interfaces when using OOP. Consider dependency injection or other Inversion of Control patterns. Maybe don't use OOP as much...
Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Friday April 22, 2022 @08:59AM (#31121062)
What is "major inroads"? Python is actually rising in popularity and major companies are building big things entirely in Python...

In my opinion there is no excuse not to.

Re:Python’s “type hints” are a bit of a disappointment to me by gilbetron on Friday April 22, 2022 @10:08AM (#31121713)
Python has a tremendous amount of momentum because it has become so popular outside of the traditional software development world, but other languages are picking away at it, even given that momentum. And while I am in a bubble, like everyone else, in my bubble, and those I talk to in my bubble, all see large a shift away from Python.

Adding stronger typing, like type hints, could reverse that, of course.

The reason not to is performance and reliability. Typing helps with the latter, Python is just bad at the former.

Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Saturday April 23, 2022 @12:31AM (#31131412)
That "shift" away from Python wouldn't be seen in any particular data, right?
Re:Python’s “type hints” are a bit of a disappointment to me by icedchai on Friday April 22, 2022 @09:25AM (#31121267)
Major companies build things entirely in Javascript, too. Popularity doesn't mean anything. Honestly, for a small web app, I'd pick PHP / Laravel over Python. Deployment is way simpler.
Re:Python’s “type hints” are a bit of a disappointment to me by foepys on Friday April 22, 2022 @09:27AM (#31121290)
What you both are experiencing is your bubbles clashing.
Re:Python’s “type hints” are a bit of a disappointment to me by tezzy on Tuesday April 26, 2022 @05:54PM (#31173658)
I have been developing almost exclusively in Python for the last 4 years (occasional C#, Java and PHP) and although my entire team disparages PHP it is really quicker and fewer characters for most stuff.

Luckily IDEs can auto add the imports, but sometimes a slightly mistyped piece of code auto adds an import I need to delete, I love avoiding imports and circular imports in PHP. The other nice thing is avoiding random python behaviour differences in MacOS, Windows and Ubuntu. Code that works fine in CircleCI but not locally. Works on a Mac but not on windows etc… I didn’t experience that with PHP.

Not sure there are a huge number of long term PHP devs who switch to Python or the other way around to have a reasonable opinion.

Re:Python’s “type hints” are a bit of a disappointment to me by gilbetron on Friday April 22, 2022 @10:09AM (#31121720)
This is a rather uninteresting statement, as we all live in bubbles - knowledge of them helps, but really just puts you in a different bubble. Still a bubble.
Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Saturday April 23, 2022 @12:32AM (#31131420)
I'd say all metrics point to the popularity of Python increasing, while there is no data indicating that people are fleeing Python en masse. Or at all, actually.
Re:Python’s “type hints” are a bit of a disappointment to me by analog31 on Friday April 22, 2022 @08:33AM (#31120837)
In my view it's both. I'm one of those "scientific" programmers. I've used type hints, just to learn it, but tend not to use them in practice. Bugs caused by typing errors seem to be extremely rare in my little world.

I've also programmed extensively in Pascal, assembly, and C. I get it about types. Don't forget C has 8 different types of integers that have to be kept straight. ;-)

On the other hand, I realize that any of my programs is but a little nub of code sitting on top of large and expertly maintained libraries. I'm grateful for whatever the authors of those libraries are doing to keep their sanity, and am not surprised when I see type hints in those codes.

Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Friday April 22, 2022 @09:14AM (#31121185)
If you have programmed extensively in Pascal, assembly and C, you aren't "one of those scientific programmers". Or at least not the newer generation that got started on R, Python and maybe SAS...