Monday, October 30, 2006

Friday, May 12, 2006

class or struct...

In C# the struct keyword doesn't mean the same thing as in C or C++. First of all functions and properties may be associated with it. Next it's treated as a base type. When I say a base type I refer to int, long etc. These types are copied when sent as arguments instead of a pointer to their location.
This means that struct's are not constructed in the same way as classes and are treated as a base type. This also means that the rules that apply to boxing and unboxing basic types also apply to these types.
From this information we can descern that structs should only be used in extremely rare cases. An example would be a map point or perhaps a complex number structure. This would mean that we have a new type that we wish to be indistinguishable to others, that can be used the same as int or a long.

Any code that contains structs without strong justification of it's usage, along with penalties of using such a construct, shouldn't be allowed to use them. If in any doubt a class should be used instead of a struct.

Monday, February 13, 2006

Default Arguments (to use or not to use)...

The case of whether default arguments should be used or instead function overloading should be is a topic that isn't so hotly debated anymore. It appears to be a rarer and rarer occurance that default arguments should/can be used.
At least for .NET (not an issue in C#) default arguments should not be used. It's simply a case of when code is compiled against a library the default value is placed in the calling binary. Meaning if a library changes it's default value, the value won't be changed in an assembly using that library until it's recompiled.

Sunday, February 12, 2006

Threading and CORBA

A while back CORBA was all the rage, especially as a means of replacing DCOM. CORBA was to allow seemless integration between machines to share load and allow programs to span multiple machines. Now the only place that really still sees such protocols are those where communication speed between machines is necessary. Protocols such as XML-RPC and SOAP now tend to replace them. These are better simply since they can be more easily debugged by using packet dumps.

I ran across an interesting issue, the other week. One of the guys at work palmed off a problem to me that wasn't mine. The logs showed that a call back was being called out of order and that the program was hanging permantly.
Basically the problem was extremely simple, though to see the behaviour it wasn't. Imagine you have a routine call that is expected to give asynchronous call backs. This means that the callbacks may be returned in any order (i.e. not the other they occurred in and sometimes before the method call has returned). The solution is to simply lock the method so that it can return any required information and then allow the callbacks to run.

The problem is of course since the callbacks occurred out of order, the program was done so that the if the second callback came before the first then it would wait. This was implemented using a changing a thread into a suspend state. Of course this meant that this thread was now unable to complete, and preventing the first callback, or any future callbacks from occurring.

The code has now simply been changed to accumilate all the information from both callbacks and then process it approprately once it's all accumilated. Simple in it's simplicity without any need to worry about threads and their states.

Tuesday, January 24, 2006

The importance of contextual metadata (part 2)

Now as we advance in the techniques that may be used for discovering metadata, through better discovery, improvements have been made so that metadata may appear in a document in a contextual location.

For examply by using the structure of paragraph and metadata recognition routines it would be possible to do something like the following.

"John and Sara searched for kransky at their local supermarket in Sydney."
becomes
"<paragraph><sentence><name>John</name> and <name>Sara</name> searched for <food>kransky</food> at their local supermarket in <location>Sydney</location>.</sentence></paragraph>"

I've dumbed it down so that nothing conflicts. Now the information now has a context, so while it's still possible to drill down on name (it'd have to be extracted to seperate field like in the previous post). Now that the information is constructed in such a fashion it's now possible to search for a sentence or paragraph that contains a food and a person. Or for a sentence that contains a name John and a location. Of course the ability to search such marked up data relies on you having either a very good search engine at your disposal or the willingness to write one. ;-)

Monday, January 02, 2006

Harriet's Damage




Poor harriet has taken a beating since I first got her. Her trouble started when she lost her fairing, in her first accident. A broken clutch lever and broken indicators were a result of this. I got to spend a few weeks not being able to breath without pain from this little accident.

The later photos show harriet with a modified front. Less cosmetic and more serious damage was done this time. A good reason not to trust cars, especially P platers to give way at a give way sign. The old girl is going in on Tuesday, and hopefully we'll be able to get her up and beautiful again.

I have a new helmet and gear ready to go, so all I'm missing is the bike, for me to be ready... Hopefully my caution, more experience and a little bit of luck will allow me to avoid further incidents to myself and Harriet.