You say “m_” , I say “_”, lets call the whole thing off!
Code Generation has one tremendous problem.
We dont like the way the code looks.
Majority of the code spat out, is, if not badly formatted, then not formatted the way I like.
and it does not change the formatting when you don't like the way it was generated or you have to fiddle with codegen settings (which for every tool is different). There are other reasons of course why codegen is not 100% accepted, like you cannot edit the generated code. If you do, it mostly quickly gets overwritten by the next run of the codegen.
But this is already being addressed (a little) by partial classes in .NET, BUT there is still no answer for the formatting problem.
AND let's face it, if any
helpful and usable code was generated and it
looked like our own code, we would be more inclined to use it.
Introducing JIT Code Formatting
it is not altering the actual layout of the file, it's just the "view" of it.
Just in time code formatting is the process of changing the formatting of any code, no matter how it looks on disk, "to the way you want it".
Imagine I send you a small project, you open it and find I have prefixed all fields with an underscore. Your development tool, understanding the semantics and changes the variable prefixes for you when you open it. It formats out the code the way you like it and likewise, when I open it, its changes it the way I like it. It is not altering the actual layout of the file, it's just the "view" of it.
Checking the source into Source Control is not a problem, as it would convert it to a consistent format for before checking in.
For example: In Visual Studio, you would have settings for how you want your formatting. The formatting can be set and pushed to all developers and each developer can have the formatting the way they need and like it.
The JIT-CodeGen engine translates the code to your settings.
Now who wants to write this?
SideBar
Built-in CodeGen in Visual Studio
The T4 templates are an example of a powerful feature in Visual Studio, incorporating code generation, however it will generate the code based on the developers ideas, conventions and standards. This is one of the problems of codegen adoption.
However T4 from Visual Studio is still very cool. Read a little intro by
Rob and from
Scott
There are many new features coming in
Visual Studio 2010, but where is this feature? There is still time, to add it in.
Listen Now:
Download
CodeGenWeekPodCast1.mp3 (7.55 mb)
iTunes
Copy this address: http://www.jonathancrossland.com/syndication.axd and paste it into iTunes.
Tags: codegen, code generation, templates, t4, visual studio, code formatting, syntax highlighting