Thread: Beginner coder
View Single Post
Old 11-9-2014, 12:46 AM   #16
shenjoku
Wubalubadubdub
FFR Veteran
 
shenjoku's Avatar
 
Join Date: May 2005
Age: 36
Posts: 1,697
Default Re: Beginner coder

Building off of what Zageron mentioned, one super important thing you need to learn is how to name member variables differently from parameters and other temp variables. If you can't immediately tell if a variable is a member just by the name then you need to rethink your naming convention. I've run in to way too many problems due to poor naming conventions.

For example in your class sample:
Code:
class
int num;
Make it m_num or something similar to make it very obvious that it's a member and not just a local temp variable. That way if you have a function that takes in a number that you want to call num you won't be confused as hell trying to figure out which num is the member and which is the input parameter. For example, try to guess what happens in this situation:

Code:
class SomeClass
{
    int num;

    void SomeFunc(int num)
    {
        num = num;
    }
};
Sure you could do this.num = num, but even that is kinda ugly. Do you really want to have to remember to prefix every member with "this."? If you forget then you'll completely screw yourself and have to hunt down a really hard to find bug.
__________________
boop

Last edited by shenjoku; 11-9-2014 at 12:47 AM..
shenjoku is offline   Reply With Quote