Many small functions vs. a few large functions
Posted: 07 May 2014, 11:50
I am sure it is personal preference, but I am curious if there are sort of standard common practices amongst programmers, that may be helpful to non-programmers like myself.
I am not a programmer, I have no formal or on the job training, or even any friends that write code. It seems AHK attracts many people like me.
Over the last year I have used AHK extensively, and after some time I found out that I should avoid global variables and use functions as much as possible. I recently started using VBA as well, and I'm running into these same questions. Does anyone know where a non-programmer can find these sorts of helpful guidelines (ie. avoid global variables) that may seem obvious to anyone that does it for a living?
I tend to write code like this:
where the one function may be a few hundred to a few thousand lines themselves. In my mind, this avoids global space as much as possible.
Is it better to instead split the function into many smaller functions, and call them from the label? VBA books seem to push this idea, that's where this question came from.
Also, quite often I'll use functions within other functions, which seems frowned upon for some reason:
Is this bad for some reason?
I am not a programmer, I have no formal or on the job training, or even any friends that write code. It seems AHK attracts many people like me.
Over the last year I have used AHK extensively, and after some time I found out that I should avoid global variables and use functions as much as possible. I recently started using VBA as well, and I'm running into these same questions. Does anyone know where a non-programmer can find these sorts of helpful guidelines (ie. avoid global variables) that may seem obvious to anyone that does it for a living?
I tend to write code like this:
Code: Select all
label:
Func()
return
Is it better to instead split the function into many smaller functions, and call them from the label? VBA books seem to push this idea, that's where this question came from.
Also, quite often I'll use functions within other functions, which seems frowned upon for some reason:
Code: Select all
Func()
{
if (AnotherFunc())
AndAnotherFunc()
}