Beginner coder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • #16
    Wubalubadubdub
    shenjoku
    • May 2005
    • 1734

    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.
    Last edited by shenjoku; 11-9-2014, 12:47 AM.
    boop

    Comment

    • #17
      Spun a twirly fruitcake,
      FFR Simfile Author
      SKG_Scintill
      • Feb 2009
      • 3877

      Re: Beginner coder

      I don't see the problem with using "this.", it's just a way to get the variable with that name of "this" class.
      Otherwise you're referring to the argument of your method, which has the same name.
      Last edited by SKG_Scintill; 11-9-2014, 09:27 AM.





      Originally posted by bluguerilla
      So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
      ___
      . RHYTHMS PR LAYERING
      . ZOMG I HAD TO QUIT OUT TERRIBLE
      .

      Comment

      • #18
        Wubalubadubdub
        shenjoku
        • May 2005
        • 1734

        Re: Beginner coder

        If you make sure your members don't clash with the names of parameters or local temp variables then you shouldn't need to use "this.whatever" ever. If you can remember to always use this to lookup members then I suppose it works, but I've had to debug many bugs caused by locals and members having the same name so I feel like it's safer to have a solid naming convention that doesn't do that ever.
        boop

        Comment

        • #19
          The Worst
          FoJaR
          • Nov 2005
          • 2816

          Re: Beginner coder

          i know i'm like 6 months late, but you're all wrong.

          python is the answer. qt if you want a gui.

          i'm less anti c# now that .net is going open source, but python is simple and easy. definitely something for someone who is just getting into coding, especially if integrating fortran code is something that you're looking for.

          Comment

          • #20
            Digital Dancing!
            FFR Simfile Author
            FFR Music Producer
            rushyrulz
            • Feb 2006
            • 13109

            Re: Beginner coder

            Python disgusts me.


            Comment

            • #21
              The Worst
              FoJaR
              • Nov 2005
              • 2816

              Re: Beginner coder

              cool insight!

              Comment

              Working...