Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW)
OpenStudy (anonymous):

When is it a good idea to build a new function for an operation?

8 years ago
OpenStudy (anonymous):

As in, "for how small of an operation is it worth building a function?" Does it depend on how many times you're going to use it?

8 years ago
OpenStudy (shadowfiend):

Often yes, it's advised that you write a function as soon as you need something more than once. Modern compilers can generally `inline' code -- meaning that they can detect when a function is relatively short and replace the function call with the code in the function itself, thus removing any performance impact from having `too many' function calls. This is, as usual, something you get a feel for, but small functions are not something to be afraid of. If what it does is not particularly evident, you can move a piece of code into a function so that you can give the function a descriptive name and then when it's used the code is clearer.

8 years ago
OpenStudy (anonymous):

Thanks!

8 years ago
Can't find your answer? Make a FREE account and ask your own question, OR you can help others and earn volunteer hours!
Latest Questions
Skatercat: I NEED IDEAS FOR MY DEMON BOOK T^T I COMPLETELY FORGOT ABOUT IT T^T
4 minutes ago 5 Replies 0 Medals
SummerWars: Fan Club of Summer Wars ONLY!!! (Friends are allowed!)
10 minutes ago 19 Replies 1 Medal
SummerWars: Summer Wars Fans only!!! (and if u are my friend)
1 hour ago 74 Replies 3 Medals