Not long ago I have started scripting. I watched many tutorials and learned a lot. However, I keep hearing about developers having to remake games because their code was messy.(ex: treelands)
What does messy code mean and how can I avoid writing messy code that I won’t understand?
I`m intermediate at coding but messy code is basically keeping it organized. When you write hundreds of lines than come back to it months later, it may be hard to understand what you made months ago. Labeling certain functions, making clear places for defining variables, and proper indentation can made code easier and more understandable to read to the eye.
Well, you have to bear in mind that a lot of things in code are up to preference.
Messy code in general could be bad practices, vague variables or poorly named/structured code, unoptimized code, etc.
It boils down to having readable, clear, efficient, and documented code in some cases. If you don’t have any of these, with the exception of documentation (though documentation is very helpful sometimes), it could be considered messy code.
Messy code is easy to avoid in lua as it is not that hard to understand what the code in scripts are doing in lua because lua is very basic function wise because there are not a lot of different functions and variables in lua like c or c++ for example where it is a lot harder to keep your code organized cause it can be confusing because of all the different functions and variables in c or c++.
Use indents. Avoid deprecated functions, bad practices, code smell. Learn some optimization methods. And document everything.
Just going off of things I see often in the scripting support forum…
In my opinion, the best way to avoid writing messy code is through the use of modularization.
Modularization can be easily implemented using ModuleScripts. The principle is simple: code should be divided into modules that fulfill a specific task or collection of predictable, similar tasks. Imagine the principle of least astonishment for code organization.
I don’t think I could possibly disagree with anything more than I disagree with this. Strictly object-oriented languages such as C and C++ all but force you to organize code into classes and objects that fulfill a specific purpose. Consequently, the code will be organized into individual (hopefully concise) files (classes) that fulfill predictable purposes.
I’d say that these are really references to bad code, not messy code.