general tips on having code neat and g o o d?

im interested in being a better coder, i see all these nice functions in source code i see, are there like general guidelines to be more organised and how do you do it in lua?

comment everything

now you’re expert coder top 1% feel free to put it on your resume

Decide on your style, make sure to apply it consistently and keep an open mind to changing it

Keep it readable, document it with comments

Generalize functionalities, even if you’re planning on using them once, it will very probably make for faster coding in the future

Once you finish a project, be willing to completely scratch it and start all over again, the second iteration will always be an improvement, because you know exactly what you’re in for

I tend also to comment before functions all the information about the function. If you do it in a consistent way, you can then create a documentation generator.

– GM.Modules.LoadModule function
– Argument 1: [String] Name of module
– Argument 2: [Table] Configuration of the module (optional)
– Returns [Bool] Successful loading of module

I also try and keep my code inside the 80 character per line rule. The original reason for this rule was for lines to be displayed properly on old monitors, but it still provides the same about of legibility, as long as you aren’t too strict about it.

You should also use named variables for constents, so anyone wanting to change a variable understands what it is.

It might be a good idea to prefix variables with identifying sequences, so as to increase your efficiency when debugging code. for example m_Variable for member variables, __Variable for local variables, g_Variable for global variables, and so on. You can do the same for classes, such as IMyInterface, bMyBooleon, mat_MyMaterial, etc.

Use OOP to be master coder

I never understood why people use OOP in Lua. Is it better? If so, how?

It can sometimes be cleaner, depends on how you do it, and also what you’re doing it for.

There isn’t any “perfect” way to organize code really. Many professional (expert) coders tend to have more complex but readable code because that is the style they’ve adapted to over their time coding.

However, my tips are to comment everything in a concise way so that both you and others will know what you’re doing. Variable names should be the same so that you know what that variable is for.

Essentially, you wanna create a style that you can understand if you leave the project for years then come back and still understand.

Also, don’t over do things, or you’ll make extremely slow progress. Last tip I can think of: plan before coding, make sure you know exactly what you’re trying to achieve and know exactly how you’re going to do it functionality wise.

I just code to make it work, then when I know it works I’ll redo it to make it better/more efficient.

Don’t we all? :v: I don’t think I know anyone who codes for efficiency on the first pass.