2 Replies Latest reply on Mar 30, 2010 3:41 PM by GordonSmith

    Too many functions?

    SpaghettiCoder Level 3

      Does it really matter if you have one really long function,

      or

      one small function but split into 3parts and called all from the first function? like a bunch of sub functions...the 2 other parts are all needed and not used by anything else.

       

      functionLong()

      {

      // 600 lines

      }

       

      OR

       

      functionShort()

      {

      // 200 lines

      functionShort2()

      functionShort3()

      }

       

      functionShort2()

      {

      // 200 lines

      }

       

      functionShort3()

      {

      // 200 lines

      }

        • 1. Re: Too many functions?
          skider

          There is probably a tiny performance hit in calling the extra functions, due to having to dereference the function, but it's not something that I would worry about. The performance hit is much less than, say, instantiating an object, and that's something that we do all the time.

           

          Instead, I think I would be more concerned with the readability of the code. Good style would dictate that you should break the code into functions that are semantically relevant (they have meaning on their own), and small and simple enough to be human readable. You should also consider reusability. If you might need to use some aspect of the code somewhere else, it should definitely be its own function.

          1 person found this helpful
          • 2. Re: Too many functions?
            GordonSmith Level 4

            I agree. If some code makes sense on its own, don't be afraid to factor it into a separate method.

             

            Gordon Smith

            Adobe Flex SDK Team