Feb 7 2009

Next on CodeGenWeek

Category: Code Generation | CodeGenWeek | TalkWareJonathan @ 04:33

Coming soon on TalkWare, it is another CodeGenWeek.

Now you may be aware, that TalkWare is the name of the PodCast show that I have started and you may also be aware of the Kent Beck interview. This is my first time doing podcasting and with all first time things, it is a learning experience. So I am starting out with a range of formats and interests and need your input to tell me what you want to hear on the show. Thank you, to a few of you who have sent me very supported emails already. It is much appreciated.

What is coming up on TalkWare?

CodeGenWeek II
This time, we are going to have 3 guests, coming to share their thoughts on Code Generation.
Once again if you have any questions, you wish me to pose to any or all of my guests, please send me an email and/or record and send me an mp3 of you asking the question.

We are going to be discussing Code Generation in today's current climate. Where will it go to next? What is the next generation going to look like?

Cyril Jandia lives in France, has a B.S. in Language Science and is a software developer interested in DSL's and OSLO.

Omer van Kloeten will be joining us from Israel. He has multiple projects on CodePlex, including Code Snippet Repository and CodeDom Patterns.

Oleg Sych, from Tampa Bay, Florida, is the creator of T4 Toolbox on CodePlex.

Tags: , , , ,

Feb 1 2009

TalkWare

Category: .NET | CodeGenWeek | Design | TalkWareJonathan @ 06:40

I have decided to create a podcast show, already available in iTunes, called TalkWare.

My very first guest is Kent Beck, so it should be a good start.




Coming Up on TalkWare , hosted by Jonathan Crossland.

Estimated Time: 6th February 2009

Extreme Programming with

Kent Beck

Kent Beck is the founder and director of Three Rivers Institute (TRI), and the creator of Extreme Programming.


Estimated Time: 13th February 2009

Code Generation with:

Omer van Kloeten, Oleg Synch and Cyril Jandia



Tags:

Jan 29 2009

CodeGen and Visual Studio Snippets

Category: .NET | CodeGenWeek | Design | DOTNET | FrameworksJonathan @ 03:36
Code Snippets in Visual Studio is a form of CodeGen.

You have a template and its injected into your editor. I modify these quite a bit, mainly because I like my properties to have fields with an underscore and named the same as the property:

Here is my Prop.snippet (found in Tools|Code Snippet Manager|C#)
It is a little different as this one matches the variable name with the property, puts the brackets how I want them and also puts my _CamelCasedField name.

Also now with Visual Studio.NET 2008, we have a Code Snippet Editor to make life easier.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
      <CodeSnippet Format="1.0.0">
            <Header>
                  <Title>prop</Title>
                  <Shortcut>prop</Shortcut>
                  <Description>Code snippet for an automatically implemented property</Description>
                  <Author>Microsoft Corporation</Author>
                  <SnippetTypes>
                        <SnippetType>Expansion</SnippetType>
                  </SnippetTypes>
            </Header>
            <Snippet>
                  <Declarations>
                        <Literal>
                              <ID>type</ID>
                              <ToolTip>Property type</ToolTip>
                              <Default>int</Default>
                        </Literal>
                        <Literal>
                              <ID>property</ID>
                              <ToolTip>Property name</ToolTip>
                              <Default>MyProperty</Default>
                        </Literal>
                  </Declarations>
                  <Code Language="csharp">
             <![CDATA[
private $type$ _$property$;

/// <summary>
/// 
/// </summary>
public $type$ $property$ 
{ 
  get
  {
    return _$property$;
  }
  set
  {
    _$property$ = value;
  }
}$end$]]>
                  </Code>
            </Snippet>
      </CodeSnippet>
</CodeSnippets>



Yeah, I know its longer, and some like the bracket on the top line {
}
like that, but thats the way I like it. Who can argue?
I know someone who still prefixes everything with str_, int_ and so on. We are all different.

Round Trip Engineering (RTE) for Code Snippets

I believe, the next generation of code snippets, and CodeGen as a whole, should have rte capabilities. using Code snippets as an example, when we embed a code snippet, in our code, it should always understand that it was/is a code snippet.
That way we could change the variable and have it change the expression in the code snippet. In fact this is simply refactoring, but keeping the Expression and code snippet metadata is an important step.

Tags: , ,

Jan 26 2009

An Even better Idea: Abstract the Code file from the Language

and the editor provides you with visualizations of the code file, which contains a base language, metadata and more contextual information.

The Web 2.0 of Code Editing?

Currently, and even our new tools, like OSLO, when its released, is and will be file based.
Now that in itself is fine, to keep in line with source control and other file based tools. But our Integrated Development Environments require a better, a whole new kind of Code Editor.

I believe that we need to create what I tentatively call ActiveEditors. An ActiveEditor is one which as described above surround code snippets, understands a lot more about Context and the code we write. In order to do that, it should build a Code Tree, Abstract Syntax tree -LIKE, Object Model, separating the FILE from the Editor.

This means that we open a FILE, but view an ActiveEditor, showing a generated “view” of the file.

The actual file and the contents could be XML, or MSIL, but what we see (via built in CodeGen), is c# or vb. So the actual code file needs not be in a particular language.

What does this do? It provides an abstraction that creates a dynamic representation of the code file, in your language. Have a look at the picture. The file could store c#, but it never directly puts the textual content of that file in the editor. Instead, it generates the code, from the model, built from the file, and pushes that into your editor. Based on a setting, the file could be MSIL, and your view could be C#, or any combination.



Now you could write an entire project in c#, but at anytime, switch to VB.NET, and it would never affect anything, because the compiler is compiling the actual file, not your Visual Display within your ActiveEditor that was created.

How would it help?

We could potentially store MetaData within the Code Tree, that would be excluded from viewing, although kept in the file. Your language choice and the code could still be generated as you are used to it. (think code-behind, where the sub document is the base language, which you can show/hide).
This new MetaData, would then actively describe the code so that Code Generation tools and the Editor can manipulate it for context, refactoring and other.


The next big thing? Coming to Visual Studio 10? is it too late ?

Imagine your Visual View of the code had toggle switches, to show/hide comments, show/hide regions, show/hide methods, show/hide classes - it would still be in the actual file, but not in your Visual Display. In the same way, I could switch my Visual Display to VB.NET to edit something, and then switch it to c# to edit something else.
Each developer on the team can view and edit in the language of their choice, it would not matter.
If a team of two was using vb.net, and then 3 more developer were brought on the team, they could continue in the same project in their own language, and it would not change anything.

Tags: , ,

Jan 26 2009

Code Snippets should have Context

"A revolution for editing code in .NET"

One of the most common Code Generation tools involve databases and are called O/R Mappers. This is going to change with the likes of OSLO and DSL's. But historically, Object-Relational Mappers have been the predominant force in CodeGen and they are usually CRUD based. (create, read, update delete) They come in various flavors and I have not used one before now that I still use today. That is, I could never find one that gives me enough freedom to design and implement my project the way I need to, and very quickly I leave them behind. Most have limitations, and don't actually do what it says on the tin.

For example, more than most try to sell you the idea, that it removes the database from you, you can talk to it via the objects, however, I have never found one, that I have not had to go “under-the-hood” to modify a Stored procedure or some aspect of the generated code. So if you do choose to use an O/R mapper, you must be sure, that you can make changes deeper down in the generated code. CodeGen is not good enough yet, to be a black-box tool

But thats one flavor of CodeGen. Other flavors involve Wrappers, Code Snippets, Designer Tools, and general utilities that can generate entire projects and/or layers and everything in between. This post, I would like to concentrate on Visual Studio .NET Code snippets.
Visual Studio.NET Code Snippets currently have a few problems. No editing tool, no built-in way of designing snippets easily. It is one way. It injects the snippet into the Editor and when done, forgets everything about the Expressions. The Refactoring Engine and the Snippet are not friends. They do not communicate.

Code Snippets

Lisa Feigenbaum - Code Snippets in Visual Studio
Ken Levy takes his camcorder over to interview Lisa Feigenbaum and get a look at the new Code Snippets feature in Visual Studio.

Code Snippets Solution applied to all code files, LIVE

A Code Snippet should not “lose” knowledge of the parameters/expressions. Anytime, I click on an Expression (example: PropertyName) that was inserted with a Code Snippet or NOT, it should still understand it. Refactoring would be automatic. Why should it be two separate tasks? Have you ever changed a Property Name, without wanting to change where its referenced?

Consider adding the “prop” Code Snippet. It asks you for Field and PropertyName. Now I believe that this is “kind-of” there for Visual Studio 2010.

But the key missing ingredient, is having our code “always aware”, especially of “expressions”. If you click on a Field it should highlight and as you make the rename change, it should alter your references automatically.

But a Code Snippet is only a small utility, but I wanted to use it as a small example of how code snippets need to keep context and knowledge of its injection, and in the same way Code generation in general has to be able to do this too.

If you generate a class for my person table in a database, and I change the class name, it should, by means of Code Snippet Expressions, Refactoring Engine, understand and align the change across to the database and the the code that references it.

Tags: ,

Jan 26 2009

Whats being said about CodeGen on the NET

Category: Code Generation | CodeGenWeekJonathan @ 10:54

Code Generation Network


CodeGeneration.NET | CodeGeneration.NET FORUM

Listen to CodeGeneration NETWORK - conference of 2007

Episode 1: UML vs DSL: A False Dichotomy?
Includes Steve Cook's emphatic view.

I absolutely love it. Truth with conviction.


Episode 2: The future of


Download the Episodes

Tags:

Jan 25 2009

Code Generation Tools

Category: c# | CodeGenWeek | Design | Development Tools | DOTNETJonathan @ 18:11

All your code are belong to us

Send me a list of your favorites and I will compile a list of them on the website. For now, here are some ad-hoc random ones to perhaps try out. if you know anything about any of these, let me know what you think of them.

http://www.codesmithtools.com/
http://www.ibm.com/developerworks/rational/library/2949.html http://www.tangiblearchitect.net/visual-studio/
http://www.raboof.com/Projects/VsCodeGeneratorShim/
http://www.microsoft.com/downloads/details.aspx?familyid=89e6b1e5-f66c-4a4d-933b-46222bb01eb0&displaylang=en
http://www.jetbrains.com/resharper/
http://www.oracle.com/technology/tech/dotnet/tools/index.html
http://www.mygenerationsoftware.com/portal/default.aspx
http://www.codeplex.com/jeremydotnet
http://www.altova.com/solutions/code-generation-tools.html
http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/
http://www.eurowisesoft.com/
http://www.dotnetsavant.com/
http://www.adonetexpress.com/
http://www.bluage.com/
http://www.razorsource.com/SourceCutter/Overview.aspx
http://www.developerinabox.com/
http://www.innoq.com/iqgen/index.html
http://www.sd.nl/software/
http://www.radsoftware.com.au/codegenerator/

Steve Hansen sent me a link to m-Power

Tags:

Jan 25 2009

Automatic CodeGen from Design Patterns


An old paper, but worth a read if you are interested in Patterns and CodeGen

Automatic Code Generation from Design Patterns
Frank Budinsky, Marilyn Finnie, Patsy Yu, Toronto Software Laboratory, John Vlissides, T.J. Watson, Research Center

Tags:

Jan 24 2009

One important reason why your Code Generation tool does not get used

Category: .NET | c# | CodeGenWeek | Design | Development Tools | DOTNET | TalkWareJonathan @ 04:20

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.


Hi, after you read this post, don't miss my Interview with Kent Beck coming soon.


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: , , , , , ,