Lua is an incredibly versatile programming language. Many things that one would think to be incorrect will run correctly in Lua, and in some cases that's a good thing: Usually though, it's not. When you begin to write long programs (and by long, I mean multiple files and mind-blisteringly complex interweaving of functions), things that you started writing at the beginning of the program are not going to be as obvious several months later as they were when you first wrote them. Bad coding practices in this regard will kill your program in readability and functionality if you're not careful, so try to make these simple programming practices a habit so that life doesn't suck later.
1) Make comments on you own code. You're probably rolling your eyes right now thinking, "I know what my own code does. Why should I put comments on it?" And that's a valid question. Today I was looking back through some several month old code of mine and I didn't even know what the thing was supposed to do, let alone how I was supposed to utilize it. Figuring out its purpose would be nearly impossible without painfully going over every single function and testing them individually. So unless you want to rewrite your code every few months, or if you enjoy that painful 'decompiling' process, don't forget to comment as much as possible.
2) Indentation. I can't stress this one enough. When you're inside of an if statement inside of a for loop inside of a while true do loop inside of a function, your code gets really messy really quick. If you don't indent everything, you are going to absolutely hate life later on when you find get an eof or 'end expected' error and you have no idea why. So yeah. Indentation is important.
3) Be concise: If you are making a function that moves a turtle forwards 12 spaces, don't name it 'thisisafunction()' because somebody looking at your code will have absolutely no idea what it's supposed to do without parsing it out. And it will suck if that somebody is you twelve months later.
4) Use the right tool for the job and be consistent about it. If you think that an ipair loop would fit a certain situation and that situation comes up later, be consistent and use the ipair loop again. Coding consistently is enormously helpful when you find yourself using the same tools over and over again because you become familiar with how you should go about different situations.
5) Remove unnecessary code. This one seems like a no-brainer, but you'd be amazed at how lazy the average human being is (or maybe you wouldn't). I often find myself just ignoring the fact that I don't use a certain function in an API and adding new things just becomes confusing when you keep looking at the unused code to see what it does. Another reason to remove unnecessary code is that it makes the whole program just 'better' and more satisfying than when the whole thing is a rag-tag mess. Making a complex program using only a few ingenious lines of code is the most enjoyable thing in programming, in my opinion :)/>/>
6) Take breaks. If you're stuck on a problem, don't sit there and stare at it for ages trying to figure it out. Go grab a drink, eat some cereal, or play a game to take your mind off it for a while. Better yet, go and take a nap. When you come back, I can promise you that you'll be able to solve the problem much, much quicker than you would otherwise.
7) Try to make an 'outline' of what you want your program to do and how you might want to go about it. This mostly only applies to long and/or complex programs, but if you're having difficulty writing anything, an outline will help out enormously.
8) Program in a way that fits you: If you program best jumping about from function to function, program like that. If you program best completely finishing each function before moving on, program like that. The unique thing about programming is that there are an infinite number of ways to go about a problem. If you have trouble working in a certain way, don't force yourself to do so.
If you take to heart these eight simple coding habits, I promise you life will be infinitely easier when you're faced with that mega-challenge you've been wanting to solve for a long time.
Thank you for reading,
Bubba