Questions tagged [google-style-guide]

The Google Style Guide project holds the style guidelines googlers use for Google code.

Every major open-source project has its own style guide: a set of conventions (sometimes arbitrary) about how to write code for that project. It is much easier to understand a large codebase when all the code in it is in a consistent style.

“Style” covers a lot of ground, from “use camelCase for variable names” to “never use global variables” to “never use exceptions.” The Google Style Guide project holds the style guidelines we use for Google code. If you are modifying a project that originated at Google, you may be pointed to its page to see the style guides that apply to that project.

74 questions
6
votes
4 answers

Why does Google name accessors and mutators after member variables?

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Function_Names#Function_Names Regular functions have mixed case; accessors and mutators match the name of the variable: MyExcitingFunction(), MyExcitingMethod(), …
szx
  • 6,433
  • 6
  • 46
  • 67
5
votes
1 answer

Brace on new line only if current line overflows clang format

I've recently decided to include a .clang-format file in a C++ project of mine to make the code more uniform and easy to read. I mostly like the Google defaults, except I'd like to use 4 space indents instead of two. The problem with this is that it…
5
votes
1 answer

Why does the Google C++ Style Guide recommend PascalCase function names?

The Google Style Guide says: Ordinarily, functions should start with a capital letter and have a capital letter for each new word (a.k.a. "upper camel case" or "Pascal case"). For me, Pascal case looks very unfamiliar and I'm very reluctant to…
morxa
  • 3,221
  • 3
  • 27
  • 43
5
votes
1 answer

r 80 character line limit

I've been working on writing readable code and styleguides for work. I'm understand the 80 character line limit suggestion. Occasionally I write a long string of code that becomes less readable if I stick to the 80 character limit. Here is an…
Mitch
  • 652
  • 1
  • 8
  • 14
5
votes
1 answer

Google Style Guide properties for getters and setters

I'm curious about one of the recommendations in the Google Python style guide concerning properties. In it, they give the following example: class Square(object): """A square with two properties: a writable area and a read-only perimeter. …
4
votes
1 answer

Closing over a local value

I read the following in Google's Python styleguide: "Avoid nested functions or classes except when closing over a local value". What does "closing over a local value" mean? The complete relevant section is below: 2.6 Nested/Local/Inner Classes…
Josh
  • 11,979
  • 17
  • 60
  • 96
4
votes
1 answer

Python Google-Style DocString for Function with No Arguments

I've been using the Google-Style Python Docstring format for a while now. The way I've been handling functions/methods with no arguments suddenly doesn't look correct to me. I did a bit of searching and couldn't find anything online that specified…
Eric Le Fort
  • 2,571
  • 18
  • 24
4
votes
1 answer

What are the inherent security vulnerabilities in the header?

The Google C++ style guide section "Other C++ features" contains the following: In addition to what's described in the rest of the style guide, the following C++ features may not be used: Compile-time rational numbers (), because of…
user9723177
4
votes
1 answer

VSCode configure syntax highlighting to match a style guide

How do I change the syntax highlighting in VSCode so that it adheres to a particular style guide? For example, I want to adhere to the Google C++ style guide where member variables are written as some_member_variable_. When I use this convention,…
4
votes
2 answers

Google C++ Style Guide include order

Google C++ Style Guide recommends to include the header files (.h) to the implementation files (.cpp, .cc) in the following order: In dir/foo.cc or dir/foo_test.cc, whose main purpose is to implement or test the stuff in dir2/foo2.h, order your…
αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71
4
votes
1 answer

Why does the Google Style Guide dictates that system headers come before project headers?

In the C++ Google Style Guide's section on headers, the first line says: Use standard order for readability and to avoid hidden dependencies: Related header, C library, C++ library, other libraries' .h, your project's .h. But that appears…
screwnut
  • 1,367
  • 7
  • 26
4
votes
1 answer

How do I correctly install the Google Java Format plugin for IntelliJ IDEA?

I want to install the Google Java Format plugin for IntelliJ IDEA. I have the latest 2016 community edition build (build #IC-163.11103.6, Jan 16th 2017), so version 1.2 of the plugin should be compatible. However, when I try to install it, I get an…
Erik
  • 4,305
  • 3
  • 36
  • 54
4
votes
1 answer

How to use the exclude_files regex in cpplint?

I am using cpplint to check my sourcode agains the google style guide. Cpplint's help says: cpplint.py supports per-directory configurations specified in CPPLINT.cfg files. CPPLINT.cfg file can contain a number of key=value pairs. Currently…
eDeviser
  • 1,605
  • 2
  • 17
  • 44
4
votes
5 answers

Is the "curly braces always should be on the statement line" rule so important?

I understand "semicolon implicit insertion", but I'm not sure it's occurs in case of function expressions. For example, this two expressions always will interpreters equally: Matrix.scale = function (mat, scaleX, scaleY, dest) { // useful…
Microfed
  • 2,832
  • 22
  • 25
3
votes
1 answer

Google Python Style Guide & relative imports

Google Python Style Guide says: Do not use relative names in imports. Even if the module is in the same package, use the full package name. This helps prevent unintentionally importing a package twice. What would be a sample setup that incurs…
Danylo Mysak
  • 1,514
  • 2
  • 16
  • 22