Clean code/script

how to make my codes less cluttered and easier to understand

2 Likes

Use modular programming and make use of comments on every block of code

Yeah state all you variables the top of the script, use comments. Too much of a thing is bad. Use spaces to make your code look neat. Last, remove lines of code that aren’t necessary.

The Roblox Lua Style Guide GitHub page provides lots of insight into the recommended coding practices to ensure that your code remains legible and consistent, making it easier to modify and debug your code over time.

1 Like

Probably the best you can possibly do is stick to this particular style guide.

https://roblox.github.io/lua-style-guide/

It’s very informing, helps you develop good habits and organize your code better. If you don’t know about object-oriented programming or metatables (yet), you can skip the that section as it may look confusing at first in that case. You can of course develop your own coding style and stick to it, however, it should comply with certain standards described in the page above, because it helps keep code readable and suggests practices that make code review and maintenance, respectively collaboration, easier.

Be consistent with your code, descriptive with naming, brief when writing code, and try to optimise performance and reduce number of lines. Readability and performance are two very important aspects. When defining variables, always stay picky. Only define variables that you truly need, and limit scope of variables that you don’t need to use globally, e.g. if you only use a count variable temporarily, define it inside a function, loop etc., so it get’s deleted/cleared upon code block finishing.

There are many aspects that are closely related to actually code performance. Having lots of unnecessary variables is not adviced. Not disconnecting unused connections or having too many of them is bad as well. Always seek for better alternatives and so on.

EDIT @StrongBigeMan9 and I posted at about the same time, so link recommendations are actually the same. :slight_smile:

1 Like