Hacker News new | ask | show | jobs
by sumofzeros 2806 days ago
> 50K LOC python/django codebase.

How much of it is generated?

2 comments

I would guess none. Code generation is very rare in the Python community. Mainly because it's generally unnecessary given the nature of the language.
Sorry for the bluntness of my question: I only have little experience in using Python, which I acquired while trying out Django, and I remember using scripts to generate certain parts of the site (things might have changed since then?).

To be fair, Django is pretty good: iirc, it induces good discipline for development, which is perhaps why it is so easy to handle a large codebase.

On the other hand, the business logic is outside the scope of Django (or any other framework), and there, if the devs do not follow good practices and develop the right tools, it might be more difficult to be productive.

The way I see it, people using dynamic languages have much more freedom in development, but also less safeguards, which means that they have to build them to make their code more robust. Having code generators is a way of getting back some safety, because you only have to make sure the generators are producing correct code.

Custom code, however, need to be thoroughly tested to be considered safe, and if the compiler doesn't do any type level consistency check, it's that many more tests that needs to be written, which adds up to the LOC count.

I frequently use code generation in python. why write thousands of lines of boilerplate code in any language when you can just generate it? Maybe I'm just lazy but the results are better and more consistent to get something done.
I would regard anything other than tiny amounts of boilerplate to be a code smell in most languages.

Code generation has so many downsides and Python is so dynamic I can't think what you're doing that couldn't be done better without code generation.

Weird, typically you can use metaclasses or mixins to remove such boilerplate.
I utilize that too but why not generate new models with forms, cbvs, drf endpoints, serializers, etc? You can pick and choose what you need, add the mixins and move on. Plus initial project using cookicutter to generate the original project in a much more fitting and featureful structure.
I've been a Django developer for years and—barring Django migrations—I've never 'generated' a single line of code.
Honestly you are missing out, I've been developing in Django for years and can't imagine not generating code anymore. Generate and a bit of tweaking, the results are the same with a lot less time.