How to better name functions
Often when organizing programs
Will combine code that is used more than twice into one function
But the code in a function may be shortened to more than 2~4 functions to process
At this point, the function naming is confusing, and it feels that it deals with the same thing but not exactly the same thing
How do you usually name it?
Please
I personally wouldn’t create too many functions as to break every possible small piece of code into one. There’s no compiling in Lua which means there’s no code improvement done for you.
If you can get something done with 1 function call that has 15 lines of code then I would keep it that way rather than breaking the code and making 3 additional function calls to get the same job done, even if one of those small functions can be used by something else. May not always apply, so you’ll need to be reasonable in your own ways.
Now, as far as naming functions, the only thing that comes to mind is to not be afraid to give it long names that more or less explains what the function does.
For example:
createDataSetToCompareAndSort()
HI
My function names are usually very long
Express the meaning of the function as much as possible
but
For example, I have an A function with 5 small functions in it
Other B functions will use 2~3 of them
This makes my naming a bit of a hindrance
Want to attach the name of class A but class B will also use it
I think it’s good to have a separate name, but I don’t think it’s the best.
Thank you for your answer
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.