Most active commenters
  • koakuma-chan(4)
  • mixmastamyk(4)
  • IshKebab(3)

←back to thread

517 points bkolobara | 32 comments | | HN request time: 1.53s | source | bottom
Show context
koakuma-chan ◴[] No.45041723[source]
I encourage every one to at least stop writing code in Python.
replies(5): >>45041794 #>>45041941 #>>45042073 #>>45043031 #>>45049992 #
1. veber-alex ◴[] No.45041941[source]
Here is some actual useful advice:

Use a type checker! Pyright can get you like 80% of Rust's type safety.

replies(7): >>45042031 #>>45042063 #>>45042147 #>>45042269 #>>45043223 #>>45047269 #>>45050186 #
2. koakuma-chan ◴[] No.45042031[source]
I don't agree that Python can be saved by a type checker. The language itself is flawed irreversibly, as well as its ecosystem. It's a big big mess. Can't build reliable software in Python.
replies(5): >>45042142 #>>45042151 #>>45042254 #>>45042267 #>>45047827 #
3. kragen ◴[] No.45042063[source]
What are the major pros and cons of Pyright and Mypy relative to one another?
4. dkdcio ◴[] No.45042142[source]
you can and this is a juvenile position. there is reliable software in any language as popular and widespread as Python. every language is flawed
replies(1): >>45053881 #
5. guitarbill ◴[] No.45042147[source]
Sorry, it's not even close to Rust. Or even C# or Java. It can't provide the same "fearless refactoring". It is better than being blind/having to infer everything manually. That's not saying much.

And that's assuming the codebase and all dependencies have correct type annotations.

6. grep_it ◴[] No.45042151[source]
Is this rage-bait? A language alone doesn't dictate reliability. There are tons of large scale systems out there running on Python. As for the language being, "flawed irreversibly", I'd be curious to hear you expand on that with examples.
replies(2): >>45043132 #>>45053870 #
7. ◴[] No.45042254[source]
8. ninetyninenine ◴[] No.45042267[source]
It can't be 100% saved, but like the OP said it's 80% saved.

It's not true you can't build reliable software in python. People have. There's proof of it everywhere. Tons of examples of reliable software written in python which is not the safest language.

I think the real thing here is more of a skill issue. You don't know how to build reliable software in a language that doesn't have full type coverage. That's just your lack of ability.

I'm not trying to be insulting here. Just stating the logic:

   A. You claim python can't build reliable software.
   B. Reliable Software for python actually exists, therefore your claim is incorrect
   C. You therefore must not have experience with building any software with python and must have your hand held and be baby-sitted by rusts type checker.
Just spitting facts.
replies(1): >>45042484 #
9. deathanatos ◴[] No.45042269[source]
I've not tried Pyright, but mypy on any realistic, real-world codebase I've thrown at it emits ~80k errors. It's hard to get started with that.

mypy's output is, AFAICT, also non-deterministic, and doesn't support a programmatic format that I know of. This makes it next to impossible to write a wrapper script to diff the errors to, for example, show only errors introduced by the change one is making.

Relying on my devs to manually trawl through 80k lines of errors for ones they might be adding in is a lost cause.

Our codebase also uses SQLAlchemy extensively, which does not play well with typecheckers. (There is an extension to aid in this, but it regrettably SIGSEGVs.)

Also this took me forever to understand:

  from typing import Dict

  JsonValue = str | Dict[str, "JsonValue"]

  def foo() -> JsonValue:
      x: Dict[str, str] = {"a": "b"}
      return x

  x: JsonValue = foo()
That will get you:

  example.py:7: error: Incompatible return value type (got "dict[str, str]", expected "str | dict[str, JsonValue]")  [return-value]
replies(4): >>45042291 #>>45042438 #>>45043507 #>>45043716 #
10. koakuma-chan ◴[] No.45042291[source]
> There is an extension to aid in this, but it regrettably SIGSEGVs.

Love this.

11. veber-alex ◴[] No.45042438[source]
I don't use mypy so I can't comment on it but at least from what I have seen pyright is deterministic in it's output and get output json.

Regarding the ~80k errors. Yeah, nothing to do here besides slowly grinding away and adding type annotations and fixes until it's resolved.

For the code example pyright gives some hint towards variance but yes it can be confusing.

https://pyright-play.net/?pyrightVersion=1.1.403&code=GYJw9g...

replies(1): >>45047779 #
12. koakuma-chan ◴[] No.45042484{3}[source]
If you know some secret behind building reliable software in a programming language without types, with nulls, and with runtime exceptions, I'm all ears. I admit that a blanket statement "can't build reliable software" is going overboard, but the intention was to be dramatic, not factually correct. You can probably build reliable software in Python if you write everything from scratch, but I wouldn't want to do that to myself. I would rather use a programming language that has a type system, etc, and a better cultured ecosystem.
replies(1): >>45043515 #
13. nicce ◴[] No.45043132{3}[source]
All programming languages are Turing complete and you can arque with that. But you reach similar results with varying pre-knowledge and effort. Sometimes it is even impossible. All programs can be bug-free but most are not, if we reverse the argument.
14. munificent ◴[] No.45043223[source]
> 80% of Rust's type safety.

Sort of like closing 80% of a submarine's hatches and then diving.

replies(1): >>45047885 #
15. zelphirkalt ◴[] No.45043507[source]
I used mypy just fine for a previous job. If you are getting 80k errors, that means you are either starting very late to use the type checker and have done many dubious things before, or you didn't exclude your venv from being type checked by mypy.
16. ninetyninenine ◴[] No.45043515{4}[source]
I prefer types too.

But I can build reliable software without types as well. Many people can. This isn’t secret stuff that only I can do. There are thousands and thousands of reliable software built on Python, ruby and JavaScript.

replies(1): >>45047838 #
17. FreakLegion ◴[] No.45043716[source]
Everyone stubs their toe on container invariance once, then figures it out and moves on. It's not unique to Python and developers should understand the nuances of variance.
18. jaza ◴[] No.45047269[source]
Exactly! I code in Python every day, I haven't done so without a type checker (usually mypy) for years, I don't push a single change without type-checking it first, it catches stupid mistakes and saves me from breaking production all the time.
19. mixmastamyk ◴[] No.45047779{3}[source]
I recommend first starting with pyflakes and later ruff on a huge old Python project. Do file by file.

When done, do typing similarly.

20. dangus ◴[] No.45047827[source]
lol, Instagram is written in Python.
replies(1): >>45058679 #
21. mixmastamyk ◴[] No.45047838{5}[source]
Indeed, I write very reliable Python every day. A lot faster than the Rust straitjacket too.

We had sentry installed so I know exactly how many exceptions were happening, rare to zero. Lots of tests/constraints on the database as well.

That said I like a nice tight straitjacket at other times. Just not every day. ;-).

P.S. Python doesn’t have the billion-dollar-mistake with nulls. You have to purposely set a variable to None.

replies(1): >>45049395 #
22. mixmastamyk ◴[] No.45047885[source]
Very few bugs are life-threatening.
replies(2): >>45049301 #>>45054156 #
23. pkolaczk ◴[] No.45049301{3}[source]
But they decrease productivity. And I seriously think many teams don’t track the time sunk for fixing bugs / defects properly and they overestimate their productivity, especially the initial productivity boost from not having to think about types.
24. ironlenny ◴[] No.45049395{6}[source]
OP was needlessly combative. But, if I have to write a program that is correct (i.e. does what I want it do to), I'm going to write it in Rust. Not because you cannot write correct programs in Python. But because it's easier to prove it's correct in Rust.

As a solo dev, I find that I start off in Python, but at a certain project size I find it too unwieldy to manage (i.e. make changes without breaking things) and that's when I implement part or all of the project in Rust.

replies(1): >>45054170 #
25. IshKebab ◴[] No.45050186[source]
I would say it's more like 50%. Rust benefits not just from static typing but also a much stronger type system with things like enums, pattern matching, marker traits, ownership, mutability, etc. You don't get any of that with Pyright.

(But if you must use Python then definitely use Pyright.)

replies(1): >>45085347 #
26. IshKebab ◴[] No.45053870{3}[source]
> A language alone doesn't dictate reliability.

Nobody would claim that. But are you trying to say that the language has no effect on reliability? Because that's obviously nonsense.

Language choice has some effect on reliability, and I would say Python's effect is mediocre-to-bad. Depending on if you use Pyright. Not too bad if you do. Pretty awful if you don't.

27. IshKebab ◴[] No.45053881{3}[source]
> every language is flawed

But not equally flawed.

https://www.lesswrong.com/posts/dLJv2CoRCgeC2mPgj/the-fallac...

28. munificent ◴[] No.45054156{3}[source]
The problem with an unsound type system like TypeScript's is that once a value of an unexpected type has snuck through a soundness hole, it can end up anywhere in the program, even in code that seems fully safe.

(Also, it means that you don't get any performance benefit from static typing your program.)

29. mixmastamyk ◴[] No.45054170{7}[source]
> have to write a program that is correct

Yes, exactly. It doesn’t happen that often, but it does.

And folks have forgotten, not sure why, but Python was always billed as a prototyping language in the “olden tymes.” Or even “executable pseudocode.” At those it excels.

30. super_flanker ◴[] No.45058679{3}[source]
What exactly? I work at Instagram.
replies(1): >>45068664 #
31. dangus ◴[] No.45068664{4}[source]
I don’t work at Instagram so I can only go off of what I found online: https://www.pythonpool.com/how-instagram-is-using-django-and...

https://python.plainenglish.io/how-instagram-uses-python-sca...

32. arthur-st ◴[] No.45085347[source]
To be fair, you do get enums and pattern matching from base language.