HOW TO WRITE CODE?

Posted by Alert Games on April 1, 2012, 12:06 p.m.

How do you write code?

A:

if (this==statement) {
code = 1;
     if (this==another) {
     moar = 2;
     }
}

B:

if (this == statement)
{
     code = 1;
     if (this == another)
     {
          moar = 2;
     }
}

C:

if (this == statement)
{
code = 1;
if (this == another)
{
moar = 2;
}
}

Notice I put semicolons after every assignment, because it is good practice.

I also put "==", even though this isnt required in game maker, its required in other languages. Probably because you can assign variables within statements in other languages.

Personally I code in A, but i think the most legible and widely used is B.

What would be cool is if there was an option in game maker to clean their code up to standards, for learning purposes.

In other news, YOYOgames is starting to go bankrupt. Which i find hallarious.

heres the link: yoyogames

Comments

sirxemic 13 years, 1 month ago

To anyone who codes like as in A: wtf - it's not even listed here

…except when FirestormX AG (or you) actually mean this:

if (this==statement) {
    code = 1;
    if (this==another) {
        moar = 2;
    }
}

MMOnologueguy 13 years, 1 month ago

if this=statement
{code=1
if this=another
moar=2}

Good enough for me.

Rob 13 years, 1 month ago

Quote:
To anyone who codes like as in A: wtf

…except when FirestormX (or you) actually mean this:

I just assumed he did that by mistake and didn't actually not indent the first line of his code blocks.

Quote: MMORPGguy

if this=statement
{code=1
if this=another
moar=2}

Good enough for me.

DISQUALIFIED!

sirxemic 13 years, 1 month ago

Also, the indent styles have names:

http://en.wikipedia.org/wiki/Indent_style

firestormx 13 years, 1 month ago

*mutters* "A" is so annoying.

Josea 13 years, 1 month ago

I prefer the Java style, and the 80-column rule.

firestormx 13 years, 1 month ago

I hate putting if () clauses on multiple lines, but seeing it done makes sense sometimes. I just really don't like it when every single clause gets a new line (one developer at my work does this, and when I'm analyzing his code, it nags at the back of my mind). Like this:

if (my_var == true
	&& that_var == false
	&& num == 3)

It's small enough to be on the same line, in under 80 characters. >_>

Also, camelcase! Raaagh!

Acid 13 years, 1 month ago

B - and I add extra lines between sections to make code more readable.

Moikle 13 years, 1 month ago

Both A and B, depending on the alignment of Jupiter and Saturn

Glen 13 years, 1 month ago

I use a format similar to B.

if (variable == value)
       {
                drop = bass;
                if (sound > 0)
                       {
                                lasers = 1;
                       }
       }