This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SuicidalSTDz's profile picture

The Do's and Dont's of Coding

Started by SuicidalSTDz, 02 April 2013 - 11:13 AM
SuicidalSTDz #1
Posted 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.
gamax92 #2
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.
Sammich Lord #3
Posted 02 April 2013 - 01:15 PM
DO not use files as functions(I'm looking at you Direderp -_-/>).
MudkipTheEpic #4
Posted 02 April 2013 - 01:15 PM
Never EVER use os.reboot to repeat a startup.
MudkipTheEpic #5
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.
Sammich Lord #6
Posted 02 April 2013 - 01:17 PM
Never use slow print! It is evil!
SuicidalSTDz #7
Posted 02 April 2013 - 01:17 PM
(I'm looking at you Direderp -_-/>).
Heh ^_^/>

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!

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.
Go for it. Just make sure you state this is what you SHOULD do.
theoriginalbit #8
Posted 02 April 2013 - 01:18 PM
Never use recursion, unless it is 100% needed!
Sammich Lord #9
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/>
SuicidalSTDz #10
Posted 02 April 2013 - 01:20 PM
Never use recursion, unless it is 100% needed!
Recursion is never needed.. *sigh* Still, NO RECURSION!
MudkipTheEpic #11
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.)
Sammich Lord #12
Posted 02 April 2013 - 01:22 PM
Never use recursion, unless it is 100% needed!
Recursion is never needed.. *sigh* Still, NO RECURSION!
Try to list a whole filesystem without recursion.
SuicidalSTDz #13
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… ^_^/>

Try to list a whole filesystem without recursion.
Yeah.. I'm going to pass on that offer ;)/>
theoriginalbit #14
Posted 02 April 2013 - 01:23 PM
Recursion is never needed.. *sigh* Still, NO RECURSION!
3 times, straight off the top of my head….. Iterating filesystems, copying tables and all internal tables, solving Towers of Hanoi…
MudkipTheEpic #15
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/>
theoriginalbit #16
Posted 02 April 2013 - 01:25 PM
never try to send entire files over redstone pulses…………………………………
Shnupbups #17
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!
MudkipTheEpic #18
Posted 02 April 2013 - 01:26 PM
Use the new wired modems, not bundled cables. (Unless absolutely necessary, or u just feel like it_
SuicidalSTDz #19
Posted 02 April 2013 - 01:26 PM
Recursion is never needed.. *sigh* Still, NO RECURSION!
3 times, straight off the top of my head….. Iterating filesystems, copying tables and all internal tables, solving Towers of Hanoi…
Most clueless members reading this post will not be attempting any of those 3 things :P/>

Do not close a file handle while it is in use! (No-brainer)
MudkipTheEpic #20
Posted 02 April 2013 - 01:26 PM
Always debug first, release later.

Always check for HTTP/Color before using them.
Sammich Lord #21
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.
MudkipTheEpic #22
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
Kingdaro #23
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:


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.
Sammich Lord #24
Posted 02 April 2013 - 01:30 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
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.
MudkipTheEpic #25
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?
oeed #26
Posted 02 April 2013 - 01:35 PM
Always, always, always serialise/sanitize your inputs!



Also, may I suggest you add the dos and don'ts to the main post, rather than trawling through the topic.
Sammich Lord #27
Posted 02 April 2013 - 01:37 PM
Always, always, always serialise/sanitize your inputs!



Also, may I suggest you add the dos and don'ts to the main post, rather than trawling through the topic.
Best XKCD ever :D/> But I've seen it before :P/>
Cloudy #28
Posted 02 April 2013 - 01:37 PM
This topic is pointless. Locked.