Pages: [1]
  Print  
Author Topic: Code Formatting  (Read 1957 times)
Offline (Female) IsmAvatar
Posted on: July 23, 2010, 08:10:10 AM

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 891

View Profile Email
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:
Code: [Select]
if(blah){doThis();}
false false:
Code: [Select]
if (blah) {
  doThis();
}

false true:
Code: [Select]
if (blah) {
  doThis();
  }

true false:
Code: [Select]
if (blah)
{
  doThis();
}

true true:
Code: [Select]
if (blah)
  {
  doThis();
  }
Logged
Offline (Male) RetroX
Reply #1 Posted on: July 23, 2010, 03:36:04 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
And other tedious things, such as spaces between operators and if() vs. if ()

Also this:
Code: [Select]
if(stuff)
Code: [Select]
if (stuff)
Code: [Select]
if( stuff )
Code: [Select]
if ( stuff )
And this:
Code: [Select]
int main()
Code: [Select]
int main(void)
« Last Edit: July 23, 2010, 03:50:03 PM by RetroX » Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Unknown gender) score_under
Reply #2 Posted on: July 23, 2010, 03:40:24 PM

Member
Joined: Aug 2008
Posts: 308

View Profile
/vote True False
Logged
Offline (Unknown gender) luiscubal
Reply #3 Posted on: July 23, 2010, 05:29:27 PM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
either false false or true false.
Also, functions with no parameters should be () rather than (void).
Logged
Offline (Female) IsmAvatar
Reply #4 Posted on: July 23, 2010, 06:17:09 PM

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 891

View Profile Email
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).

Quote
And 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/etc
Code: [Select]
if(true)
Code: [Select]
if (true) (does anybody really use False here?)


* Spacing between beginning parenthesis and contents
Code: [Select]
(false)
Code: [Select]
( true) (does anybody really use True here?)

* Spacing between ending parenthesis and contents
Code: [Select]
(false)
Code: [Select]
(true ) (does anybody really use True here?)

** Combined:
Code: [Select]
( true && true )

* Spacing between each argument (after comma)
Code: [Select]
run(false,false)
Code: [Select]
run(true, true)
* Spacing around operators
Code: [Select]
(false|false)
Code: [Select]
(true|true)
« Last Edit: July 23, 2010, 06:21:32 PM by IsmAvatar » Logged
Offline (Male) RetroX
Reply #5 Posted on: July 23, 2010, 09:08:43 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
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
« Last Edit: July 24, 2010, 05:03:35 PM by RetroX » Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Unknown gender) luiscubal
Reply #6 Posted on: July 24, 2010, 02:49:26 PM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
Quote
* Spacing after if/while/etc
I used to write "if(xyz)" without a space...
Logged
Offline (Male) Josh @ Dreamland
Reply #7 Posted on: August 02, 2010, 06:18:09 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
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...
« Last Edit: August 02, 2010, 06:21:39 PM by Josh @ Dreamland » Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) polygone
Reply #8 Posted on: December 06, 2010, 08:03:56 AM

Contributor
Location: England
Joined: Mar 2009
Posts: 809

View Profile
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.
« Last Edit: December 06, 2010, 10:05:54 AM by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) Josh @ Dreamland
Reply #9 Posted on: December 06, 2010, 09:14:13 AM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
Wow, I actually had -not- considered that, polygone. I'll add that to my growing list of ways to boost ENIGMA's notoriety.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: [1]
  Print