code convention - dongwon18/CareRobotBoBi GitHub Wiki
-
NHN ์ฝ๋ฉ ์ปจ๋ฒค์
-
ํญ 2์นธ (๋์ด์ฐ๊ธฐ X ๋ฌด์กฐ๊ฑด ํญ)
-
๋น์ค์ 1์ค๋ง
- Airbnb ์คํ์ผ ๊ฐ์ด๋
- ํญ 2์นธ
- Airbnb ์คํ์ผ ๊ฐ์ด๋
-
๋ค์ฌ์ฐ๊ธฐ ์คํ์ด์ค 4์นธ
-
vscode settings.json์
"[python]": { "editor.defaultFormatter": "ms-python.python" },
์ถ๊ฐํ๊ณ ์ ์ฅ
alt+shift+f
๋ก prettier ๋์์ํค๋ฉดautopep8
๊น์์ผ ํ๋ค๋ ์๋ฆผ์ด ์ค๋๋ฐ ์ด ๋ ์ค์นํ๋ฉด ์ ๋์๋จ -
- ํจํค์ง ์ด๋ฆ์ ์งง์์ผ ํ๊ณ ์๋ฌธ์, _ ์ฌ์ฉ ๋ถ๊ฐ
- ๋ชจ๋ ์ด๋ฆ์ lower_case ๊ฐ๋ฅ
- ํด๋์ค๋ PascalCase
- ํ์
๋ณ์๋ PascalCase
- covariant, contravariatํ ๋ณ์๋ _co, _contra๋ฅผ ๋ค์ ๋ถ์ด๊ธฐ
- ์ ์ญ ๋ณ์๋ ๋ชจ๋ ์์์๋ง ์ฌ์ฉํ๊ธฐ, ํจ์ ์ด๋ฆ ์์ฑ๊ณผ ๋น์ท
- ๋ณ์, ํจ์๋ lower_case
- ์ธ์คํดํธ ๋ฉ์๋ ์ฒ์์ self
- ํด๋์ค ๋ฉ์๋ ์ฒ์ ๋ ๋ฆฝ๋ณ์๋ cls
- ๋ ๋ฆฝ ๋ณ์ ์ด๋ฆ์ด ์ถฉ๋ํ๋ค๋ฉด class_์์ผ๋ก ์ฐ๊ธฐ clss ๊ฐ ์๋๋ผ
- ๋ฉ์๋ ์ด๋ฆ, ์ธ์คํด์ค ๋ณ์๋ lower_case
- ์๋ธ ํด๋์ค๋ ๋ณ์ ์์ __ ๋ถ์ __lower_case
- ์์๋ CAPI_CASE, ๋ชจ๋ ๋ ๋ฒจ์์ ์ ์
- c์ ๊ฑฐ์ ๋ฌธ๋ฒ์ด ๋์ผํ๋ฏ๋ก c์ ์ปจ๋ฒค์ ๋ฐ๋ผ๊ฐ๊ธฐ
-
K&R
-
visual studio์์ ๋๊ตฌ โ ์ต์ โ ํ ์คํธ ํธ์ง๊ธฐ โ C/C++ โ ์์ โ ์ผ๋ฐ โ ๊ธฐ๋ณธ ์์ ์คํ์ผ์ Visual Studio์์ Google๋ก ๋ณ๊ฒฝ
- ์ถ๊ฐ๋ก ํญ ํฌ๊ธฐ๋ ๋ณ๊ฒฝํด์ผ ํจ(2, ๋ค์ฌ์ฐ๊ธฐ, ๊ณต๋ฐฑ ์ฝ์ ์ผ๋ก ํต์ผ)
-
- constant ์์๋ k๋ฅผ ๋ถ์ด๊ณ kPascalCase
- struct ๊ตฌ์ฑ ์์๋ lower_case
- ํจ์ ์ด๋ฆ์ PascalCase
- ์ง์ญ ๋ณ์๋ lower_case
- ์ค์ด ๊ธธ์ด์ ์ฌ๋ฌ ์ค์ ์ธ ๋๋ ๋ ผ๋ฆฌ ์ฐ์ฐ์ ๋ค์์ \n, ์ฒซ ์ค์ ๋ง์ถค
- if ์ธ ๋ ์ด์ ์ return, break, continue ์ผ์ผ๋ฉด ๊ทธ ๋ค์ else ์ฐ์ง ๋ง๊ฒ
- func declare์์ ๊ธธ์ด์ง ๋๋ ์ธ์ ๋ณ๋ก , ๋ค์์ \nํ๊ณ ์ฒซ ์ค์ ๋ง์ถค, ํจ์ ํธ์ถ๋ ๋์ผ, ํจ์ ์ ์๋ ๋์ผ
// Sample file using the Google C++ coding standard.
//
// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
//
// General rules:
// - Indents are two spaces. No tabs should be used anywhere.
// - Each line must be at most 80 characters long.
// - Comments can be // or /* but // is most commonly used.
// - File names should be lower_case.c or lower-case.c
//
// Note: The Google C++ coding standard is a C++ coding standard. There are
// aspects specific to C that the coding standard does not specify, and these
// exceptions are noted below.
#include <stdlib.h>
#include <stdbool.h>
// For macros, use ALL_CAPS separated by underscore:
#define FLAG_FOO 0x0
// If a macro's replacement is not just a literal, enclose it in parentheses:
#define FLAG_BAZ (0x1 << 3)
// For constants, use k followed by PascalCase:
const int kStateFoo = 0;
// Type names should be PascalCase.
// Note: the Google coding standard does not specify how to format a struct
// name that has not been typedef-ed. I am following the lower_case separated
// by underscores format for now but this can be changed later.
typedef struct linked_list LinkedList;
// Enum values can either look like macros:
typedef enum {
MODE_FOO,
MODE_BAR,
MODE_BAZ,
MODE_QUX
} Mode;
// or they can look like contants:
typedef enum {
kStateFoo,
kStateBar,
kStateBaz,
kStateQux
} State;
// Names of members of structs are lower_case and separated by underscores:
typedef struct sample {
int first_field;
bool second_field;
Mode mode;
State state;
struct sample *next;
} Sample;
// Function names are PascalCase. Opening braces come at the end of the last
// line for the function declaration rather than on the next line.
bool SampleEqual(Sample *self, Sample *other) {
// Local variables are lower_case and separated by underscores.
if (self == NULL && other == NULL) {
return true;
}
if (self == NULL || other == NULL) {
return false;
}
// For statements that span multiple lines, break after the logical operator
// and align each line with the start of the first line.
if (self->first_field == other->first_field &&
self->second_field == other->second_field &&
self->state == other->state &&
self->mode == other->mode &&
self->next == other->next) {
return true;
}
// If the previous block ends with areturn (or break or continue), do not
// follow it with an else.
return false;
}
// For function declarations that span multiple lines, then align subsequent
// lines with the first parameter.
Sample *SampleNew(int first_field,
bool second_field,
Mode mode,
State state,
Sample *next) {
Sample *sample = (Sample *) malloc(sizeof(*sample));
if (sample == NULL) {
return NULL;
}
memset(sample, 0, sizeof(sample));
sample->first_field = first_field;
sample->second_field = second_field;
sample->mode = mode;
sample->state = state;
sample->next = next;
return sample;
}
Sample *SampleClone(Sample *sample) {
if (sample == NULL) {
return NULL;
}
// For function calls that span multiple lines, align each subsequent line.
return SampleNew(sample->first_field,
sample->second_field,
sample->mode,
sample->state,
sample->next);
}
// For function declarations (and function calls) where you cannot fit
// the parameters with the first after the opening parentheses, then align
// the parameters indented four spaces on the next line:
static void SampleDoSomethingWithALongName(
Sample *sample,
int parameter_with_a_long_name,
bool another_parameter,
int another_parameter) {
if (sample == NULL) {
return;
}
// else and else if comes after the previous closing brace and not on the
// next line.
bool local_variable;
if (parameter_with_a_long_name == kStateFoo) {
local_variable = true;
} else {
local_variable = false;
}
sample->first_parameter += another_parameter;
sample->second_parameter |= local_variable;
}
last modified on 18 Aug, 2022