Re:Writing Python Like Rust
by synergy20 on Wednesday June 28, 2023 @11:21PM
(#36515940)
django has 500K lines of python and it's considered well written and stable, so it's possible to do python with large code base I think. oddly, django does not seem to be even using type hints, new features such as dataclasses was not found from the source base either, still it just works well somehow.
[ Parent
| on HN ]
I was curious:
SLOC Directory SLOC-by-Language (Sorted)
232099 tests python=232099
102470 django python=102470
424 docs python=424
158 scripts python=142,sh=16
21 top_dir python=21
0 extras (none)
0 js_tests (none)
Totals grouped by language (dominant language first):
python: 335156 (100.00%)
sh: 16 (0.00%)
Please credit this data as "generated using David A. Wheeler's 'SLOCCount'."Wow, 2.3x for tests/src ratio. I remember some recommendation for Java to have around 0.9x ratio, otherwise too much tests maintenance.
Depends on the project of course, e.g. SQLite has an insane ratio.
Could also be that Java's typing already accounts for some part of what would need to be tests in Python code...
Exactly, that's what I meant. E.g.
if very_rare_condition:
raise MyRareException
Java wouldn't compile (no exception instantiation), but Python would work fine in production until the rare condition happened (but not captured above, as it's a class, not instance). Cases like that justify 100% tests coverage in Python, but not Java.That's because a great deal of Django was written before type hints or even dataclasses existed.
And type hints aren't really that mature yet. If you look at the `typing` module's documentation in Python 3.11, there's 23 occurrences of the string "Changed in version". And the Python 3.12 version of the same document adds 9 more. Type hinting in Python is constantly evolving.
Re:Writing Python Like Rust
by walthamstow on Thursday June 29, 2023 @10:25AM
(#36520772)
That's the main reason we haven't adopted it at my place. We do have types of args and returns in docstrings though and it is enough for IDEs to do checks and suggestions from those types.