Re: Stevey and overengineering
- From: notzeb@xxxxxxxxx
- Date: Wed, 13 Feb 2008 09:27:08 -0800 (PST)
On Feb 13, 6:36 am, Jeff Lait <torespondisfut...@xxxxxxxxxxx> wrote:
You don't seem to have learned the lesson of the philosophy. The
"solution" isn't to compactify and remove white space until it fits on
a screen. That is like fulfilling a 5 page essay requirement by
tweaking the font size. It fulfills the text of the requirement while
violating the spirit.
The answer is, when you are faced with too long a function, to find a
way to factor out or simplify the function until it does fit on a
screen.
Generally, I try to separate into smaller functions first. The macro
thing is for things that I use a lot, and take up lots of space. Take
a look at the all shortest paths algorithm:
for (int i = 0; i < n; ++i) { // all shortest paths algorithm
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
if (distance[j][i] + distance[i][k] < distance[j][k]) {
distance[j][k] = distance[j][i] + distance[i][k];
}
}
}
}
I've used it so often that this is what I tend to write instead:
#define f(x,y) for (int x = 0; x < y; ++x)
f(i,n) f(j,n) f(k,n) if (distance[j][i] + distance[i][k] < distance[j]
[k]) distance[j][k] = distance[j][i] + distance[i][k]; // all
shortest paths algorithm
My code becomes full of little idioms like this (such as table driven
logic for moving up/down/left/right), which I recognize, but other
people don't. (YES, I KNOW THAT #define MACROS ARE EVIL. SO AM I. I
KILL C# PROGRAMMERS FOR PLEASURE.)
Even then, the rule should be taken with a heaping tablespoon of
salt. Some algorithms are naturally ugly and intractable. Splitting
them up along unnatural lines to fit a "one function one screen"
paradigm merely increases your LOC and maintance burden. And to
delete a comment to fit such a requirement? Unforgivable.
Keeping each function simple is meaningless if doing so results in
your program-as-a-whole becoming too complicated.
Of course, I tend to use 100 row screens now, so what constitutes one
screen is up for debate.
--
Jeff Lait
(POWDER:http://www.zincland.com/powder)
It isn't a hard and fast rule. But algorithms which force me to
violate it are very very rare, especially since I keep my text editor
as big as possible.
.
- Follow-Ups:
- Re: Stevey and overengineering
- From: Paul Donnelly
- Re: Stevey and overengineering
- References:
- Stevey and overengineering
- From: Radomir 'The Sheep' Dopieralski
- Re: Stevey and overengineering
- From: notzeb
- Re: Stevey and overengineering
- From: Jeff Lait
- Stevey and overengineering
- Prev by Date: Re: Stevey and overengineering
- Next by Date: Re: 7drl starting announcement
- Previous by thread: Re: Stevey and overengineering
- Next by thread: Re: Stevey and overengineering
- Index(es):
Relevant Pages
|