• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Poor programming habits

S

Shirley White

Guest
Why does GML use a single = in conditional statements like ...
if raining = true

This is a very BAD habit to teach young programmers because when they move on to ANY more complex language like JavaScriob, Java ,C# or C++ (to name a few) they will have to remember that a single = is assignment and a == asks a question.
 

Toque

Member
Just use == then. It’s flexible to whatever works best for you.

I use == as well.

I always wondered why screen 0,0 is top left and not bottom left........
 
Last edited:
B

Bayesian

Guest
The idea is to make it easy for those just starting out. They only need to learn what they need to at the time. It won't be impossible to learn how it works in other languages later if ever

whether you agree with that or not
 

curato

Member
I use == I also put and then on the end and put the curly bracket on the next line. I am addicted to clean self documenting code.

so then:
Code:
if (test == answer)  then
{
      // do a bunch of good stuff with a semicolon at the end because reasons;
}
 

FrostyCat

Redemption Seeker
Why does GML use a single = in conditional statements like ...
if raining = true

This is a very BAD habit to teach young programmers because when they move on to ANY more complex language like JavaScriob, Java ,C# or C++ (to name a few) they will have to remember that a single = is assignment and a == asks a question.
GML doesn't officially sanction single = for comparisons, it only tolerates it for historical reasons (see below).

But I do agree it's an abhorrent habit to teach. Programming is one of few places where forgiveness always exacts a net toll from people who expect it. For instance, take this example of someone trying to write a JS extension without weaning off that habit.

The idea is to make it easy for those just starting out. They only need to learn what they need to at the time. It won't be impossible to learn how it works in other languages later if ever

whether you agree with that or not
Single = for comparisons didn't come from an attempt to be forgiving. It came from an attempt in early versions of GM (legacy 4.x and below) to accommodate both C-style and Pascal-style syntax. C-style syntax uses = for assignments and == for comparisons, while Pascal-style syntax uses := for assignments and = for comparisons. I have posted a more detailed explanation on the old GMC years ago.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
GML is made to be forgiving for new programmers or just relaxed coding
the correct way to do it is
== for comparisons
= for setting

but both work fine for both jobs in GML
 
Last edited:

FrostyCat

Redemption Seeker
GML is made to be forgiving for new programmers or just relaxed coding
the correct way to do it is
== for comparisons
= for setting

but both work fine for both jobs in GML
== certainly doesn't work as an assignment operator in GML.

But I should have expected a statement like this from someone who believes it's GML's job to forgive.
 
Last edited by a moderator:
Q

QatariGameDev

Guest
I totally agree,
It's always better for GML to use the common standard way of programming, Or at least add this to the preferences options (Enable/Disable good programming practice when using GML)
 
G

GM029

Guest
I don't think it's that big of a deal. For anyone moving on to C/JavaScript/Java etc you'll just learn to use == for comparisons. Like others have said though you can use either syntax in GML. GML is flexible in many other ways too. For instance you can use 'and' or '&&'. You can also use 'or' or '||' (I'm also willing to bet it would take '<>' or '!=' for not equal to). I'm sure there are dozens of other flexible coding methods built in.

I grew up programming in Basic which uses a single '=' for both assignment and comparison. It didn't really hinder me in learning other languages like Pascal, C++, Javascript, C# etc.
 
Last edited by a moderator:
D

dannyjenn

Guest
As FrostyCat mentioned, it was originally in there so that programmers could program in a more Pascal-like syntax if they preferred. But I think that's being phased out in favour of the C style... the single equals is still tolerated for compatibility/legacy reasons, but we should use double equals nowadays (I think).

That said, the C syntax is not the programming "standard". While JavaScript, Java, C#, and C++ all use the C syntax, there are a great many other programming languages which do not. And if you're learning to program in a particular language, you're going to need to learn that language's own syntax anyway. Young/inexperienced programmers do need to understand the conceptual difference between assignment and comparison, but it doesn't really matter which syntax they start with. Syntax is rather arbitrary.
 
G

GM029

Guest
I believe you can also either use 'if/then' and 'end if' or if/{ } to encapsulate code in GML.
 
G

GM029

Guest
I agree with dannyjenn. In the end understanding the logic of programming is more important than the differences in syntax.

Most modern programmers need to be able to program in multiple languages, or at least be able to learn them on the fly. Some that have completely different syntaxes from one another.
 
Last edited by a moderator:
Top