* Posts by Juha-Matti Myllylä

1 publicly visible post • joined 4 Dec 2007

Bloody code!

Juha-Matti Myllylä
Alien

@challenge

Hi,

Here's one simple pseudo-code challenge.

//==================================================

// Finds object from a universe.

// Return: Coordinate of object if object was found.

// If object is not found RL_NOT_FOUND is returned.

// Constraints: Given universe and object id exists.

===================================================

rlCoordinate FindObject( rlUniverse* aUniverse, rlObjectId* aId )

{

if ( !aUniverse ) raise some exception.

if ( !aId ) raise some other exception

for ( int x = 0; x < UNIVERSE_X_SIZE; x++ )

for ( int y = 0; y < UNIVERSE_Y_SIZE; y++ )

for ( int z = 0; z < UNIVERSE_Z_SIZE; z++ )

if ( aUniverse->FindObjectAt( aId, x, y, z )

return rlCoordinate( x, y, z );

return RL_NOT_FOUND; // maybe it's in other universe ;-)

}

@others:

I think in principal if you find multiple exits, break, continue, single exit, exceptions, etc too complicated you're in the wrong industry. Also not seeing some exit points sounds like u need better glasses, power on you're monitor or something like that.

Break, continue, goto, exceptions as well as multiple exits were all made for purpose and need. They all got their places and shouldn't be avoided by some stupid conventions. Somebody says developers not smart enough to use them properly is the source of problems. I'd say yes and no; simply: don't hire guys who can't do good code because they're causing problems and by hiring them you're actually the one causing problems.