Indent is pretty nice, because you can specify just about everything one might want to do. And once you are happy with the output, you can save those options in an .indent.pro file and you are set for life...Sven Schüle wrote:I guess you meant:Kempelen wrote:in place of:
Code: Select all
static const int EV_B_SITUACION_CABALLO_NEGRO[64] = { -30, -24, -14, -10, -10, -14, -24, -30, -20, -10, 0, 6, 6, 0, -10, -20, -3, 5, 16, 22, 22, 16, 5, -3, -4, 4, 14, 20, 20, 14, 4, -4, -10, 0, 10, 14, 14, 10, 0, -10, -14, -10, 0, 4, 4, 0, -10, -14, -17, -12, -7, -5, -5, -7, -12, -17, -25, -20, -15, -12, -12, -15, -20, -25 };
Code: Select all
static const int EV_B_SITUACION_CABALLO_NEGRO[64] = { -30, -24, -14, -10, -10, -14, -24, -30, -20, -10, 0, 6, 6, 0, -10, -20, -3, 5, 16, 22, 22, 16, 5, -3, -4, 4, 14, 20, 20, 14, 4, -4, -10, 0, 10, 14, 14, 10, 0, -10, -14, -10, 0, 4, 4, 0, -10, -14, -17, -12, -7, -5, -5, -7, -12, -17, -25, -20, -15, -12, -12, -15, -20, -25 };
Personally, I prefer not to use any tool other than a text editor for this task ... Using a stylizer (beautifier, ...) tool may have some advantages but it must fit your needs "really perfect", otherwise you end up fixing all those annoying exceptions again and again, each time you run it over all your sources. I don't know any such tool, and in fact I never missed it.Kempelen wrote:This is always annoying.
How do you stylize code to avoid this things? do you have any other stylizing tips?
So my advice would be: always write your code in its "final" layout from the beginning, then you won't need a beautifier tool for later "postprocessing".
Sven
Stylizing code
Moderators: hgm, Rebel, chrisw
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Stylizing code
-
- Posts: 1434
- Joined: Wed Apr 21, 2010 4:58 am
- Location: Australia
- Full name: Nguyen Hong Pham
Re: Stylizing code
I am interested about this. However, I think there is no simple solution:Kempelen wrote:Hello,
I use AStyle for stylizing my code. I suppose many here use it too. But I have a problem with array initialization, like PSTs. It always show wrong:
in place of:Code: Select all
static const int EV_B_SITUACION_CABALLO_NEGRO[64] = { -30, -24, -14, -10, -10, -14, -24, -30, -20, -10, 0, 6, 6, 0, -10, -20, -3, 5, 16, 22, 22, 16, 5, -3, -4, 4, 14, 20, 20, 14, 4, -4, -10, 0, 10, 14, 14, 10, 0, -10, -14, -10, 0, 4, 4, 0, -10, -14, -17, -12, -7, -5, -5, -7, -12, -17, -25, -20, -15, -12, -12, -15, -20, -25 };
This is always annoying.Code: Select all
static const int EV_B_SITUACION_CABALLO_NEGRO[64] = { -30, -24, -14, -10, -10, -14, -24, -30, -20, -10, 0, 6, 6, 0, -10, -20, -3, 5, 16, 22, 22, 16, 5, -3, -4, 4, 14, 20, 20, 14, 4, -4, -10, 0, 10, 14, 14, 10, 0, -10, -14, -10, 0, 4, 4, 0, -10, -14, -17, -12, -7, -5, -5, -7, -12, -17, -25, -20, -15, -12, -12, -15, -20, -25 };
How do you stylize code to avoid this things? do you have any other stylizing tips?
- in technique, astyle has to know little bit about grammar instead of some line states only. It also needs to scan the code at least twice to beautify some above lines based on bellow lines. Thus if the program is designed for scanning code only one, there is no hope for new improvement in coming time
- there is no standard about style of an array
- we seem to have different ideas about code beauty of an array. the "price" for it may not be cheap
For example, I am not sure if all have the same acceptant level about the below code:
Code: Select all
int64 array1[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 430, 0, 0,
0, 0, 0, 0, 60, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 456548098090
};
int64 anotherStylingArray2[] = { // will be crazy if you have double columns
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 430, 0, 0,
0, 0, 0, 0, 0, 0, 0, 456548098090
};
-
- Posts: 620
- Joined: Fri Feb 08, 2008 10:44 am
- Location: Madrid - Spain
Re: Stylizing code
I am looking into indent tool, recommendad bad Bob, it is great at first view, and you can hand format one time this arrays and tell the program not format then only adding 2 lines of codes as the sample put by bob.phhnguyen wrote:I am interested about this. However, I think there is no simple solution:Kempelen wrote:Hello,
I use AStyle for stylizing my code. I suppose many here use it too. But I have a problem with array initialization, like PSTs. It always show wrong:
in place of:Code: Select all
static const int EV_B_SITUACION_CABALLO_NEGRO[64] = { -30, -24, -14, -10, -10, -14, -24, -30, -20, -10, 0, 6, 6, 0, -10, -20, -3, 5, 16, 22, 22, 16, 5, -3, -4, 4, 14, 20, 20, 14, 4, -4, -10, 0, 10, 14, 14, 10, 0, -10, -14, -10, 0, 4, 4, 0, -10, -14, -17, -12, -7, -5, -5, -7, -12, -17, -25, -20, -15, -12, -12, -15, -20, -25 };
This is always annoying.Code: Select all
static const int EV_B_SITUACION_CABALLO_NEGRO[64] = { -30, -24, -14, -10, -10, -14, -24, -30, -20, -10, 0, 6, 6, 0, -10, -20, -3, 5, 16, 22, 22, 16, 5, -3, -4, 4, 14, 20, 20, 14, 4, -4, -10, 0, 10, 14, 14, 10, 0, -10, -14, -10, 0, 4, 4, 0, -10, -14, -17, -12, -7, -5, -5, -7, -12, -17, -25, -20, -15, -12, -12, -15, -20, -25 };
How do you stylize code to avoid this things? do you have any other stylizing tips?
- in technique, astyle has to know little bit about grammar instead of some line states only. It also needs to scan the code at least twice to beautify some above lines based on bellow lines. Thus if the program is designed for scanning code only one, there is no hope for new improvement in coming time
- there is no standard about style of an array
- we seem to have different ideas about code beauty of an array. the "price" for it may not be cheap
For example, I am not sure if all have the same acceptant level about the below code:
Code: Select all
int64 array1[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 430, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 456548098090 }; int64 anotherStylingArray2[] = { // will be crazy if you have double columns 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 430, 0, 0, 0, 0, 0, 0, 0, 0, 0, 456548098090 };
-
- Posts: 1434
- Joined: Wed Apr 21, 2010 4:58 am
- Location: Australia
- Full name: Nguyen Hong Pham
Re: Stylizing code
It is good that you have a solution for your code!
For me, I am very lazy to add any lines just for styling. I also don't want to explain them later for other people. Both code formatted by astyle and code with adding those lines are not perfect and at same annoying level.
Thus I will accept any thing a beautifier can do.
For me, I am very lazy to add any lines just for styling. I also don't want to explain them later for other people. Both code formatted by astyle and code with adding those lines are not perfect and at same annoying level.
Thus I will accept any thing a beautifier can do.
-
- Posts: 5106
- Joined: Tue Apr 29, 2008 4:27 pm
Re: Stylizing code
I may have to look at indent again. I tried to use it years ago and it immediately was confused by my commenting style. I remember that it balked on '/** ...' and the issue was that it was looking for just '/*' followed by a space or newline. I could not work around it and I figured it was useless to me if before I even started I had to go through the entire code base and start modifying it.bob wrote: Indent is pretty nice, because you can specify just about everything one might want to do. And once you are happy with the output, you can save those options in an .indent.pro file and you are set for life...
I'm sure that bug has been fixed by now ...
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Stylizing code
Don wrote:I may have to look at indent again. I tried to use it years ago and it immediately was confused by my commenting style. I remember that it balked on '/** ...' and the issue was that it was looking for just '/*' followed by a space or newline. I could not work around it and I figured it was useless to me if before I even started I had to go through the entire code base and start modifying it.bob wrote: Indent is pretty nice, because you can specify just about everything one might want to do. And once you are happy with the output, you can save those options in an .indent.pro file and you are set for life...
I'm sure that bug has been fixed by now ...
It works fine, although I don't like the syntax. but if you want to use that, it won't cause any problems. Just indented this to test:
/****** comment ******/
int f(int v) {
if (v >= 0.0)
return 0;
else
return 1;
}
And I get the same thing as the final result.
-
- Posts: 319
- Joined: Fri Dec 18, 2009 11:40 am
- Location: Naperville, IL
Re: Stylizing code
ಠ_ಠbob wrote:int f(int v) {
if (v >= 0.0)
-
- Posts: 5106
- Joined: Tue Apr 29, 2008 4:27 pm
Re: Stylizing code
bob wrote:Thanks, I will check it out again then.Don wrote:I may have to look at indent again. I tried to use it years ago and it immediately was confused by my commenting style. I remember that it balked on '/** ...' and the issue was that it was looking for just '/*' followed by a space or newline. I could not work around it and I figured it was useless to me if before I even started I had to go through the entire code base and start modifying it.bob wrote: Indent is pretty nice, because you can specify just about everything one might want to do. And once you are happy with the output, you can save those options in an .indent.pro file and you are set for life...
I'm sure that bug has been fixed by now ...
It works fine, although I don't like the syntax. but if you want to use that, it won't cause any problems. Just indented this to test:
/****** comment ******/
int f(int v) {
if (v >= 0.0)
return 0;
else
return 1;
}
And I get the same thing as the final result.
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Stylizing code
That was code used during the great "0.0" debate. I just added a "Don format" comment at the top to make sure indent didn't crap out...UncombedCoconut wrote:ಠ_ಠbob wrote:int f(int v) {
if (v >= 0.0)