[Tutor] Code optmisation

W W srilyk at gmail.com
Sat Apr 5 13:24:16 CEST 2008


On Sat, Apr 5, 2008 at 2:44 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "yogi" <byogi at yahoo.com> wrote

>  > Question 2: If I have convert this code into a function.
>  > Should I ?
>
>  Only if you have a need to reuse it in a bigger context
>  or of you want to parameterize it. You could maybe break
>  it out into smaller helper functions such as the one I
>  suggested above.

Personally, functions are always fun!
...

And useful. Even if you don't need to play with them later, there's no
loss, because the exercise is in and of itself a good one. Plus, I
think functions tend (though not always) force you to clean up your
code: As Alan has mentioned, there are a few places that you duplicate
code. The exercise of converting to functions will often point out the
fact that you have multiple code.

Have fun!
-Wayne


More information about the Tutor mailing list