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

Castypher 12 years, 8 months ago

I used to code in A all the time, and some IDEs consider that default (when you create a new file with content). Unity comes to mind. But right now I code in B, because it does feel the most legible to me.

Also, GM was better when Mark ran the show.

Iasper 12 years, 8 months ago

I always use C, but in a different way:

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

Although I sometimes stack the { and } if they take up to much space.

ludamad 12 years, 8 months ago

I don't use GM anymore, but my C++/Java style of choice is:

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

leemcd56 12 years, 8 months ago

^that's how I write

duckman 12 years, 8 months ago

A.

Rez 12 years, 8 months ago

I slam my head on the keyboard. I generally write like B but I'm prone to being messy when I have to add something extra.

Alert Games 12 years, 8 months ago

@Iasper: Thats not good practice at all :( Youre missing semi-colons, parenthesis, and indentation. I recommend picking up on A or B if youd like to continue programming, as it is a standard. Try it out!

@ludamad: Yeah im starting to pick up on that as well. Indentation after a statement clause is much easier to follow.

Extravisual 12 years, 8 months ago

I like to code everything like so:

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

marbs 12 years, 8 months ago

I like the brevity of method A, but enjoy the nostalgia and readability of method B.

I used to write code completely like method B, stemming from my background in Game Maker, however in recent years have had to use method A due to conformity with existing project coding styles. Since then I have been impartial to either method.

My choice would be to go with whatever the standard is for the particular language or project, since consistency is paramount.

Rob 12 years, 8 months ago

I prefer B over A.

But honestly as long as it's not C it's okay.

Quote: Iasper
Although I sometimes stack the { and } if they take up to much space.

Kill yourself.