Apply standard coding style#2
Conversation
|
@ivucica, I can't request a review in the GitHub UI so I think this mention is a way of doing it. (I do not expect this to be merged immediately or as-is, or ever; it's just a discussion-prompter). |
ivucica
left a comment
There was a problem hiding this comment.
While I like consistency, I am not a huge fan of reformat changes just for the sake of reformatting unless there is a clear benefit or clean standard. The very size of the change (over 3000LOC) says there is no existing expectation of consistency, so while new code should always be consistent, there isn't great benefit in patching existing code.
Having said that -- I don't object greatly either (and as I said I do value consistency). Therefore, I would like to rope in @ericwa as one of the principal authors of Opal to decide.
| : (int[]) advances | ||
| : (size_t)count | ||
| : (int[]) advances | ||
| { |
There was a problem hiding this comment.
This new indentation doesn't seem right and even the fix is not consistent:
: (p)q
: (a)b
: (c) d
There additional cases like this one.
There was a problem hiding this comment.
This is a formatter bug. I'll report it.
| } | ||
| if (t1.b != t2.b) { | ||
| if (t1.b != t2.b) | ||
| { |
There was a problem hiding this comment.
GNU style, the way I understand it, would require two additional spaces before the brace. For example:
if (t1.b != t2.b)
{
return false;
}
```
There was a problem hiding this comment.
Agreed, I would favour doing the GNU style brace indentation.
| } | ||
| else if (nameStruct.platform_id == TT_PLATFORM_MICROSOFT && | ||
| nameStruct.encoding_id == TT_MS_ID_UNICODE_CS) | ||
| nameStruct.encoding_id == TT_MS_ID_UNICODE_CS) |
There was a problem hiding this comment.
I believe this fix is wrong, and the original indentation should be correct. I don't have GNU style guide at hand, so I may be wrong.
There are multiple instances of this.
There was a problem hiding this comment.
I'd agree with @ivucica : for multiline expressions the lines after the first one shouldn't be indented left of the opening paren.
Here's an example in libs-gui:
https://github.com/gnustep/libs-gui/blob/master/Source/NSTextView.m#L1677
There was a problem hiding this comment.
This was another attempt to mimic the prevalent "Opal style" rather than canonical GNU style. This is easily changeable in the formatter config.
| { | ||
| fprintf(stderr,"Cannot open display: %s\n", XDisplayName(NULL)); | ||
| exit(EXIT_FAILURE); | ||
| } |
There was a problem hiding this comment.
The original indentation here is an example of the correct indentation for GNUstep.
|
Hi! Sorry for leaving things in a messy formatting state! I am OK with merging a reformat, but I would suggest aiming for the style used by CoreBase / libs-back / libs-gui, rather than trying to preserve elements of the original Opal style. One question is whether to use tab characters at all; it seems older code in GNUstep does but some newer code doesn't (corebase, e.g. the cairo backend in libs-back). I don't see it mentioned explicitly in https://www.gnu.org/prep/standards/standards.html#Formatting , but the manpage for GNU indent says the default is to use tabs ( Also - I noticed |
Apply a standard coding style for the Opal project, which suffered from terribly deviating styles in a relatively small project. All files were formatted with: > astyle --style=gnu -s2 -xM -S -xP2 -H -xU -xC79 These options preserve the GNU coding standards.
|
I just updated the pull request to contain a reformat which follows the GNU format (or should, at least). There is also a second commit that has the files converted from DOS line endings to Unix. Maybe now we have a better reformat to start discussing. (This time we use Whenever I try using GNU indent Objective-C stuff gets screwed up. That's why I tend to prefer astyle. |
|
|
||
| void CGContextSetGrayStrokeColor(CGContextRef ctx, CGFloat gray, CGFloat alpha); | ||
| void CGContextSetGrayStrokeColor(CGContextRef ctx, CGFloat gray, | ||
| CGFloat alpha); |
There was a problem hiding this comment.
This looks odd, should be 1 argument per line if it won't all fit on one line?
| CGRect bboxes[]) | ||
| { | ||
| return [font getGlyphBBoxes: glyphs : count : bboxes]; | ||
| return [font getGlyphBBoxes: glyphs: count: bboxes]; |
There was a problem hiding this comment.
whoops, formatter got confused by the weird getGlyphBBoxes::: selector name.
| + (NSArray*) destinationClasses; | ||
| + (Class) destinationClassForType: (NSString*)type; | ||
|
|
||
| + (NSArray *)typeIdentifiers; |
There was a problem hiding this comment.
The formatter doesn't seem to standardize the space before the *:
+ (NSArray*) destinationClasses;
+ (NSArray *)typeIdentifiers;
I believe (NSArray *) is the standard format in GNUstep, we could probably do a regex fix if the formatter can't fix this.
| /** Returns the rectangle obtained by translating rect | ||
| * horizontally by dx and vertically by dy. */ | ||
| OP_GEOM_SCOPE CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy) OP_GEOM_ATTR; | ||
| OP_GEOM_SCOPE CGRect CGRectOffset(CGRect rect, CGFloat dx, |
There was a problem hiding this comment.
I just checked libs-gui a bit and the code will go over 80 characers/line when needed to avoid awkward line breaks.
Maybe we should try 100 character columns?
|
@theiostream Any updates in this PR? |
As described in the commit message, apply a standard code style for Opal with the following configurations:
cases inside switch blocksif ()as opposed toif())Unlike other GNUstep projects (Base, GUI, CoreBase), which may not conform fully to a coding style but mostly converge to one, Opal is currently a very big mess when it comes to styles to the point that reading code becomes really hard sometimes. This one I came up with tries to resemble most of the codebase.
If you agree with applying this, I intend on adding a CI build stage which fails the build if AStyle detects a file is outside these constraints.
On a sidenote, I am sure either formatter bugs or a bad config may have generated awkward or worse code in parts of the codebase. But the overall
For purposes of not corrupting the git history with this huge commit, Git provides
git blame -w, which ignores whitespaces from ablamefor debugging purposes.This change is