Thursday, March 26, 2009

Why code generate something after it is already written?

[This was originally posted at http://timstall.dotnetdevelopersjournal.com/why_code_generate_something_after_it_is_already_written.htm]

If you've already written something, why go back and code-gen it? There could be a couple reasons:

  • You're going to write a lot more of it, so you might as well leverage code-gen for all that existing code.
  • You need to extend it with more functionality. Sure, the current stuff is already written, but you need to add new (tedious) features, like recording which properties of a class have had their setters called.
  • You want to make it easier to maintain. Manually-maintained code counts as technical debt. Such code grows, get copied into off-by-one, and gradually gets customized. By code-generating it now, you'll make maintenance easier in the future.
  • You want to document the rules. As codeGen essentially acts as documentation, this will give you a place to clearly define all those boundary cases.
  • The code is already easy to generate. If the code is already prepared to be generated, might as well go ahead and migrate it.

No comments:

Post a Comment