Merge lp:~michihenning/unity-api/astyle into lp:unity-api

Proposed by Michi Henning
Status: Merged
Approved by: Michał Sawicz
Approved revision: 66
Merged at revision: 67
Proposed branch: lp:~michihenning/unity-api/astyle
Merge into: lp:unity-api
Diff against target: 65 lines (+50/-0)
2 files modified
README (+6/-0)
astyle-config (+44/-0)
To merge this branch: bzr merge lp:~michihenning/unity-api/astyle
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
Jussi Pakkanen (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+170468@code.launchpad.net

Commit message

Added astyle-config.

Description of the change

# Options for formatting code with astyle.
#
# This helps to make code match the style guide.
#
# Use like this:
#
# astyle --options=astyle-config mfile.h myfile.cpp
#
# Occasionally, astyle does something silly (particularly with lambdas), so it's
# still necessary to scan the changes for things that are wrong.
# But, for most files, it does a good job.
#
# Please consider using this before checking code in for review. Code reviews shouldn't
# have to deal with layout issues, they are just a distraction. It's better to be able
# to focus on semantics in a code review, with style issues out of the way.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Maybe a "make style" / "make astyle" target for easy invocation?

review: Needs Information
Revision history for this message
Michi Henning (michihenning) wrote :

> Maybe a "make style" / "make astyle" target for easy invocation?

I considered doing this but figured that it probably wouldn't do any good. That's because astyle isn't perfect and occasionally messes with things that are reasonable. So, if I run astyle recursively over the tree, it'll do lots of good things once, which is nice. But if I run it over a tree that's in perfectly good shape, it repeatedly will make the same mess of some things.

If astyle were perfect, I wouldn't hesitate to run it automatically as part of the tool chain. But, unfortunately, it isn't :-(

Revision history for this message
Michał Sawicz (saviq) wrote :

W dniu 20.06.2013 03:17, Michi Henning pisze:
> I considered doing this but figured that it probably wouldn't do any good. That's because astyle isn't perfect and occasionally messes with things that are reasonable. So, if I run astyle recursively over the tree, it'll do lots of good things once, which is nice. But if I run it over a tree that's in perfectly good shape, it repeatedly will make the same mess of some things.

I'm not saying that it should be run on "all" target, but instead of
having to remember the astyle --... command, a quick make would maybe be
used more easily / more often?

We could try and find out the changed files (but then without checking
against :parent branch it would only style whatever wasn't committed yet).

--
Michał Sawicz <email address hidden>
Canonical Services Ltd.

Revision history for this message
Michi Henning (michihenning) wrote :

> I'm not saying that it should be run on "all" target, but instead of
> having to remember the astyle --... command, a quick make would maybe be
> used more easily / more often?

Hmmm... What should "make astyle" in a given directory do?

astyle requires a list of source and header files. If I add --recursive, it also descends into sub-directories.

So, if I'm in src/unity/util, how would I tell astyle to not mess with files that have, say, a lambda in them that might get re-written poorly?

> We could try and find out the changed files (but then without checking
> against :parent branch it would only style whatever wasn't committed yet).

astyle reports which files it touched. But I'm not sure that helps. Suppose there is source file that contains a lambda that gets messed up by astyle. I make a change to the source file, but I also break the style guide somewhere. Now, when I run astyle, it'll fix my broken style, but mess up the lambda.

So, it seems that "make astyle" would repeatedly do damage for some files in a directory, even without --recursive? Or am I missing something else here?

Revision history for this message
Michi Henning (michihenning) wrote :

Any more comments on this? I'm not sure how to progress this.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Fine by me. We can add the target invocation in a different MR. Michał?

review: Approve
Revision history for this message
Michał Sawicz (saviq) wrote :

W dniu 20.06.2013 03:44, Michi Henning pisze:
>> I'm not saying that it should be run on "all" target, but instead of
>> having to remember the astyle --... command, a quick make would maybe be
>> used more easily / more often?
>
> Hmmm... What should "make astyle" in a given directory do?
>
> astyle requires a list of source and header files. If I add --recursive, it also descends into sub-directories.
>
> So, if I'm in src/unity/util, how would I tell astyle to not mess with files that have, say, a lambda in them that might get re-written poorly?
>
>> We could try and find out the changed files (but then without checking
>> against :parent branch it would only style whatever wasn't committed yet).
>
> astyle reports which files it touched. But I'm not sure that helps. Suppose there is source file that contains a lambda that gets messed up by astyle. I make a change to the source file, but I also break the style guide somewhere. Now, when I run astyle, it'll fix my broken style, but mess up the lambda.
>
> So, it seems that "make astyle" would repeatedly do damage for some files in a directory, even without --recursive? Or am I missing something else here?

I thought the other way around - find out which files were changed, and
only run astyle on them. It's obviously problematic when you've already
committed before (we might try and compare against :parent, but that
could be unreliable...).

> Any more comments on this? I'm not sure how to progress this.

> Fine by me. We can add the target invocation in a different MR. Michał?

Yeah, let's.

--
Michał (Saviq) Sawicz <email address hidden>
Canonical Services Ltd.

Revision history for this message
Michał Sawicz (saviq) :
review: Approve
Revision history for this message
Michi Henning (michihenning) wrote :

> I thought the other way around - find out which files were changed, and
> only run astyle on them. It's obviously problematic when you've already
> committed before (we might try and compare against :parent, but that
> could be unreliable...).

Not pretty. Probably more complex than what it is worth. And the problem still remains: if I change a file that contains something that astyle will mess up, I'm screwed even if my style is perfect.

For now, I think it's best to run this as a manual step. People can feed their code through style before proposing the merge, and a quick check with bar diff will tell them whether astyle changed anything that it should have left alone.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2013-06-12 22:07:05 +0000
3+++ README 2013-06-20 00:21:34 +0000
4@@ -211,6 +211,12 @@
5 Things that are dubious in some way with no better solution available
6 are marked with a HACK comment.
7
8+Style
9+-----
10+
11+Consider running astyle over the code before checking it in.
12+See astyle-config for more details.
13+
14
15 Test suite
16 ----------
17
18=== added file 'astyle-config'
19--- astyle-config 1970-01-01 00:00:00 +0000
20+++ astyle-config 2013-06-20 00:21:34 +0000
21@@ -0,0 +1,44 @@
22+# Options for formatting code with astyle.
23+#
24+# This helps to make code match the style guide.
25+#
26+# Use like this:
27+#
28+# astyle --options=astyle-config mfile.h myfile.cpp
29+#
30+# Occasionally, astyle does something silly (particularly with lambdas), so it's
31+# still necessary to scan the changes for things that are wrong.
32+# But, for most files, it does a good job.
33+#
34+# Please consider using this before checking code in for review. Code reviews shouldn't
35+# have to deal with layout issues, they are just a distraction. It's better to be able
36+# to focus on semantics in a code review, with style issues out of the way.
37+
38+--formatted
39+--style=allman
40+--min-conditional-indent=2
41+--indent-switches
42+--max-instatement-indent=80
43+--pad-header
44+--align-pointer=type
45+--align-reference=type
46+--add-brackets
47+--convert-tabs
48+--close-templates
49+--max-code-length=132
50+
51+# --pad-oper
52+#
53+# Commented out for now. It changes
54+#
55+# for (int i=0; i<10; ++i)
56+# to
57+# for (int i = 0; i < 10; ++i)
58+#
59+# Unfortunately, it also messes with rvalue references:
60+#
61+# ResourcePtr& operator=(ResourcePtr&& r);
62+#
63+# becomes:
64+#
65+# ResourcePtr& operator=(ResourcePtr && r);

Subscribers

People subscribed via source and target branches

to all changes: