From: Brendan Murphy <[EMAIL PROTECTED]>
Date: Wed, 2 Aug 2006 13:03:30 -0500
Joe wrote:
On Aug 02, 2006, at 11:05 UTC, Theodore H. Smith wrote:
The thing I don't understand that no one mentioned, not even the
article, is that fast code is usually maintainable code and code
that's quicker to write.
That's because less code = faster code. less code = quicker to
write and maintain.
Though Theo's assertion is not correct in the context in which he
presents it,
Actually, it is.
Because I said "usually". Not "always".
Here's a great example. Some project I've been working on recently
does a lot of this kind of thing:
if (ItemListArray[ItemListArray[GetSelectedIndex()].Parent].Name ==
"Fred") {
ItemListArray[ItemListArray[GetSelectedIndex()].Parent].Type = Maybe;
ItemListArray[ItemListArray[GetSelectedIndex()].Parent].Class = This;
ItemListArray[ItemListArray[GetSelectedIndex()].Parent].Thing = That;
}
etc etc etc.
It's not my code, which is why it's written like that.
Now, I would do it like this:
int i = GetSelectedIndex();
Item* item = &ItemListArray[i];
Item* parent = &ItemListArray[item->Parent];
if (item->Name == "Fred") {
item->Type = Maybe;
item->Class = This;
item->Thing = That;
}
As you can see: Less code = faster code.
Basically what I'm talking about is invariant code. Most coders don't
realise just how much invariant code there is in their code. I have a
good eye for that sort of thing :)
--
http://elfdata.com/plugin/
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>