Jump to content


Photo

Why the 2 syntaxes?


  • Please log in to reply
89 replies to this topic

#1 Experimenator

Experimenator

    Java Developer

  • GMC Member
  • 374 posts
  • Version:GM8

Posted 05 June 2012 - 09:52 PM

It appears to me that GML has 2 code styles mixed up.
For example:
Both of these codes are the same
//Pascal/Delphi
if (a=5 or b<>true and c='lulz') then begin
   show_message('true combination');
   d:=2;
end;
//C/C++
if (a==5 || b!=1 && c=="lulz") {
   show_message("true combination");
   d=2;
};
Same codes in Pascal and C.
But why exactly is this for?
  • 0

#2 Moogle-Girl

Moogle-Girl

    Shipper on Deck

  • GMC Member
  • 249 posts
  • Version:None

Posted 05 June 2012 - 10:11 PM

Probably just to make it more flexible.

Edited by Moogle-Girl, 05 June 2012 - 10:11 PM.

  • 1

#3 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14396 posts
  • Version:GM:Studio

Posted 05 June 2012 - 11:42 PM

Yep, basically it supports almost all language syntax which is fun as no matter were you come from your style/language will work. and it makes copying code from various sources easy.
  • 0

#4 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 7203 posts
  • Version:GM:Studio

Posted 06 June 2012 - 01:57 AM

So that people on the GMC would argue about how you should use == instead of =, and && instead of and.
  • 3

#5 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14396 posts
  • Version:GM:Studio

Posted 06 June 2012 - 02:04 AM

So that people on the GMC would argue about how you should use == instead of =, and && instead of and.


and don't forget != instead of <> they sure love their != over here...
  • 0

#6 ugriffin

ugriffin

    Idiot

  • Global Moderators
  • 1453 posts
  • Version:Mac

Posted 06 June 2012 - 09:22 AM

So that people on the GMC would argue about how you should use == instead of =, and && instead of and.


Oh, I hate people who actually dare correct me when I use = instead of ==. The runner recognises = just fine, and I happen to be a perfectly competent C programmer who knows exactly what == means.

As for the && vs and:

#define and &&

int x=0;
int y=0;

if(x==x and y==y)
{
//Derp
}

Done, C can do 'and' too, no worries.

Whoever actually cares about such trivialities needs to get a new hobby.
  • 2

#7 RedOctober

RedOctober

    GMC Member

  • GMC Member
  • 117 posts
  • Version:GM:Studio

Posted 06 June 2012 - 12:19 PM

So that people on the GMC would argue about how you should use == instead of =, and && instead of and.


And to complain that we cannot use % (using mod instead).
  • 1

#8 Snail_Man

Snail_Man

    Level Builder

  • GMC Member
  • 863 posts
  • Version:GM8.1

Posted 06 June 2012 - 03:18 PM

Do people argue about putting ; at the ends of lines?

Cause I never do that...
  • 0

#9 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 7203 posts
  • Version:GM:Studio

Posted 06 June 2012 - 03:22 PM

Do people argue about putting ; at the ends of lines?

Cause I never do that...

If you use the var statement, you do.
  • 0

#10 Moogle-Girl

Moogle-Girl

    Shipper on Deck

  • GMC Member
  • 249 posts
  • Version:None

Posted 06 June 2012 - 04:52 PM

Whoever actually cares about such trivialities needs to get a new hobby.

Isn't nitpicking (especially about programming syntax) kind of a necessary habit to have if you're into programming? XD

Do people argue about putting ; at the ends of lines?

Cause I never do that...

Here's my opinion on the matter: GML may accept it, but many programming languages don't. It's just pretty handy to get in the habit of sticking semicolons on the end of every line, especially if you plan on learning multiple languages.

Edited by Moogle-Girl, 06 June 2012 - 04:53 PM.

  • 0

#11 kburkhart84

kburkhart84

    GMC Member

  • GMC Member
  • 1618 posts
  • Version:GM:Studio

Posted 06 June 2012 - 05:04 PM

I code the "C++" way with '==' and '&&' and ';' at the end of every line. I believe that the syntax for gml is fine as it is, as long as having this "situation" is not detrimental to the devs that have to code the runners and compilers for it. I don't have handy the post, but it seems like they have said at some point that gml syntax is going to be getting stricter at some point, but it doesn't appear to have happened just yet. Either way is fine by me because it is just another language, and most of you in this topic know that each language has its grammar rules to get used to.

On the other hand, it can be confusing to new people coming in. An example is requiring the semi-colon for var statements, but not requiring it anywhere else....strange.
  • 0

#12 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 2865 posts
  • Version:GM:Studio

Posted 06 June 2012 - 05:14 PM

Nothing is true, Everything is permitted.

GML has no syntax, its a weeeeiird mockup of syntaxes..
  • 0

#13 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14396 posts
  • Version:GM:Studio

Posted 06 June 2012 - 05:51 PM

Whoever actually cares about such trivialities needs to get a new hobby.

Isn't nitpicking (especially about programming syntax) kind of a necessary habit to have if you're into programming? XD

Yes, but the nitpicking should be limited to readability and reliability. The GML multi-syntax support is prone to create confusion when the user switches in the middle... for say a c syntax to a VB syntax.

Do people argue about putting ; at the ends of lines?

Cause I never do that...

Here's my opinion on the matter: GML may accept it, but many programming languages don't. It's just pretty handy to get in the habit of sticking semicolons on the end of every line, especially if you plan on learning multiple languages.


Not really. aside for the var case; Not all languages end a line with ; . When my main languages was c++ and VB, I would put ; at the end of a VB line and I would use = and <> in a c++ line. or == != in the VB code. sometimes the error is was not captured by the compiler and caused me a lot of griefs. Nothing can be done about those human errors.

Today though, I agree with training your mind to a c/java style because that is likely the main languages you will use...
  • 0

#14 Schreib

Schreib

    Valen Shadowbreath

  • GMC Member
  • 1455 posts

Posted 06 June 2012 - 06:00 PM

And if Game Maker didn't allow these bull**** programming styles, I wouldn't have to write hours of extra code. *trollface*

For the purpose of pointing this out, here is a section from the obfuscator code:

	private static void fix****tyProgramming(List<Token> l, int ver) {
		for (int i = 0; i < l.size(); i++) {
			if (l.get(i).getType() == TokenType.FIXCANDIDATE) {
				Token prev = previousNonCommentOrSpaceToken(l, i);
				if (prev != null && prev.getType() == TokenType.IDENTIFIER &&
						!GMNativityUtil.isGMKeyword(prev.getToken(), ver)) {
					insertProperCurlyBrackets(l, i);
				}
			}
		}
	}
	
	private static Token previousNonCommentOrSpaceToken(List<Token> l, int index) {
		Token t = null;
		for (int i = index-1; i >= 0; i--) {
			if (l.get(i).getType() != TokenType.COMMENT) {
				if (!(l.get(i).getType() == TokenType.DELIMITER && 
						l.get(i).getToken().equals(" "))) {
					t = l.get(i);
					break;
				}
			}
		}
		return t;
	}
	
	private static void insertProperCurlyBrackets(List<Token> l, int index) {
		l.add(index, new Token(TokenType.DELIMITER, "{"));
		// strategy: two adjacent identifiers or a semicolon or a } marks end of block
		// knowledge: we already know that every space separates two identifiers
		boolean found = false;
		for (int i = index; i < l.size(); i++) {
			Token t = l.get(i);
			if (t.getType() == TokenType.DELIMITER && (t.getToken().equals(" ") ||
					t.getToken().equals(";") || t.getToken().equals("}"))) {
				l.add(i+1, new Token(TokenType.DELIMITER, "}"));
				found = true;
				break;
			}
		}
		if (!found) {
			l.add(l.size(), new Token(TokenType.DELIMITER, "}"));
		}
	}

Pay special attention to what name I gave the first method there.

Edited by Schreib, 06 June 2012 - 06:02 PM.

  • 2

#15 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 2865 posts
  • Version:GM:Studio

Posted 06 June 2012 - 06:49 PM

hahaha thats lovely, Shreib! :lol:

Edited by Manuel777, 06 June 2012 - 06:49 PM.

  • 0

#16 ugriffin

ugriffin

    Idiot

  • Global Moderators
  • 1453 posts
  • Version:Mac

Posted 06 June 2012 - 06:54 PM

I think Mike said two things regarding GMNext:

1) GMNext will only feature C syntax.
2) GMNext may have a 'strict syntax' mode. Or it may actually have strict syntax.

Good things for anyone who actually cares about syntax. In my opinion, as long as it doesn't interfere with the readability, and as long as the code works, I couldn't care less what syntax is used. That said, I am a fan of C syntax as I believe it's one of the cleanest and fastest to type.
  • 0

#17 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 1415 posts
  • Version:Unknown

Posted 06 June 2012 - 06:55 PM

BTW % and %= made it into the most recent build...


Russell
  • 5

#18 Schreib

Schreib

    Valen Shadowbreath

  • GMC Member
  • 1455 posts

Posted 06 June 2012 - 07:13 PM

There are so many reasons why the loose syntax bothers me. One is automated code reading, like I illustrated above. What that code does above is actually fix an obfuscation problem that occurs when semicolons aren't used. Here's how it works. The stripped code might look like this:

onevar = anothervar obj_carpet.x = something

The obfuscator replaces indices among other things, to

if0f4MFE__=f48_4fj_9if (-5).x=mf894

Now suddenly f48_4fj_9if is treated as a script, syntax error. To fix this, I insert extra curly brackets, but these have to be inserted in a very specific way, to

if0f4MFE__=f48_4fj_9if{(-5).x=mf894}

Just one reason I support strong syntax and maybe even strong typing in GM.
  • 0

#19 ugriffin

ugriffin

    Idiot

  • Global Moderators
  • 1453 posts
  • Version:Mac

Posted 06 June 2012 - 07:18 PM

Just one reason I support strong syntax and maybe even strong typing in GM.


I don't thing there's any need for strong typing. While I am a fan of strong typing (simply because it makes documentation, code, and custom functions more readable), the reality is that scripting languages that Lua and Squirrel don't use it and strong typing would add only another barrier to entry.

That said, I dream of the day when the GM documentation and function hints and all of that becomes more like this:

draw_text(real x, real y, string text);

Instead of what we currently have:

draw_text(x,y,string);

And I'm not sure we need strong typing for that. I'm pretty torn up on it: it simplifies the barrier to entry, but then again all those 'id' arguments where the runner wants some pointer to an object, database, whatever would be so simplified by strong typing.
  • 0

#20 Schreib

Schreib

    Valen Shadowbreath

  • GMC Member
  • 1455 posts

Posted 06 June 2012 - 07:19 PM

Oh, I agree with you. Which is why I'm dubious about the strong typing issue (but not the strong syntax issue). One reason to use Python is to avoid the picky semantics.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users