As some of you may know, a huge part of the C# sources for db4o.net are generated from the Java version. This is possible because of the similarities of the two plaftorms, and of the two languages. So we have a converter, that takes care of translating the Java sources, to plain C# sources. So far, if the code we generated was readable by the C# compiler, it was a little harder to read for human eyes.
Let's take a small example. So, in the Java class ClassMetadata, we have this code:
public QCandidate readSubCandidate(MarshallerFamily mf, Buffer reader, QCandidates candidates, boolean withIndirection) {
int id = reader.readInt();
if (id == 0) {
return null;
}
return new QCandidate(candidates, null, id, true);
}
And here is the C# that was generated before:
public virtual Db4objects.Db4o.Internal.Query.Processor.QCandidate ReadSubCandidate
(Db4objects.Db4o.Internal.Marshall.MarshallerFamily mf, Db4objects.Db4o.Internal.Buffer
reader, Db4objects.Db4o.Internal.Query.Processor.QCandidates candidates, bool withIndirection
)
{
int id = reader.ReadInt();
if (id == 0)
{
return null;
}
return new Db4objects.Db4o.Internal.Query.Processor.QCandidate(candidates, null,
id, true);
}
If this is perfectly valid C#, it's not always easy to read, because every type is fully qualified.
But now, with the new improvements to our converter, we will organize the imports for every C# source file:
using Db4objects.Db4o.Internal;
using Db4objects.Db4o.Internal.Marshall;
using Db4objects.Db4o.Internal.Query.Processor;
// ...
public virtual QCandidate ReadSubCandidate(MarshallerFamily mf, Buffer
reader, QCandidates candidates, bool withIndirection)
{
int id = reader.ReadInt();
if (id == 0)
{
return null;
}
return new QCandidate(candidates, null, id, true);
}
This is still perfectly valid C#, but at least, it's much more readable. This is a little example, but imagine it applied to the thousands of thousands of line of code in db4o. I hope it will help those of you who are using the C# sources of db4o, and sometimes have to debug an issue that may have its root in db4o.
Now that it is done, how would you like we to improve the .net version of db4o?
-
Posted by Anonymous on 3/20/2010 6:41 PM
Welcome to the May Newsletter! 6.2.501 adds Committed Callbacks and Pushed Updates, improves C# readability
-
Posted by ErikNRC on 3/20/2010 6:41 PM
Is this converter tool open source as well? Amazing work. I had no idea that the C# sources were converted.
-
Posted by Adriano Verona on 3/20/2010 6:41 PM
Responding to ErikNRC:
By the time JB posted this our converter was not open source but (as you may already know) it is!!
It is called Sharpen.
You can read more here (http://developer.db4o.com/blogs/product_news/archive/2008/05/21/sharpen-your-java-app-now-java-to-c-converter-released-as-free-software.aspx).
Have fun!
Adriano
Loading, please waiting...