Live data from Hacker News

Boring Python: Code quality

b-list.org

81–90 of 232 posts

Re: Boring Python: Code quality

#81
post #34

Earlier quoted context omitted.

Does ruff replace isort? Because I'm really unhappy with it, it doesn't work with tabs and conflicts with yapf all the time.

> it doesn't work with tabs What do you mean by this? Are you indenting Python with tabs?

Yes. The code started as being indented by tabs, so changing it now is a mess. Also, not to start a flamewar, but I've always preferred tabs to spaces in any language, I find them more reliable, easier to use...

Re: Boring Python: Code quality

#82
post #65

Earlier quoted context omitted.

Anyone with experience of writing both dynamic typed and statically typed can tell you that. Infact, you could just try it out for yourself. But here is your internet source for this blatantly obvious fact: https://games.greggman.com/game/dynamic-typing-static-typing...

I do have such experience and I really can't tell that. Which is why I wondered if anyone else was in fact saying that. > But here is your internet source for this blatantly obvious fact: https://games.greggman.com/game/dynamic-typing-static-typing ... Ah no I meant a proper peer reviewed source. The claim that untyped code has fewer bugs is completely bonkers, so I was quite sure that no such source existed. Why do…

"If typechecking would actually introduce bugs, it'd be better not doing it right?"

Correct if you misapply a tool to the wrong situation you get poor or negative results.

The right tools are unit testing, integration testing, uat and automated whole system testing.

Re: Boring Python: Code quality

#83

I wish VSCode would figure out that ExampleModel.objects.first() returns ExampleModel or None or ExampleModel.objects.filter() returns an iterable of ExampleModel. Has anybody gotten this working, automatically or manually annotating?

It's not a shortcoming of vscode it's due to the dynamic untyped nature of Django models unless you have a plugin or add typing to your own managers

Re: Boring Python: Code quality

#84
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 catch bugs when unit testing, now they are much more commonly type errors.

The other thing typing does is allow for refactoring code. If anything, high code quality relates to the ability to refactor code confidently and typing helps this. Therefore I would put it at the top of the list above all the tooling presented (exception I agree with ci/cd)

Re: Boring Python: Code quality

#85
post #10
post #5

Earlier quoted context omitted.

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

Don't pin unless it's needed. I have a library… most downloaded version is 3 years old. The newer versions are massively faster but nobody uses them.

Agree in principle, but I'm giving advice to someone who programs on occasion and is primarily concerned with their programs breaking due to dependency version upgrades when they come back to them after a little while.

Re: Boring Python: Code quality

#86
post #65

Earlier quoted context omitted.

I do have such experience and I really can't tell that. Which is why I wondered if anyone else was in fact saying that. > But here is your internet source for this blatantly obvious fact: https://games.greggman.com/game/dynamic-typing-static-typing ... Ah no I meant a proper peer reviewed source. The claim that untyped code has fewer bugs is completely bonkers, so I was quite sure that no such source existed. Why do…

"If typechecking would actually introduce bugs, it'd be better not doing it right?" Correct if you misapply a tool to the wrong situation you get poor or negative results. The right tools are unit testing, integration testing, uat and automated whole system testing.

That seems to completely forget the fact that libraries exist, that A LOT of bugs can happen calling libraries, and that you're not really supposed to unit test libraries, they are supposed to have their own tests.

Re: Boring Python: Code quality

#87
post #65

Earlier quoted context omitted.

I do have such experience and I really can't tell that. Which is why I wondered if anyone else was in fact saying that. > But here is your internet source for this blatantly obvious fact: https://games.greggman.com/game/dynamic-typing-static-typing ... Ah no I meant a proper peer reviewed source. The claim that untyped code has fewer bugs is completely bonkers, so I was quite sure that no such source existed. Why do…

"The claim that untyped code has fewer bugs is completely bonkers" There are plenty of academic sources that will tell you that the number of bugs in a program is directly proportional to the number of lines in the program and static typing has no effect on this. https://stackoverflow.com/questions/2898571/basis-for-claim-... Additionally, statically typed code involves large amounts of boilerplate code in the form o…

Please don't reply multiple times to the same thing.

> Actual Python houses typically don't use static typing.

If you had ever developed python professionally, you'd know this to be untrue.

Also your "paper" points to a 404 page.

Re: Boring Python: Code quality

#88

If you aren’t happy with Flake8, Pylint, and isort (or maybe if you are!), I recommend checking out Ruff: https://github.com/charliermarsh/ruff It’s literally 100 times faster, with comparable coverage to Flake8 plus dozens of plugins, automatic fixes, and very active development.

+100 on ruff.

replaced both flake8 and isort across all my projects

Re: Boring Python: Code quality

#89

If you aren’t happy with Flake8, Pylint, and isort (or maybe if you are!), I recommend checking out Ruff: https://github.com/charliermarsh/ruff It’s literally 100 times faster, with comparable coverage to Flake8 plus dozens of plugins, automatic fixes, and very active development.

Does ruff replace isort? Because I'm really unhappy with it, it doesn't work with tabs and conflicts with yapf all the time.

yes it does. see see https://github.com/charliermarsh/ruff#supported-rules for the rules it supports. "IOO1" being the code for isort

relevant section from my pyproject.toml

  [tool.ruff]
  line-length = 88
  # pyflakes, pycodestyle, isort
  select = ["F", "E", "W", "I001"]

Re: Boring Python: Code quality

#90
post #86

Earlier quoted context omitted.

"If typechecking would actually introduce bugs, it'd be better not doing it right?" Correct if you misapply a tool to the wrong situation you get poor or negative results. The right tools are unit testing, integration testing, uat and automated whole system testing.

That seems to completely forget the fact that libraries exist, that A LOT of bugs can happen calling libraries, and that you're not really supposed to unit test libraries, they are supposed to have their own tests.

Unit tests test the parts of the library that are in use implicitly.

As does integration testing, user acceptance testing and whole system testing (QA engineers, frontend testing, etc.)

Nothing has been forgotten. Python isn't Java, nor should you develop your Python code as if it were Java. Python has it's own software development practices that take advantage of the language's strengths including dynamic typing.

It you don't know how to work with a dynamically typed language properly, that's on you. And I guarantee you will get poor results pretending it's a statically typed language.

Post reply on HN