Live data from Hacker News

Boring Python: Code quality

b-list.org

191–200 of 232 posts

Re: Boring Python: Code quality

#191

Even since the start of python typing, it was recommended to use a more generic type like Iterable instead of List. The author claims that List is too specific -- this seems like a straw man argument against typing that doesn't acknowledge python's own advice. Also, mypy has gotten really good in recent years and I can vouch that on projects that have typing I catch bugs much much sooner. Previously I would only catc…

I got good use of the run-time type checking of typeguard [0] when I recently invoked it via its pytest plugin [2]. For all code visited in the test suite, you get a failing test whenever an actual type differs from an annotated type.

[0]: https://github.com/agronholm/typeguard/

[1]: https://typeguard.readthedocs.io/en/latest/userguide.html#us...

Re: Boring Python: Code quality

#192
post #125

Earlier quoted context omitted.

You should not pin the public requirements that get uploaded with a library (listed in setup.py, setup.cfg, or pyproject.toml), since that will restrict your downstream users, leading to version conflicts and persistent security vulnerabilities. But it’s totally reasonable to pin the private requirements that you develop it against (listed in requirements.txt, poetry.lock, or similar), updating them every so often du…

So leaf packages can pin vulnerable or slow stuff why?

The context is

> For your dependency/versioning issue, use a virtualenv per-project and pin your dependency versions in requirements.txt

requirements.txt is not uploaded to PyPI and has no effect on your package’s dependencies when a user installs it (leaf package or no). It’s only used for developing the package itself, typically in a unique virtual environment.

Re: Boring Python: Code quality

#193
post #127
post #73

Earlier quoted context omitted.

> I love python but this is exactly why I prioritize languages that don't churn out new drastic features quickly. What do you mean by "drastic" features "quickly"? Python releases new version once a year these days, and upgrading our Django-based source code with 150 dependencies from 3.4 to 3.11 literally meant switching out the python version in our CI configuration and README.rst every once in a while, no code cha…

Firsr, to this date, stuff I absolutley need that is in 2.7 i have to either try to fix or venv or somehow get it to work is one of my biggest headaches (Not my code). Second, yes, all you have to do is switch out the python version to upgrade but let's say you start using f-strings that means all of your users (doesn't apply to django since it is server software) have to upgrade to the right python version including…

> Firsr, to this date, stuff I absolutley need that is in 2.7 i have to either try to fix or venv or somehow get it to work is one of my biggest headaches (Not my code).

2.7 was supported for 10 years and it's support ended 2 years ago. There's been ample time to upgrade the code or look for an alternative. If I "absolutely needed" to use a piece of code that I didn't write, is for an unsupported platform and is itself unsupported, I'd absolutely find the time for it. As a developer if I use a library that hasn't been touched for 3 years it's a red flag and I start to look for alternative libraries or forking the code.

> That means all other libraries need to use the same or greater python version but what if your distro doesn't yet support the very latesr python version? It's such a nightmare.

if your distro doesn't support the latest python version you're probably on a very old distro. For example python3.11 installs fine on all supported versions of Ubuntu (18.04+) and Debian (10+) and both Windows (8.1+) and macOS (10.15+). And python3.9 installs fine even on centos7 (released in 2014) and still supports the vast majority of python libraries.

If you're on an OS nearing or past its end of support, you can't reasonably expect all the latest software to work on it. And it's usually fine to just use an older version of python / libraries until you're ready to update.

> New versions should come out no more often than every 3-4 years imho

If new versions came out every 3-4 years, that would mean they would have more drastic changes, because the smaller changes would accumulate over that duration. The longer the "new features" are out, the longer users have to upgrade their system and the longer developers can take getting used to them.

But in the end, it doesn't really matter how often a new version comes out but rather how long the old versions should be supported, right? And I think it's up to the library authors to decide how long to support older versions, not the authors of the programming language.

Re: Boring Python: Code quality

#194
post #98
post #94

Earlier quoted context omitted.

A lot of modern open source projects include a lock file or some other mechanism that ensures that all contributors use the same versions of certain key tools. Obviously there are still going to be some differences in the environment, but for things like formatting, linting, etc, it's generally fairly easy to lock down a specific version. In Python, the easiest way to achieve this is using Poetry, which creates a loc…

Using lock files is a good way to make sure your software never ends up in a distribution and in the hands of users.

Distros can keep their own lock file that is based on their own release branch's versions. If it doesn't build, the pkg maintainer will either file a bug report or make a patch, or neither.

Source: I maintain distro packages.

Re: Boring Python: Code quality

#195

Earlier quoted context omitted.

pre-commit is very useful, in my opinion. When organising code from a lot of Python developers at least, getting the boring stuff like formatting, import ordering, linting, mypy etc. sorted is a time saver.

Do you know how slow all of that is? Do you want to run all of that per every commit? The result would be people making a monocommit rather than incremental commits that is easy to review one by one.

I do like pre-commit for enforcing linted and typed code but the speed (or lack thereof) does hurt.

Re: Boring Python: Code quality

#196
post #152

Earlier quoted context omitted.

> The other thing typing does is allow for refactoring code. No. What allows you confident refactoring code are automated tests. I honestly can't understand why people are so obsessed about types, especially in languages like Python or Javascript.

> I honestly can't understand why people are so obsessed about types It's a very powerful sanity check that lets me write correct code faster, avoiding stupid bugs that the unit tests will also, eventually, find. And, to me, reading the code is much much nicer. Types provide additional context to what's going on, at first glance, so I don't have to try to guess what something is, based on its name: results: list[Some…

> I don't have to try to guess what something is, based on its name

It's probably just a bad example, but in case it isn't:

Sounds like you ended up at the same place. You went from guessing what is some_api.get_results(), based on it's name, to guessing what is SomeAPIResult, also based on it's name.

If some_api is your library, then you could have just added type hints to get_results() and let type inference do it's job.

If it's a third party library, then using your custom SomeAPIResult means that code is becoming alien to other engineers that worked with that library in the past. It might be worth it, but it's definitely controversial. You probably should've done it with stubs anyway.

Re: Boring Python: Code quality

#197

Earlier quoted context omitted.

"I did not bother. The fact that microsoft, google and facebook invest money into it is proof enough. You reject it because you're being irrational." Basically, you are saying you are a cargo cultist rather than a serious software developer. You fail to understand that the software practices of large multi-national companies are rarely good. Good luck flying your plane: https://www.abyssapexzine.com/2020/03/cargo-cul…

> Basically, you are saying you are a cargo cultist rather than a serious software developer. No. I'm saying I tried both ways and I know advantages and disadvantages and I'm capable of deciding by myself. You on the other hand did not try both but feign expertise. > Good luck flying your plane: https://www.abyssapexzine.com/2020/03/cargo-cult/ Yes everybody knows what a cargo cult is. It's not some sort of intellect…

No offense, but it's like a textbook on awful debates.

Your best arguments are: "big guys are doing it therefore it's good for me too" (argument from authority) and "I tried both and decided only one is good" (argument from authority/anecdotal evidence). Plus a ton of ad hominems.

To be fair, your opponent isn't very different.

Re: Boring Python: Code quality

#198

Earlier quoted context omitted.

> if you try to force contributors to reproduce exactly your local setup, you will be left with no contributors. ... That's not been my experience. To the contrary, having a requirements.txt means your contributors are more likely to have a working environment, as when your package depends on package X but the contributor has a 5-year-old buggy version of X, doesn't realize it, and it causes your program to do the wr…

> How do black reformatting changes cause an extra 5 minutes? Did you even read my comments? Black reformatting causes more steps in bisecting. It's quite easy that a test suite takes 5+ minutes.

None of your comments mention running the full test suite, only build.

When I've used bisection, I've always had a targeted test that I was trying to fail, not the entire test suite. This is because the test suite at the time of that commit wasn't good enough to detect this failure. Otherwise it would have failed with that commit.

Instead, a new failure mode is detected, an automated test developed, and that used to probe the history to identify the commit.

Why are your bisections doing the full suite?

> Black reformatting causes more steps in bisecting

Yes, of course it does. But it's log2(n).

The worst-case analysis I did assumed there was a black commit after every human commit. This is a bad practice. You should be using black as a pre-commit hook, in which case only your new collaborator's commits will cause re-formats. And once they are onboard, you can explain how to use requirements.txt in a virtualenv.

If only 10% of the commits are black reformattings, which is still high!, then a bisection of 100 human commits (plus 10 black commits) goes from about 6.64 tests to 6.78 tests, which with a 5 minute test suite takes an additional 42 seconds.

If it's 3% then your bisection time goes up by 13 seconds.

If you are so worried about 13 seconds per bisection then how much time have you spent reducing the 5 minute test suite time? I presume you run your test suite before every commit, yes? Because if not, and you're letting CI run the test suite, then you're likely introducing more commits to fix breaking tests than you would have added via black, and taking the mental task switch hit of losing then regaining focus.

Re: Boring Python: Code quality

#199

Earlier quoted context omitted.

> Basically, you are saying you are a cargo cultist rather than a serious software developer. No. I'm saying I tried both ways and I know advantages and disadvantages and I'm capable of deciding by myself. You on the other hand did not try both but feign expertise. > Good luck flying your plane: https://www.abyssapexzine.com/2020/03/cargo-cult/ Yes everybody knows what a cargo cult is. It's not some sort of intellect…

You literally told me that you are a cargo cultist and your words should not to be listened to in your previous comment. No one who has really tried both would conclude that static typing is better hence I know you are lying. :p

> You literally told me that you are a cargo cultist and your words should not to be listened to in your previous comment.

I did no such thing. But after hours of you writing lies, I'm not surprised you wrote another one.

> No one who has really tried both would conclude that static typing is better hence I know you are lying. :p

In 10-15 years, when you will actually have some non-made-up programming experience, you will agree with me :)

Re: Boring Python: Code quality

#200
post #182

Earlier quoted context omitted.

> But how about not building the complicated system in the first place? "For every complex problem, there's a solution that is simple, neat, and wrong."

Read it carefully. Complicated is not the same as complex .

A person judging a solution he doesn't know to a problem he doesn't know… How well reasoned.
Post reply on HN