Not really a paradigm shift, but fixing my kludgy start. I've gone down the very non-OO approach of large switch statements to control flow:
switch (node.Name)
{
case "BinaryProcessor":
m_Blocks.Add (new Processors.BinaryProcessor());
break;
case "Parser":
m_Blocks.Add (new Parsers.Parser());
break;
case "Processor":
m_Blocks.Add (new Processors.Processor());
break;
//...
}
This thing of beauty had a fraternal twin elsewhere in the code:
object curData = ...;
string str;
byte[] bytes;
if (block is Parsers.IParser)
{
((Parsers.IParser)block).Parse ((byte[])curData, out str);
curData = str;
}
else if (block is Renderers.IRenderer)
{
((Renderers.IRenderer)block).Render ((string)curData, out bytes);
curData = bytes;
}
else if (block is Processors.IBinaryProcessor)
{
((Processors.IBinaryProcessor)block).Process ((byte[])curData, out bytes);
curData = bytes;
}
//...
Eeeewwww. Even as I was typing this I was shaking my head. You know how it goes though. First it's just 1 case or if just to make sure you don't slip in something nasty. Then it becomes 2 -- it's soo much easier than OO-ing the code. Laziness kicks in and Shazam! you end up with spaghetti. Just today I found myself seeing if unions were supported in .NET which finally snapped me out of it.
It's now time to do this properly.
I have to admit it was somewhat nostalgic cutting "university-code" again. All I need is to sprinkle a few printf(""); here and there to "make it work".
Thursday, September 11, 2003
Paradigm shift
Posted by BigEasy at 9/11/2003 09:50:00 PM 0 comments
Some useful tools
I just found some very useful tools that I figure I should share. In truth I can't take credit for finding any of them on my own as I just grabbed them from the sources indicated below, but here they are anyway:
Posted by BigEasy at 9/11/2003 09:23:00 PM 0 comments
Subscribe to:
Posts (Atom)