Tuesday, February 28, 2006

 

Creational dependencies and attributes


True extensibility requires a mechanism to handle creational dependencies. Factories are a common design construct to handle those dependencies, but often they don't really remove dependencies: they just concentrate them in a single class.
In C++, thanks to the automatic creation of static objects, it is possible to have self-creating prototypes (or single-product factories), automatically registering themselves in a repository. This is a nice form of Product Trader, a pattern that is often mistaken for a "simple" factory.
In C#, static objects aren't created unless needed, so this approach can't be used. That means we have to resort to other language-specific constructs to have truly extensible software.
Reflection is probably the first idea coming to mind. In C#, creating an object having the class name (as a string) is trivial. However, we probably don't want the product (in the Product Trader terminology) name to be the class name. Therefore, some kind of indirection is needed. This indirection is often realized through a configuration file, which is a good solution in many cases, especially when products will be provided as external plug-ins.
In simpler cases, however, an external file is undesirable. It would be better to simply decorate methods (using .NET attributes) as being factories. A general-purpose, reusable product trader could then discover all the decorated method through reflection, and build a map of product factories. This could be done transparently, the first time the product trader is asked for a product.
I've written code for this reusable, attribute-based product trader under .NET 1.1, and it works like a snap. Now I'm considering building a better version in .NET 2, using generics to increase type safety. Curiously enough, it's not that trivial :-). Anyway, when I'll finish I'll probably write a short paper about it, and post the code here.

Sunday, February 26, 2006

 

Vanity Search

A popular sport :-) among authors is to do a vanity search (looking for themselves) on search engines, and see what comes up. Indeed, for a long time I've planned to create a "backlinks" page, where papers and pages referencing my works would appear, nicely classified according to their sources. Of course, that turned out to be a lot more work than I'm willing to do :-), so there will not be a backlinks section on my site anytime soon.
However, Google volunteered :-)) to do some work for me when they created Google Scholar to search scholarly papers, and Google Book Search to search inside books (although not so many books are indexed [yet]). So, here is the result of my little vanity search on those two services. Not quite extensive as a real backlinks page would be, but not so bad :-).
While speaking about vanity :-))), here is an IBM Patent referencing one of my articles (you have to scroll down to "Other References" to see it).

Friday, February 24, 2006

 

C++ Standards Committee Papers

A previous post generated a flurry of email about C++. The basic question was, is C++ "technologically dead"? Is anybody working on extending the language? Well, the ISO Working Group 21 is still alive. You can browse the C++ Standards Committee Papers and get a glimpse of what has been discussed in the past few years. Among them, the discussion on Concepts for C++0x is quite interesting for those playing with metaprogramming. There are a few more papers around on the same subject, most of them by Jaakko Jarvi.

Tuesday, February 14, 2006

 

Estimation and Probability Density

I've been playing around with a somewhat complex problem related with probability density for a long while now (see my previous post What I've seen and what I've got :-) and Running, Oxygen, Probability Density). In the end, it should allow me to create better probabilistic estimates (both more realistic and more accurate). Today, after a long hiatus, I've spared some time to play with that again and guess what, an extremely simple solution came up out of nowhere. It's also more mathematically sound than what I had before. Seems like I'll be willing to implement this one into a small tool :-). If (or when :-) I do, I'll probably make it freely available.

Monday, February 13, 2006

 

Corso Software Project Management

Ho finalmente messo online il programma del mio corso Software Project Management. Come si evince dal nome :-), il corso e' dedicato al PM di progetti software, che non sono progetti come gli altri.
Oltre al programma, trovate alcuni cenni al corso in un mio post di ottobre, ed alcuni cenni (ed altri riferimenti) ad argomenti comunque correlati in un post di novembre.

Sunday, February 12, 2006

 

Quotation of the day

Some tinkering in the past days brought back to my memory a quote from C.A.R. Hoare: "Here is a language so far ahead of its time, that it was not only an improvement on its predecessors, but also on nearly all its successors". It was about ALGOL 60, but being slightly younger :-)) I was thinking of something else.
Here are a few more quotes from Tony (who, for the few out there who don't know him, invented quicksort among other things).

 

Walking on sunshine...

It's still somewhat cold here, but not so much in the morning sun. So I took a walk on the beach, got a few pictures of seagulls flying around, and brought back home a couple artistic :-) pieces of wood carved by water...

Sunday, February 05, 2006

 

Type Inference in C#: No Trail Arguments Deduction

Like C++, C# does type inference when a generic function is called:
class Test
{
private static void f< T >( T p ) { }

public static void Main()
{
// explicit type argument
f< int >( 3 ) ;
// type inference
f( 3 ) ;
}
}
According to the C# Version 2.0 Specification, "The presence of type inference allows a more convenient syntax to be used for calling a generic method, and allows the programmer to avoid specifying redundant type information". All so true. Unfortunately, they didn't look close enough to what C++ can do, that is, trail argument deduction.

This is legal C++ :
template< class T1, class T2 > void f( T2 p2 )
{
}

int main()
{
f< double >( 3 ) ; // calls f< double, int >( 3 )
}
but this is not legal C# :
class Test
{
private static void f< T1, T2 >( T2 p ) { }

public static void Main()
{
f< double, int >( 3 ) ; // works
f< double >( 3 ) ; // error
}
}
Why would you want trail argument deduction? For the same reasons you want type inference: to get a more convenient syntax, and to avoid specifying redundant type information. (Of course, in real cases, f would make use of type T1 inside its body; I could definitely use something like that for my GUI rules library [see my post "C#: In search of language"]).
Overall my experience with C# is mixed. There is some good stuff in it. But as soon as you try to do something slightly more advanced, you're hitting a wall. It's so disappointing. Gotta do something about it :-)).

Friday, February 03, 2006

 

Work Smarter, Not Harder

It was a management mantra in the late '80s - early '90s, and as such, it has got a bit of a misnomer :-) among developers. I distinctly remember it being used even on the Dilbert strip (from the pointy hair manager, of course).
However, that was a good advice indeed. In the past two days I've been consulting on a data replication - sinchronization - fusion problem. There are a number of issues involved, including a legacy system with severe data quality problems (data is not really in a format that makes this kind of stuff easy, and changing structures is a difficult, costly, error-prone activity). Currently, deployment is quirky to say the least.
I contributed with a few good ideas, changing long, manual, error-prone procedures into short, automatic, safe procedures. I also brought back attention to the data quality issue, which was no longer consided part of the problem, trying to draw a roadmap to gradually move outside the quagmire. At the end, we had a short-to-long term stratey, consisting of six steps, each one bringing some improvement at a reasonable cost (and risk). I'm confident we will take the first 3 steps. Steps 4 to 6 may or may not see the light, depending on future business & technological issues (and on human factors as well :-).
All this required thinking outside the box. Weinberg, in his "precision listening" concept, told us to watch out for absolutes, like "this can't be done". Sure it can. We just need to find a way :-). Too often, we don't see a way because we're trapped by linear thinking. Still, we can spare ourselves a lot of hard work by finding creative solutions, requiring little manual coding. Actually, I don't believe in hard-work in programming. If we're working too hard (I mean long hours of pure coding, bug fixing, patching around fragile systems, etc) often we're not looking hard enough (or haven't been looking hard enough :-) for a better way to do the job. [Or we overpromised, either by lack of technical or managerial skills, but even there, often we've not been looking hard enough for a better way to get the job :-)]

This page is powered by Blogger. Isn't yours?