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: 5,955 | Comments: 44,412

filter by tags archive

Code Generation and the Open Close Principal


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. What is new in RavenDB 3.5–Intro - 5 hours from now
  2. Production postmortem: The case of the infected cluster - about one day from now

There are posts all the way to Jul 09, 2015

RECENT SERIES

  1. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
  2. Special Offer (2):
    27 May 2015 - 29% discount for all our products
  3. RavenDB Sharding (3):
    22 May 2015 - Adding a new shard to an existing cluster, splitting the shard
  4. Challenge (45):
    28 Apr 2015 - What is the meaning of this change?
  5. Interview question (2):
    30 Mar 2015 - fix the index
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats