Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 10 | Comments: 37

filter by tags archive

Code Generation and the Open Close Principal

time to read 1 min | 83 words

Vladan Strigo made a really inspiring comment about code generation in the NH Users list.

I didn't want to use codesmith for that because it would de-OCP-fy me in my future efforts :)

That makes a lot of sense, and manages to touch on what bothers me the most with code gen as an architectural approach. It gives up a very important concept, and that affect a lot of the stuff that is dependant on that.


Comments

Mark Lindell

I agree that Passive code gen can be abused.

I particularly don't like passive code gen other than a template starting point to save you some typing. Come on, snippets are passive code gen and no one would deny the benefit of those, right?

On the other hand, I do believe that active codegen can be used appropriately to solve the right problems. Infrastructure that are driven by metadata can benefit from active code generation. (Proxy generation?)

After all, isn't Reflection.Emit a form of active codegen?

I understand your dislike of code gen as an architectural solution when good design would solve the same problem without violating OCP. (yeah you know me -- sorry music joke)

Alon Fliess

So JIT is a violation of OCP, it does code generation from IL to assembler. Also any runtime implementation of proxy, interception layer, data accessors, etc. are bad.

I don't think that code generation has anything to do with OCP, its the design of your system that has. Code Generation may be based on the same good OO patterns. I have implemented a system were all my code generators are discovered in runtime. They registered themselves to a pub/sub mechanisms that calls them whenever they need to emit their code. I can remove or add a generator without touching any other generator...

Any generator can derived from existing one and change the code it emits.

This is an OO & OCP based design...

Alon.

Ayende Rahien

You missed this part: "code gen as an architectural approach"

I wasn't talking about emitting IL to do something at runtime. I was talking about code gen as an architectural approach, that is, we will define the application using (DB, XML, pretty pictures) and generate the code from there

Lars Wilhelmsen

Not to be annoying or anything - but isn't there a slight difference between "Principal" & "Principle"?

--larsw

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. Production postmortem: The case of the memory eater and high load - 13 hours from now
  2. Production postmortem: The case of the lying configuration file - about one day from now
  3. Production postmortem: The industry at large - 3 days from now
  4. The insidious cost of allocations - 4 days from now
  5. Find the bug: The concurrent memory buster - 5 days from now

And 4 more posts are pending...

There are posts all the way to Sep 10, 2015

RECENT SERIES

  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    14 Aug 2015 - The case of the man in the middle
  3. What is new in RavenDB 3.5 (7):
    12 Aug 2015 - Monitoring support
  4. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats