3 ms·
Here is some actual useful advice: Use a type checker! Pyright can get you like 80% of Rust's type safety.
by veber-alex 1y ago
Here is some actual useful advice:
Use a type checker! Pyright can get you like 80% of Rust's type safety.
- kragen 1y agoWhat are the major pros and cons of Pyright and Mypy relative to one another?
- koakuma-chan 1y agoI 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.
- dkdcio 1y agoyou can and this is a juvenile position. there is reliable software in any language as popular and widespread as Python. every language is flawed
- IshKebab 1y ago> every language is flawed But not equally flawed. https://www.lesswrong.com/posts/dLJv2CoRCgeC2mPgj/the-fallacy-of-gray https://www.lesswrong.com/posts/dLJv2CoRCgeC2mPgj/the-fallac...
- grep_it 1y agoIs 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.
- nicce 1y agoAll 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.
- IshKebab 1y ago> 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.
- deleted 1y ago[deleted]
- ninetyninenine 1y agoIt 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.
- koakuma-chan 1y agoIf 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.
- ninetyninenine 1y agoI 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.
- mixmastamyk 1y agoIndeed, 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.
- dangus 1y agolol, Instagram is written in Python.
- super_flanker 1y agoWhat exactly? I work at Instagram.
- dangus 1y agoI 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-python/ https://www.pythonpool.com/how-instagram-is-using-django-and... https://python.plainenglish.io/how-instagram-uses-python-scaling-the-worlds-largest-django-application-1fb274fdf3d6 https://python.plainenglish.io/how-instagram-uses-python-sca...
- guitarbill 1y agoSorry, 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.
- deathanatos 1y agoI'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]
- koakuma-chan 1y ago> There is an extension to aid in this, but it regrettably SIGSEGVs. Love this.
- veber-alex 1y agoI 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=GYJw9gtgBALgngBwJYDsDmUkQWEMoAiSAxjAFBkBSAzmCgGoCGANgK4CmUAvFNTCFAA%2BhEjADafEABooAIhp0mbdrIC6FACbtgUYGDAAKAJRQAtAD4oChiw4AuMlCfOAHnZGkJ-GZNXcoAN6yjLLusgBGsgC%2Bjs5OIOwwrCAoUC5kQA https://pyright-play.net/?pyrightVersion=1.1.403&code=GYJw9g...
- mixmastamyk 1y agoI recommend first starting with pyflakes and later ruff on a huge old Python project. Do file by file. When done, do typing similarly.
- munificent 1y ago> 80% of Rust's type safety. Sort of like closing 80% of a submarine's hatches and then diving.
- mixmastamyk 1y agoVery few bugs are life-threatening.
- pkolaczk 1y agoBut 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.
- munificent 1y agoThe 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.)
- jaza 1y agoExactly! 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.
- IshKebab 1y agoI 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.)
- arthur-st 1y agoTo be fair, you do get enums and pattern matching from base language.