code convention - dongwon18/CareRobotBoBi GitHub Wiki

HTML / CSS

javascript

React.js

python

  • PEP8

  • ๋“ค์—ฌ์“ฐ๊ธฐ ์ŠคํŽ˜์ด์Šค 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, ๋ชจ๋“ˆ ๋ ˆ๋ฒจ์—์„œ ์ •์˜

arduino

  • c์™€ ๊ฑฐ์˜ ๋ฌธ๋ฒ•์ด ๋™์ผํ•˜๋ฏ€๋กœ 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

โš ๏ธ **GitHub.com Fallback** โš ๏ธ