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 12 years, 8 months 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 12 years, 8 months ago

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

Good enough for me.

Rob 12 years, 8 months 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 12 years, 8 months ago

Also, the indent styles have names:

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

firestormx 12 years, 8 months ago

*mutters* "A" is so annoying.

Josea 12 years, 8 months ago

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

firestormx 12 years, 8 months 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 12 years, 8 months ago

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

Moikle 12 years, 8 months ago

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

Glen 12 years, 8 months ago

I use a format similar to B.

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