Pages: 1
Author Topic: Code Formatting  (54,008 Views)
Offline (Unknown gender) IsmAvatar

LateralGM Developer
LGM Developer
Joined: Apr 2008
Posts: 877
View profile
Posted on: July 23, 2010, 01:10:10 PM
Not to sound lazy, but LGM could really use a code formatter, and since ENIGMA already has a parser, it seems like it'd be a lot easier for ENIGMA to serve that purpose than LGM. Obviously there'd be a few options to specify the format. Right now I think a simple set of post-conditional indentation controls to be the bare essentials.

1) Place first curly bracket on newline?
2) Indent curly bracket(s)?

Needless to say, the code inside the curly brackets would be indented properly without needing to specify an option at this point.

Original heap of junk:
if(blah){doThis();}

false false:
if (blah) {
  doThis();
}


false true:
if (blah) {
  doThis();
  }


true false:
if (blah)
{
  doThis();
}


true true:
if (blah)
  {
  doThis();
  }
Offline (Unknown gender) RetroX

Master of all things Linux
Contributor
Joined: Apr 2008
Posts: 1,055
View profile
Reply #1 Posted on: July 23, 2010, 08:36:04 PM
And other tedious things, such as spaces between operators and if() vs. if ()

Also this:
if(stuff)
if (stuff)
if( stuff )
if ( stuff )

And this:
int main()
int main(void)
Offline (Unknown gender) score_under

Member
Joined: Aug 2008
Posts: 308
View profile
Reply #2 Posted on: July 23, 2010, 08:40:24 PM
/vote True False
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #3 Posted on: July 23, 2010, 10:29:27 PM
either false false or true false.
Also, functions with no parameters should be () rather than (void).
Offline (Unknown gender) IsmAvatar

LateralGM Developer
LGM Developer
Joined: Apr 2008
Posts: 877
View profile
Reply #4 Posted on: July 23, 2010, 11:17:09 PM
There will be no voting, and the second option will not be omitted as false. These are options which are user preferences, meaning that each user will select their desired formatting style from a preferences frame with checkboxes/such. Formatting will only be applied if the user then chooses to format their code. If you get someone else's code and don't like their formatting, you may simply pass it through the formatter with your preferences passed in (which will be remembered between uses).

QuoteAnd other tedious things, such as spaces between operators and if() vs. if ()
Although options could be made of these, I think for now some of these could just be included in the formatter by default. Unless I'm mistaken, I think most people prefer to see "if ()".

If they are made options, we should word them.
Here's my attempt at wording these options:

* Spacing after if/while/etcif(true)if (true) (does anybody really use False here?)


* Spacing between beginning parenthesis and contents(false)( true) (does anybody really use True here?)

* Spacing between ending parenthesis and contents(false)(true ) (does anybody really use True here?)

** Combined: ( true && true )


* Spacing between each argument (after comma)run(false,false)run(true, true)

* Spacing around operators(false|false)(true|true)
Offline (Unknown gender) RetroX

Master of all things Linux
Contributor
Joined: Apr 2008
Posts: 1,055
View profile
Reply #5 Posted on: July 24, 2010, 02:08:43 AM
spacing around if/while is good because they're not functions

most people space && and || no matter what but I don't space anything else; that should be an option as well
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #6 Posted on: July 24, 2010, 07:49:26 PM
Quote* Spacing after if/while/etc
I used to write "if(xyz)" without a space...
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #7 Posted on: August 02, 2010, 11:18:09 PM
A typical formatter can be written without a lex of any sort. I could do this with my style relatively easily. Different settings are plausible as well, without too much hassle, I mean. Currently, ENIGMA's output 'formatter' is a lazy piece of work that outputs it in "sort of legible" format. I keep very few variables, and no stack or anything, so it gets pretty ugly at times. Everything is given a space around it regardless, for example. So we see things like "; i ++ )". But I could pretty easily get the system in general to work for the sole purpose of beautification, if I wrote a new ending segment that simply put everything in a nice format.

Not right now, though. You and I still need to discuss getting that highlighter of yours to recognize my ever-changing function list...
Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
Reply #8 Posted on: December 06, 2010, 01:03:56 PM
What priority is this suggestion at the moment? Because perhaps something people have not fully considered is that if this was implemented it could be very useful for Game Maker also right now. People could open a GM file in LGM, reformat the code then save back as a GM file with nice and neatly formatted code. I know this could be rather useful for people.

Another nice feature would be a DnD to GML converter. You see loads of these being created in GM itself but to have one in LGM would be great. Firstly for those that don't like to use DnD and it exists in a project they could change it all into code very easily. But mainly I see that it could be a great learning tool for DnD users, having the ability to convert from DnD to GML inside project will give them a very nice way of seeing GML equivalents to DnD icons and I believe much aid their learning. Again this could be very useful for Game Maker users right now, regardless of Engima's state.

Adding either of these features could boost the profile of LGM and Enigma within the Game Maker community.
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #9 Posted on: December 06, 2010, 02:14:13 PM
Wow, I actually had -not- considered that, polygone. I'll add that to my growing list of ways to boost ENIGMA's notoriety.
Pages: 1