Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How would you space this code block?

Name: Anonymous 2011-04-28 15:54


if (    pokemon != getSelectedPokemon() // lorem ipsum dolor sit amet
        || !pokemon->health // lorem ipsum dolor sit amet
        || pokemon->health < MIN_HEALTH // lorem ipsum dolor sit amet
        || pokemon->health >= MAX_HEALTH // lorem ipsum dolor sit amet
        ) {
    // lorem ipsum dolor sit amet
    this->remove(pokemon);
    abort();
}

Name: Anonymous 2011-04-28 18:36


if ( (pokemon != getSelectedPokemon())
    || (pokemon->health != 0)
    || (pokemon->health < MIN_HEALTH)
    || (pokemon->health >= MAX_HEALTH) ) {
    remove(pokemon);
    abort();
}


Like that. Note the removal of comments (comments for fucking everything is retarded and for amateurs). I also removed the explicit use of this when calling remove, fucking redundant. I also added extra parentheses to convey intent with the various conditions. Note that if MIN_HEALTH is always greater than zero, you can get rid of the explicit check to ensure health is not equal to zero.

If you really wanted to clean it up to be well-factored and self-commenting, you could create some private inline member functions.


inline bool isNotSelected(Pokemon* pokemon) {
     return (pokemon != getSelectedPokemon());
}

inline bool isDead(Pokemon* pokemon) {
    return (pokemon->health < MIN_HEALTH) || (pokemon->health >= MAX_HEALTH);
}

...

if (isNotSelected(pokemon) || isDead(pokemon)) {
    remove(pokemon);
    abort();
}


Note how that really cleans up the code and is much more self-commenting, without the need for actual comments. That's the ENTERPRISE way to factor code.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List