Author Topic: [Let It Be Known To All] - Tumble Bug  (Read 3552 times)

How is it sloppy? It's orderly and easy to read.
I like to always put brackets with my if statements.
You're indented 5 times and each new condition brings an extra 3 lines. The inclusion of brackets with your if statements aren't a problem so much as the end result of having so many of them. It's simply a poor choice next to Ip's version.


This is 200% false, condensing it into one if statement actually speeds it up and nothing he said is correct

You can condense it as follows into one if statement:
Thanks for clearing this up, I'll talk to my AP Computer teacher about this.

Thanks for clearing this up, I'll talk to my AP Computer teacher about this.
What I said only really applies to TorqueScript, when it comes to things like C++ and other languages like that, the compiler is (in most cases) actually really good at optimizing that kind of stuff, and the code snippet
Code: [Select]
if(x > 0)
    if(y < 0)
        return 5;

might produce the exact same machine code as
Code: [Select]
if(x > 0 && y < 0)
    return 5;
so I'm really not sure how much it applies to other languages.

Here's an abstract representation of what the two methods actually boil down to. Keep in mind that this is with &&; one with & would look very different.
Series of if statements (keep in mind that the additional return instructions do not slow it down):

000 conditional jump to 002
001 return
002 conditional jump to 004
003 return
004 conditional jump to 006
005 return
006 ...


Condensed if statement:

000 conditional jump to 004
001 conditional jump to 004
002 conditional jump to 004
003 return
004 ...
« Last Edit: April 22, 2014, 12:03:22 PM by Port »