# Why I hate generated code

DevFeed: [Why I hate generated code](<https://devfeed.tech/articles/why-i-hate-generated-code-33384.md>)

Original publisher: [Read original article](<https://timkellogg.me/blog/2011/12/26/why-i-hate-generated-code>)

Published: 2011-12-26T00:00:00Z

Content type: opinion

Language: en

Sources: [Tim Kellogg](<https://devfeed.tech/sources/tim-kellogg.md>)

Topics: [Code generation](<https://devfeed.tech/topics/code-generation.md>), [maintenance](<https://devfeed.tech/topics/maintenance.md>), [Rails](<https://devfeed.tech/topics/rails.md>), [ASP.NET](<https://devfeed.tech/topics/aspnet.md>), [mvc](<https://devfeed.tech/topics/mvc.md>), [SQL](<https://devfeed.tech/topics/sql.md>)

Tags: [asp-net](<https://devfeed.tech/tags/asp-net.md>), [code-generation](<https://devfeed.tech/tags/code-generation.md>), [maintenance](<https://devfeed.tech/tags/maintenance.md>), [mvc](<https://devfeed.tech/tags/mvc.md>), [rails](<https://devfeed.tech/tags/rails.md>), [software](<https://devfeed.tech/tags/software.md>)

## AI overview

The author argues that generated source code can create maintenance problems when it produces large amounts of unused or dead code. The article distinguishes this from compiler output and just-in-time code generation, which the author considers useful because it is generated only when needed.

## Source excerpt

If you've worked with me for any amount of time you'll soon figure out that I often profess that "I hate generated code". This position comes from years of experience with badly generated code. Let me explain.The baby comes with a lot of bathwaterIn the past year I had an experience with a generated data layer where CodeSmith was used to generate a table, 5 stored procedures, an entity class, a data source class, and a factory class for each entity that was generated. My task was to convert this code into NHibernate mappings.The interesting thing about this work is how little of the generated code was actually being used. I'm sure, in the beginning, the developer's thoughts were along the lines "oh look at all this code I don't have to write manually :D". However, after some time, subsequent developer's thoughts were along the lines of "with all this dead code, it's hard to find real problems". It's funny how some exciting breakthroughs turn into headaches down the road. The table is always used, but some entities are created & read but never modified, others are only created during migrations and only read from during run time.Code generators often produce code you don't need. Since all code requires maintenance, dead code is just a liability because it doesn't provide any benefit. I always delete dead code and commented out code (it'll live on in version control, no need to release it into production).There are several professional developer communities that generate code as a way of life. Ruby on Rails comes prepackaged with scripts to generate models, views, and controllers in a single command. ASP.NET MVC will generate controllers and views with a couple clicks. And if you've ever used either of these frameworks, you'll probably find yourself deleting a lot of generated code.The problem of transient code generationThe issue that I keep running into with my policy of hating code generation is that it's nearly impossible to be a professional software engineer and