Kadoba
I'd say your code is on the messy side. Here are some tips:
Keep your spacing consistent.
Use indention.
If a line becomes long then break it up into multiple lines.
Use either camelCase or under_scores to indicate spaces in variable names. Try not to use both and be consistent. (camelCase is more common)
I really recommend sticking all of your globals into a single table. There are multiple benefits to doing this.
Put reusable code into functions. Functions are cheap and easy to define in lua so take advantage of that.
Comments should add understanding to the code. The ones you had were pretty obvious so I removed them.
Also keep in mind while there are a lot of common agreements on what is clean code and what isn't, there are some things people don't agree on. The absolute most important thing is that you must be consistent. If you do things a certain way then try and do them that way all the time, although that isn't always possible.
Here's your code the way I would write it (I haven't tested it):
well when I was trying to learn C# Visual Studio did all of the spacing and indenting for you, is there a setting In Scite that will help with spacing and indention. Are you saying it's not clean or good to us both cameICase and under_Scores in the same program at all.
Will with the Functions and globals I haven't really got to that point or full understand how to use them and how did you make a function with out declaring it.
my skills are limited right now im just getting the grasp of the basics. i was planing on for today to be functions and understating for loops more then a little bit of table because i really want to start seeing oop programing.
miko
It depends on those factors:
- do you use any coding style at all
- do you strictly follow choosen coding style
- is that coding style easily understandable by others
well for me as of now the answers would be no, no, and I don't know I'm going to look at the link to see what is what.
kikito
It's a matter of priorities.
The one thing you must have to understand is this: nowadays when one writes code, the main objective is not that the machine understands it (or, as if you say, that "it runs"). The main objective is that other people understand it.
"But I'm going to be the only one using this code" you may say. Well, take this into account: your future self is also other people.
"But this is a small piece of code, I'm going to use it once and then never use it again": First, you never know for sure. Second, if it's just a small piece of code, then it's a great opportunity to practice clean code! It's such a small code! It's perfect!
So, first you make it "understandable for humans". Then you fix the errors, adapt the syntax, add secondary functions, etc until the machine also understands it.
ok ok i'll try that method out to see if it works for me, humans over machines.
Robin
What the others have said, plus:
In Lua, terminating semi-colons are not necessary. I'd suggest not using them in general, it only adds line noise.
The comments for the first two io.read()s are information for the user, not for the programmer, so it'd be better to print them if you want the user to see that.
I'm not sure what you want with:
Code: Select all
input_YesOrNo = "yes", "no"
It assigns "yes" to input_YesOrNo, and then the program ends.
semi-colons is something i picked up from C# i saw that it work and so i kept on using them but I'll stop.
ok i guess i should write better comment because that was for the programer. can you give me an example of what you would write for comments in my little code.
and yes one of my friends point that out to me I guess i should do input_YesOrNo ="yes", input_YesOrNo = "no"