Advertisement Jump to content
Sign in to follow this  
DejaimeNeto

"Oh God, Who Wrote This?", "You Did", "Wait? I wrote This?"

This topic is 1794 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Yeah, that's really common. But in my college they taught me pretty well this kind of best practices.

Of course, by then I only thought that was unnecessary and overrated, and only got to understand what I was taught long after that...

 

This one I knew was going to be a problem when I typed the r in for... "I'll make it like this anyway, who's going to read this anyway?", and ta-da! I probably spent 40 minutes debugging this loop...

Guess I'll start to do what needs to be done, it is not like I did this out of inexperience, neglect would be the word!

 

And I even have a KISS T-shirt... (I really do)

Share this post


Link to post
Share on other sites

Yeah, that's really common. But in my college they taught me pretty well this kind of best practices.

Of course, by then I only thought that was unnecessary and overrated, and only got to understand what I was taught long after that...

 

This one I knew was going to be a problem when I typed the r in for... "I'll make it like this anyway, who's going to read this anyway?", and ta-da! I probably spent 40 minutes debugging this loop...

Guess I'll start to do what needs to be done, it is not like I did this out of inexperience, neglect would be the word!

 

And I even have a KISS T-shirt... (I really do)

 

My university has horrible coding classes. I took three of them: Intro to C, and Comp. Sci. 1 & 2. 

 

In my last class, I had a teacher who used inconsistent namings, strange variable names, passed vectors by value like a baus, didn't bother deleting allocated memory, and wrote a crap ton of comments in the style "int add(int, int); // Adds two integers," some of which I found to be lying about their return values.

 

Currently, and this is about 4 years now since I started programming, I am quite anal about consistently structuring my code and focus quite about on making sure it's as straightforward as I can make it. Of course, everyone says I'm over reacting, but I've seen the effects of not caring, and I know how big of a benefit clarity and consistency carry.

Share this post


Link to post
Share on other sites


Of course, everyone says I'm over reacting, but I've seen the effects of not caring, and I know how big of a benefit clarity and consistency carry.

There is definitely a balance to be struck there. Ideally you are able to write both sorts of code: the throwaway prototype you needed yesterday, and the carefully structured (and tested) code that is headed for production.

Share this post


Link to post
Share on other sites

 


Of course, everyone says I'm over reacting, but I've seen the effects of not caring, and I know how big of a benefit clarity and consistency carry.

There is definitely a balance to be struck there. Ideally you are able to write both sorts of code: the throwaway prototype you needed yesterday, and the carefully structured (and tested) code that is headed for production.

 

 

I agree that perhaps it's unnecessary to structure code with utmost care when prototyping, but even if prototyping I feel like there's still things one could do to write cleaner, albeit throwaway, code.

 

The poster in this thread is a prime example: http://www.gamedev.net/topic/652538-pathfinding-behaviour/

 

I wouldn't put code like this in production, but I would certainly not write it as throwaway either. I managed to fix an error in his adding function merely by giving the variables proper names, which, if he had done in the first place, he would have noticed the glaring logical error. 

Share this post


Link to post
Share on other sites

laugh.png That is indeed horrible. Way too many parenthesis to keep track of what's inside what (and some are entirely unnecessary). Try separating the function arguments onto separate lines so you can see them, and separate out some of the repeating ugly things into variables.

for (totalMatches = 1; totalMatches <= (pIt)->first->getSize(); ++totalMatches)
{
    int eventIndex = eventLog.size()-totalMatches;
    const Event *event = eventLog[eventIndex];
    if (!(pIt)->first->compare(
         (pIt)->first->getSize()-totalMatches,
         event->getType(),
         translator->translate(event->getKeyCode()),
         getTimeDiff(eventIndex)))
         break;
}

Or better yet, put the whole thing in a function that returns true at the end, and have the if statement return false instead of breaking.

Share this post


Link to post
Share on other sites

laugh.png That is indeed horrible. Way too many parenthesis to keep track of what's inside what (and some are entirely unnecessary). Try separating the function arguments onto separate lines so you can see them, and separate out some of the repeating ugly things into variables.

for (totalMatches = 1; totalMatches <= (pIt)->first->getSize(); ++totalMatches)
{
    int eventIndex = eventLog.size()-totalMatches;
    const Event *event = eventLog[eventIndex];
    if (!(pIt)->first->compare(
         (pIt)->first->getSize()-totalMatches,
         event->getType(),
         translator->translate(event->getKeyCode()),
         getTimeDiff(eventIndex)))
         break;
}

Or better yet, put the whole thing in a function that returns true at the end, and have the if statement return false instead of breaking.

 

variables  for   (pIt)->first  and  (pIt)->first->getSize()   outside  loop  to simplify even more

 

Im trying to remember when I just started using that kind of simplification and pre-optimization automatically

Share this post


Link to post
Share on other sites

Way too many parenthesis to keep track of what's inside what (and some are entirely unnecessary).

 

Parenthesis are never unnecessary as long as they increase clarity, in my opinion.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!