Never call the sleep function if it is not needed. It makes the user wait for no reason, which usually causes frustration.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
The Do's and Dont's of Coding
Started by SuicidalSTDz, 02 April 2013 - 11:13 AMPosted 02 April 2013 - 01:13 PM
This topic is going to be all about the Do's and Dont's of coding. What we should and should not do so users like our scripts/programs. Please do not repeat anything that was already mentioned.
I will start us off:
Never call the sleep function if it is not needed. It makes the user wait for no reason, which usually causes frustration.
Posted 02 April 2013 - 01:14 PM
Do not use shell.run in place of a while loop.
Do not store passwords in plain text.
Do not store passwords in plain text.
Posted 02 April 2013 - 01:15 PM
DO not use files as functions(I'm looking at you Direderp -_-/>).
Posted 02 April 2013 - 01:15 PM
Never EVER use os.reboot to repeat a startup.
Posted 02 April 2013 - 01:16 PM
Can we also put the ALWAYS's of coding? If we can, put always indent and comment so you never forget what the code is supposed to be doing.
Posted 02 April 2013 - 01:17 PM
Never use slow print! It is evil!
Posted 02 April 2013 - 01:17 PM
Heh ^_^/>(I'm looking at you Direderp -_-/>).
On topic: Don't use fake loading screens. If nothing is being loaded/downloaded/or ran then don't make it look like something is. It is trashy and clutters code with useless nonsense!
Go for it. Just make sure you state this is what you SHOULD do.Can we also put the ALWAYS's of coding? If we can, put always indent and comment so you never forget what the code is supposed to be doing.
Posted 02 April 2013 - 01:18 PM
Never use recursion, unless it is 100% needed!
Posted 02 April 2013 - 01:19 PM
When make a GUI do not constantly redraw every pixel. Have two buffers. The screen that has just been drawn and the one that needs to be drawn. Compare the two and only redraw what you need.
900th post! WOOO! :D/>
900th post! WOOO! :D/>
Posted 02 April 2013 - 01:20 PM
Recursion is never needed.. *sigh* Still, NO RECURSION!Never use recursion, unless it is 100% needed!
Posted 02 April 2013 - 01:20 PM
Never use parallel/coroutines when you don't need to.
Always send rednet messages in compact form. (Aka, 1 serialized table, not 6 individual messages.)
Always send rednet messages in compact form. (Aka, 1 serialized table, not 6 individual messages.)
Posted 02 April 2013 - 01:22 PM
Try to list a whole filesystem without recursion.Recursion is never needed.. *sigh* Still, NO RECURSION!Never use recursion, unless it is 100% needed!
Posted 02 April 2013 - 01:23 PM
Did I just release everyone's stress from bad code, into one topic?! Well, better here than on a clueless member… ^_^/>
Yeah.. I'm going to pass on that offer ;)/>Try to list a whole filesystem without recursion.
Posted 02 April 2013 - 01:23 PM
3 times, straight off the top of my head….. Iterating filesystems, copying tables and all internal tables, solving Towers of Hanoi…Recursion is never needed.. *sigh* Still, NO RECURSION!
Posted 02 April 2013 - 01:25 PM
Did I just release everyone's stress from bad code, into one topic?
Yes, yes you did. :P/>
Posted 02 April 2013 - 01:25 PM
never try to send entire files over redstone pulses…………………………………
Posted 02 April 2013 - 01:25 PM
No using snippets of code over and over, just make a local function! It's easier! And if it is already a function that takes up one line that you're using a lot, e.g. shell.getRunningProgram(), store it as a local shorter variable!
Posted 02 April 2013 - 01:26 PM
Use the new wired modems, not bundled cables. (Unless absolutely necessary, or u just feel like it_
Posted 02 April 2013 - 01:26 PM
Most clueless members reading this post will not be attempting any of those 3 things :P/>3 times, straight off the top of my head….. Iterating filesystems, copying tables and all internal tables, solving Towers of Hanoi…Recursion is never needed.. *sigh* Still, NO RECURSION!
Do not close a file handle while it is in use! (No-brainer)
Posted 02 April 2013 - 01:26 PM
Always debug first, release later.
Always check for HTTP/Color before using them.
Always check for HTTP/Color before using them.
Posted 02 April 2013 - 01:26 PM
More for security but whatever.
Never trust user input. I don't care what it is. Just don't trust your users at all.
Never trust user input. I don't care what it is. Just don't trust your users at all.
Posted 02 April 2013 - 01:28 PM
More for security but whatever.
Never trust user input. I don't care what it is. Just don't trust your users at all.
I challenge you to make a login system without user input. XD
Posted 02 April 2013 - 01:28 PM
It's okay to make assumptions as to how some things work, but if this doesn't work:
Don't ask why it doesn't work, and don't call it a bug that it doesn't work. At least attempt to look up what the real syntax for it is.
While True Do {
System.Console.writeln(new String("Hello World!"));
}
Don't ask why it doesn't work, and don't call it a bug that it doesn't work. At least attempt to look up what the real syntax for it is.
Posted 02 April 2013 - 01:30 PM
I said don't trust it. When you make a login system that uses SQL you are going to change the string to prevent SQL injection.More for security but whatever.
Never trust user input. I don't care what it is. Just don't trust your users at all.
I challenge you to make a login system without user input. XD
Posted 02 April 2013 - 01:34 PM
Always declare your variables local unless you have a good reason not to. (Weird no-one posted this yet.)
–Offtopic: What is SQL injection?
–Offtopic: What is SQL injection?
Posted 02 April 2013 - 01:37 PM
Best XKCD ever :D/> But I've seen it before :P/>
Posted 02 April 2013 - 01:37 PM
This topic is pointless. Locked.