by gabereiser · 4y ago · 0 comments
Why do we do this? The more LOC is somehow attributed to more features? That simply isn’t true. More LOC means two things. One, what you are trying to do with the language is pushing its limits. Or two, you don’t understand the domain.
Most large monorepo’s I have seen fall into the latter category while few reside in the former. Game engines, mature enterprise software, and a few others are large (probably OP’s codebase too), but we seem to revel in the fact that we have so much code to grok. Sometimes conciseness is better than cleverness.
Back to mypy. I’d throw in black as well. Combining black, flake8, mypy, on precommit has loads of advantages. It’s completely opinionated but I find it helps me write better Python code.
> Sometimes conciseness is better than cleverness.
Isn't concise and clever on the same side of the balance? Cleverness and abstraction is how you cut down on LOC.
Abstraction has its own cost, so while you can trade LOC for cleverness/abstraction, there's limits/costs to that as well.
Also also, python/mypy still lacks support for higher-kinded types, which really puts a soft-ceiling on the amount of abstraction you can type-safely utilize.
Aaaanyways, I think the whole original point is, "we have a large codebase, and mypy helps keep the wheels on at speed".
+1 on black and precommit. That has done wonders for codebase consistency. I'd run flake8 too but the maintainer is weirdly opposed to supporting pyproject.toml for config.
I haven't used it in anger yet, but FlakeHeaven (https://github.com/flakeheaven/flakeheaven) looks like a nice fork that includes pyproject.toml support.
LOC should be looked at as a negative at a certain point. Software Engineers spend more time reading code than writing code. The more LOC you have, the more an engineer needs to read to get work done. LOC is not a good measurement of quality software nor is it a measurement of complexity of the problem, only the complexity of the code.
I tried to acknowledge the deficiencies in LOC in the second paragraph... but it felt like a useful shorthand for conveying a sense of scale and complexity (at least to an order-of-magnitude) in a domain-agnostic way.
Outside of Mypy, we use: black, isort, flake8, docformatter, and autoflake (to remove unused imports) -- all on pre-commit + enforced on CI. I'd like to see Black cannibalize more of that toolchain :)
Complexity to me comes from obtuse concepts. The business trying to cast too wide a net or something along those lines. Microservices help to concise that vision into reusable bits but its gets a bad wrap because of the context switching (which means your domains aren't well defined.)
Keep using those tools though, they will save you so much time down the road when you enforce test coverage and fully lean in on that autoflake.