June 2005 - Posts
JetBrains opened an EAP for its Meta Programming System.
I'm downloading it, I'll post my impressions after I find some time to play with it.
We are currently using two code-generation techniques. For the data access and business logic layers, we have a code generator written in Prolog. For the layers on top of that one (i.e, a WS layer or a UI layer) we started using CodeDom and then we switched to an ASP.NET-like template-based code generator engine.
The main reason to switch from CodeDom to templates was that we wanted our customers to customize them, and customizing CodeDOM code is very difficult, while customizing a template is quite easy. From our point of view, it's also easy to write templates, even if it means that we need to maintain two sets of them, one for C# and another for VB.NET.
The main issue with template-based code generators is that it's quite difficult to have a 'clean' set of templates. For anything but the simplest stuff, templates are spaghetti code. They are hard to read and difficult to modularize, even with help of the template editors. This is much better with CodeDom, as you can use OO techniques to design your code generator.
Additionally, using templates, keeping the code generated clean is also a challenge. You usually need to decide if you prefer to have cleaner templates or cleaner generated code. If your main development artifact is the template, then you could decide that is better to have a cleaner template. However, if the people using the generated code tend to read it, try to understand it, and evaluate your code-generation tools depending on it, you could prefer to have cleaner generated code.
For example, in DeKlarit you can write things like:
ModifiedDate = System.DateTime.Today if update or insert;
CreatedDate = System.DateTime.Today if insert;
MyNamespace.MyMethod.AddRelatedRecord(CustomerId, CustomerName) on AfterInsert;
These rules are then generated in methods like:
public void AfterInsertRules()
{
MyNamespace.MyMethod.AddRelatedRecord(row.CustomerId, row.CustomerName);
}
and invoked in another methods like:
public void Insert()
{
// Do something here..
AfterInsertRules();
}
This happens with the 'AfterInsert', the 'AfterUpdate', 'AfterDelete', etc.
If we are generating code using templates, we can generate that code in several ways. One is to write something like:
<% if (ListOfAfterInsertRules.Length > 0)
{ %>
public void AfterInsertRules()
{
<% PrintListOfRules(); %>
}
<% } %>
and before calling the method, write:
public void Insert()
{
// Do something here..
<% if (ListOfAfterInsertRules.Length > 0)
{ %>
AfterInsertRules();
<% } %>
}
If we do it this way, then the generated code will be cleaner, and the 'AfterInsertRules' method won't be generated or called when there are no rules to execute.
If I want to keep the template code cleaner, then I could write:
public void AfterInsertRules()
{
<% PrintListOfRules(); %>
}
public void Insert()
{
// Do something here..
AfterInsertRules();
}
In this case, if there are no rules to trigger, my generated code will have an empty method and a call to an empty method, so my generated code will look worse.
You could need to make this decision if you are using a CodeDom generator or a Template-based generator.
The interesting thing is that if you are using a CodeDom-like approach is that before writing the DOM to the source file, you can refactor it...
This means that as far as you don't touch the public interface, you can do whatever you want with it the DOM. For example, you can look for empty methods, and remove them together with their calls. You can find variables that are not used and remove them. You can find unreacheable code and delete it. You can find member variables that are only used in one method and define them as local to that method.
Some of these changes will probably have no important impact in the runtime performance of the application, but will make the generated code look much better, and you can also keep your code-generation code much cleaner.
One of the main reasons why we work with Prolog is that it's an easy (OK, easy if you know/like Prolog ;) way to have a CodeDom-like generator without requiring us to use typed language for it, so creating a DOM for the code is just creating a complex list. Refactoring the code is just processing that list and transforming it.
OK, I'm out of Orlando.
I hated the weather, but loved the show.
I think there were more developers than last year, probably because VS2005 is around the corner.
Yesterday I attended Scott's presentation on code generation, which was repeated at a time when the Exhibit Hall was closed, so I could attend. They did pretty cool stuff with code-generation. After seeing presentation I adopted SlickRun. It rocks.
After that I went to the 'Influencer Party' and spent a while talking to Gregor Hohpe, without knowing that he was him ;), and I got his cool Thoughtworks card that I'll attach to the book ;).
On the morning, I found Don Box in a surprise presentation (podcast here, people laughs because he previously defined 'model' as 'a representation of an ideal'), and as usual it was quite fun. He talked about models, model driven development, the OMG metametamodels, etc.. Now each time I say 'metadata' I remember him and try to change the word by 'information'.
Today was also a fun day, I made DeKlarit demos to Harry Pierson, Scott Hanselmann, John Lam and Daniel Cazzullino, and I got a cool PluralSight t-shirt. Not bad ;)
I've just found out by browsing the TechEd powerpoints that there's a new 'Report Control' in .NET 2.0, which can be used in Windows Forms and ASP.NET applications (so they are actually two controls ;) ), that don't require (but support) Reporting Services.
This means you can load a DataSet (or a collection of simple objects), and bind it to a report.
It's kind of what we have with Crystal Reports, but that instead of having a binary format for the reports, it's XML, which makes it very easy for us code-generation-junkies to create them.
Just to wrap up this post, there is no way to send a SqlXml type as binary to the server. It's always sent as text. You can receive it as binary, but not send it.
IMHO, this kind of sucks, but that's the way it is.
I posted a suggestion in the feedback center, but it won't be changed for SQL2005.
There's a new website focused in sharing GAT artifacts.
I found about it in kzu's t-shirt ;)
DeKlarit has a booth in TechEd (the 4th year in a row, booth #850 this time), and we are showcasing a DeKlarit 4.0 CTP that runs in Visual Studio 2005.
It still does not take advantage of most of the new .NET 2.0 feature, but it generates partial classes, uses the new .NET DataSet serialization features, and it includes one new feature that is causing a lot of impact, which is SQLCLR stored procedures.
Let's say you want to save an Invoice, and before saving it you need to check the Customer's balance, the Product's inventory, and if everything is OK, save the Invoice header, update the Customer Balance, update the Item inventory, and save the Invoice line.
Doing this with a single roundtrip to the database is not possible using dynamic SQL. Doing it with T-SQL stored procedures is also difficult because there's no way to send the whole Invoice to the stored proc. If you write T-SQL stored procedures with business logic, you could have one stored procedure to save the header and check the customer balance, and another to check the item inventory, decrease it, and save the lines. If you have '1-sql-sentence' T-SQL stored procedures, then you will need one to check the customer balance, another to save the header, other to check the inventory, another to update it, and another to insert the invoice line. This goes in the same direction as the 'databases as services' approach.
With CLR stored procedures, you can send the whole Invoice as a single data structure and do everything in the server. This is what we are enabling with DeKlarit 4.0. In the current version we are sending a diffgram, but we are testing other alternatives. This makes me less worried about not having support for batching outside of the SqlDataAdapters ;)
Some people will like it, other people won't, but I think it's very important to have this option.
I liked it. It was fun, and we finally know the VS 2005 and SQL 2005 release date.
He also announced that Reporting Services will be available for SQLExpress, which means there's no reason to not to use it. Report Builder will be in Standard Edition, which will also make its adoption faster.
The RFID stuff was also quite cool.
DeKlarit has been a VSIP partner since 2002. At that time the program name was 'Visual Studio Integration Program'. Some time later, it changed to 'Visual Studio Industry Partner'.
Back in 2002 there was only one type of membership, but when they opened it, they created 4 types. We are in the 'Premier Partner' category.
Being part of the VSIP program always gave us marketing opportunities, like the ones described in the website, the chance to attend to Dev Labs in Redmond focused in VS integration, and the ability to have direct access to the VS team. We don't abuse of the VS people, but they always help us a lot when we don't see the light at the end of the tunnel. All of the VSIP team, the marketing and the technical people, is very friendly and willing to help.
This year the VSIP Marketing team did a great job in TechEd. For being part of the program, we had the chance to do two presentations in the TechEd Theater (tomorrow is the second one), and we got into a Visual Studio and SQL Server Partners co-marketing activity, in which you need to visit several partner booths, and get a 'paper CD' that you put in a neat metal CD case, and when you get 5 paper CDs, you get into a daily raffle of a SmartPhone. They also arranged some interviews with the press.
If you are not part of the VSIP Permier Partner category, think about it. It's very good, and it's worth the money. If you are part of it, then having a booth in a MS Event is a very good way to take advantage of it.
OK. It's late, I'm tired, but it's the time to say something about TechEd.
The Ballmer keynote wasn't very interesting for me. The 'developers developers developers' motto was not present. I can understand it as TechEd is not a developers-only conference, but it was quite boring.
A couple of years ago I made TechEd and JavaOne in a row, and it was fun to see how in JavaOne's keynotes they spent time talking about Microsoft, and in TechEd's keynotes, they barely mentioned the competition. This one was different. It started with some ironic comments about Apple and Google, and MS competitors were mentioned several times during the keynote. The same happened in Paul Flessner's one, but not as often.
Another fun thing was to see that the code name for the next Office version is '12'. There was a time where the version number was 12 and the code name was 'aweirdname', but now it's the other way around.
More Posts