Hello everyone,
First off, I would like to thank everyone that replied to this thread and contributed their criticism and advice regarding my style of coding.
I am really grateful since I am relatively new to Lua. There seems to be issues about my particular style of coding that doesn't seem to be as well accepted by everyone but that's okay, everyone has their view on the 'correct' way of programming.
So lets first address some facts initially pointed out by
BigTwisty.
-->> Because args is defined as {...} it will always exist as a table. Remove "args and" as it is redundant.
- Did not know that, but should have realized.
Comparisons return a boolean
- Didn't know that either, saves me a few lines of code.
-->> burnCoolDown() calls lineUpdate() before it is declared. You need to move the lineUpdate() function above burnCoolDown() so it exists when burnCoolDown() is compiled.
- It didn't seem to matter? Does it really need to be organized like that? I thought alphabetical would have been better.
Feel free to reply to my remarks about those.
====================
Topic 2. Functions
One of the things I have noticed with my Lua programming is that I see that I have used a lot of set notions I have used languages, like in C#. I seem to have developed a sense of 'hiding' the code wherever possible, leading to single-use functions that Programmer's Notepad recognizes as a collapsible block of code. Normally for C#, you would use something like the
#region directive (C# Reference) to tell the IDE to trigger the outlining feature.
That explains a small portion of why I use run-once functions, simply because they make it slightly more 'readable' but also just happen to hide a portion of the code in a summary of what it does i.e. printVariable() from line 56-63. I could understand if you're mad at me for writing run-once functions but if I gave them meaningful names, then It becomes more readable.
Intro -> getVariables -> printVariables -> <Main Sequence> -> exit()
In addition, I actually have an API called eTurt with Intro() that I usually include with the programs that I have programmed, I just didn't include it because most of it actually contains nothing relevant to this new program except for one function. (Total programs that call Intro() is about 7, I believe)
But I totally agree with you, If I did this for the sake of just want to have clean collapsible code (which I did), Then I am a fool and live up to the name.
I am however interested in that checking tree, Tell me more….
local tree = {
["folder"] = {
"screenUtils"; "otherCrap"; --etc.
["NotAFolder"] = true;
}
On the topic of how many functions you should have though, I agree with
theoriginalbit. I prefer to break it down as much as possible without reducing readability.
I visualise code a tree, You may have many many branchs and leaves but it boils down to the trunk that is holding the whole thing together, main(). The branches are functions, if they are healthy, then you don't need to know what is behind them. Likewise the smaller branches do not need to know about how leaves work, they just need to produce energy via photosynthesis (Processing), and the branches supply the nutrients (Variables).
But thank you again for commenting on my code, I expect even more criticism soon.
PS. functions do shorten code if you use the function more than once.