Re: Functions - how far to go with them?
Hi Robert,
See Cal's Naming Conventions tips. Cal and I differ a bit in our naming conventions, but it's a good start. Basically I'd say make it unique, 23 or less characters, be clear to it's purpose, don't end in a number, Don't start with something similar to many Alpha function names, and if for distribution, include unique ID in name to avoid name collisions, e.g. AIMS_Format, CSDA_BarCode.
I also tend to make test code start with "a_" to put it at the top of the code list. When I am done with old code, I tend to rename it, starting it with "z_" (and occasionally adding a number at the end to indicate version revision) so it sorts to the bottom of the code list.
In general, if it's a 1 line piece of code (e.g. Opening a form), leave it in the button/event (I'll use the term button below to mean ervent code). If it's a small conditional, e.g.
then put the conditional in the function. If the reference date is different, pass it as a parameter argument, e.g.
that calls the same function 2 different ways. You could either possibly add an end parameter (ideally optional and/or having a default), or use an existing function parameter to control the choice.
However, assuming it couldn't be brought into your function, something as simple as the above I would still leave in the button.
It comes down to what constitutes code specific to the use on the button (in which case it tends to stay on the button), and what is common between other uses of similar code (in which case it goes in the function). Once the button's code exceeds a trivial # of lines (particularly if I need to debug/edit it alot, or think about what it is doing at the higher level concept, it goes to a function)
One exception to this is the OnKey event. Sometimes this is very time sensitive, if you have poorly written code. The number of key events is a lot higher than one might think. So the top of the code does a check to see if it is what I need to process. If not, it immediately returns. If it is, it calls my onkey code that I have in a function. That code tends to amount to maybe 5 lines of code.
From another perspective, consider the fact that my common library of functions has roughly 1000 functions in it that I have written over many years. Many are test code or old versions. That is not a lot, and none of the finished ones are similar. So it is not every button, it is just my "common code"
Hi Robert,
Originally posted by Mayapur
View Post
I also tend to make test code start with "a_" to put it at the top of the code list. When I am done with old code, I tend to rename it, starting it with "z_" (and occasionally adding a number at the end to indicate version revision) so it sorts to the bottom of the code list.
Originally posted by Mayapur
View Post
Code:
IF date()>{01/01/2000} newdate=myfunction(birthdate) ELSE newdate=myfunction(addyears(birthdate,-1)) END IF
Code:
newdate=myfunction(birthdate,{01/01/2000})
However, assuming it couldn't be brought into your function, something as simple as the above I would still leave in the button.
It comes down to what constitutes code specific to the use on the button (in which case it tends to stay on the button), and what is common between other uses of similar code (in which case it goes in the function). Once the button's code exceeds a trivial # of lines (particularly if I need to debug/edit it alot, or think about what it is doing at the higher level concept, it goes to a function)
One exception to this is the OnKey event. Sometimes this is very time sensitive, if you have poorly written code. The number of key events is a lot higher than one might think. So the top of the code does a check to see if it is what I need to process. If not, it immediately returns. If it is, it calls my onkey code that I have in a function. That code tends to amount to maybe 5 lines of code.
From another perspective, consider the fact that my common library of functions has roughly 1000 functions in it that I have written over many years. Many are test code or old versions. That is not a lot, and none of the finished ones are similar. So it is not every button, it is just my "common code"
Comment