Skip to content

Coding rules and cpplint #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 5, 2016
Merged

Conversation

peterschrammel
Copy link
Member

No description provided.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure why this one is tagged "help", or actually whether there are specific questions that need answers?

- Avoid destructive updates if possible. The irept has
constant time copy.
- Avoid unnecessary #includes, especially in header files
- We allow to use 3rd libraries directly. No wrapper matching the coding rules
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that be 3rd-party libraries (instead of "3rd libraries")?

- Avoid unnecessary #includes, especially in header files
- We allow to use 3rd libraries directly. No wrapper matching the coding rules
is required. Allowed libraries are: C++ standard library.
- No "using namespace std;".
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant with "Do not use namespaces"

is required. Allowed libraries are: C++ standard library.
- No "using namespace std;".
- Use instances of std::size_t for comparison with return values of .size() of
SLT containers and algorithms, and use them as indices to arrays or vectors.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/SLT/STL/

- No "using namespace std;".
- Use instances of std::size_t for comparison with return values of .size() of
SLT containers and algorithms, and use them as indices to arrays or vectors.
- Prohibited stuff from the standard library: ??? TODO!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be prohibited?

@tautschnig
Copy link
Collaborator

Suggestions for further rules:

  • Each function should have a standard comment block above it (all of which should eventually get populated)
  • Headers need to have include guards (`#ifndef CPROVER_.... #define CPROVER_... #endif)

@thk123
Copy link
Contributor

thk123 commented Nov 10, 2016

These are the questions I've had so far on which style is prefered. I don't know if these are too detailed/heavy handed.

A ruling on spacing, e.g. prefer

int x=0;
// or
int x = 0;

Preferred header guard style, e.g.:

#ifndef FILENAME_H
#define FILENAME_H
// ...
#endif // FILENAME_H

Specify whether the override keyword should be used on function declarations.

Should {, } be always used for if, while etc. or not

if(condition)
{
  doSomething();
}
// or:
if(condition)
  doSomething();

@tautschnig
Copy link
Collaborator

Very useful questions, and I'm answering them from having read a lot of code (no right or wrong here, just ruling from majority of cases):

  1. No whitespace around assignment operators
  2. The header-guard style is unfortunately a bit mixed. Personally I would prefer some rule that is easily machine-checkable, such as the full path or containing-directory+file name.
  3. I haven't seen any use of override
  4. Use {...} where necessary or where it makes sense for other reasons, but don't unnecessarily stretch the code vertically.

h) Avoid destructive updates if possible. The irept has
constant time copy.
- Use 2 spaces indent, no tabs.
- No lines wider than 80 chars.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code base, by and large, actually uses 70 chars. Though be sensible about it: don't trade extra-short (and then meaningless) variable names for achieving short lines.

@thk123
Copy link
Contributor

thk123 commented Nov 21, 2016

A couple of other things that have come up from @peterschrammel reviewing my code (apologies Peter if I've misunderstood anything):

When splitting function parameters on to multiple lines (both in headers and in source files), subsequent lines should not be indented to continue from previous line i.e.

No Continuation

void foo(int x, 
  int y, 
  int z);

instead of Continuation:

void foo(int x, 
         int y, 
         int z);

Does anyone know of a way to get QtCreator to do this? As far as I can tell it can either have no indentation or align with the previous line

Full variable names (e.g. symbol_table not st).

Prefer ++i to i++

Use American spellings

Use #if 0 to comment out code

@peterschrammel
Copy link
Member Author

We'll make this machine checkable so that we don't have to comment on most style issues during reviewing anymore.

@peterschrammel
Copy link
Member Author

The integration with travis is working now. The CPP-LINT log is at the end of the log.

@peterschrammel peterschrammel changed the title Refined coding rules (by @trtikm) Coding rules and cpplint Nov 28, 2016
@thk123
Copy link
Contributor

thk123 commented Nov 29, 2016

Is this really what the coding rules suggest?

Old code:

mock_generator.reset(new c_fff_mock_generatort(*message_handler, *e2c,
  symbol_table));

New code:

mock_generator.reset(
  new c_fff_mock_generatort(
  *message_handler,
  *e2c,
  symbol_table));

This code is already accepted by the linter, would this be preferable?

mock_generator.reset(
  new c_fff_mock_generatort(
    *message_handler,
    *e2c,
    symbol_table));

@tautschnig
Copy link
Collaborator

tautschnig commented Nov 29, 2016 via email

@tautschnig
Copy link
Collaborator

@peterschrammel If you could squash my additional commits into your Travis configuration modifications I'd be grateful!

@peterschrammel
Copy link
Member Author

@tautschnig, squashed.

@peterschrammel
Copy link
Member Author

@thk123, as @tautschnig pointed out, the latter version is preferable:

mock_generator.reset(
  new c_fff_mock_generatort(
    *message_handler,
    *e2c,
    symbol_table));

peterschrammel and others added 3 commits November 30, 2016 17:08
The following changes were made:
- admissible source files
- header guards
- do not check order of header files
- no whitespace around =
- operator spacing
- braces on separate lines
- keep access keywords on base column
- allow virtual override
- argument and parameter indent
- types end with t
- fix spaces around && and ||
- no namespace and using
- exclude auto-generated files
@peterschrammel
Copy link
Member Author

@kroening, can we merge this?

@kroening kroening merged commit b4d50d2 into diffblue:master Dec 5, 2016
smowton pushed a commit to smowton/cbmc that referenced this pull request May 9, 2018
Initial version of trace transformer utility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants