<commit_before>===============
Coding Standard
===============

.. contents:: Table Of Contents
.. section-numbering::

Overview
========

Don't make me think!


Dev Env
=======

- lua
  lua-5.3.2

- mysql

- redis
  redis-3.0.0

Encoding
========

lua file
########

utf-8 without BOM

db table
########

utf-8

request/response
################

utf-8

Lua
===

design
######

- scope and visibility

  variables and functions should be local

  采用“作用域小”优先原则

- prefer array mapping to switch clause

  too many cases is hard to read, but in array, they
  are straightforward.

- var declaration should be closest to its first reference

- lua files all has suffix of '.lua'

  never use like '.inc'

- class only talk to immediate friends
  
  never talk to strangers

- never copy extra variables

  especially when a var is referenced only once

  ::

    // bad
    local desc = ngx.req.get_uri_args()['description'];
    print(desc);

    // good
    print(ngx.req.get_uri_args()['description']);

format
######

- always add a space between the keyword and a operator

  ::

    a = a + 1; // good
    a = a+1;   // bad

- empty line

  - an empty line is reserved for seperation of different logical unit
    
    never overuse empty line

  - between method/function blocks
    
    there will be 1 and only 1 empty line

- indent

  4 spaces

  never use tab

- avoid line over 120 chars

- never use the following tags in file header
  @author

naming
######

- never include data type info in var name

  ::

    int_uid;    // never do like this
    uid;       // do like this

- private var && method all starts with '_'

- camel case names

  used for class name

  ::

    MysqlClient = {}

- lower case connected with underscore names

  used for file name, class name, function name

  ::

    mysql_client.lua
    function do_connect(host, port, timeout) {

- upper case connected with underscore names

  used for constants

  ::

    local DEFAULT_REPLICAS = 64

- do not reinvent an abbreviation unless it is really well known

comment
#######

It's a supplement for the statements, not a repitition.

- never comment out a code block without any comments.

- sync the logic with corresponding comments

  if the logic changes, change it's comment to

- keyword
  FIXME, TODO

- comments are placed directly above or directly right to the code block<commit_msg>missing var nameing<commit_after>===============
Coding Standard
===============

.. contents:: Table Of Contents
.. section-numbering::

Overview
========

Don't make me think!


Dev Env
=======

- lua
  lua-5.3.2

- mysql

- redis
  redis-3.0.0

Encoding
========

lua file
########

utf-8 without BOM

db table
########

utf-8

request/response
################

utf-8

Lua
===

design
######

- scope and visibility

  variables and functions should be local

  采用“作用域小”优先原则

- prefer array mapping to switch clause

  too many cases is hard to read, but in array, they
  are straightforward.

- var declaration should be closest to its first reference

- lua files all has suffix of '.lua'

  never use like '.inc'

- class only talk to immediate friends
  
  never talk to strangers

- never copy extra variables

  especially when a var is referenced only once

  ::

    // bad
    local desc = ngx.req.get_uri_args()['description'];
    print(desc);

    // good
    print(ngx.req.get_uri_args()['description']);

format
######

- always add a space between the keyword and a operator

  ::

    a = a + 1; // good
    a = a+1;   // bad

- empty line

  - an empty line is reserved for seperation of different logical unit
    
    never overuse empty line

  - between method/function blocks
    
    there will be 1 and only 1 empty line

- indent

  4 spaces

  never use tab

- avoid line over 120 chars

- never use the following tags in file header
  @author

naming
######

- never include data type info in var name

  ::

    int_uid;    // never do like this
    uid;       // do like this

- private var && method all starts with '_'

- camel case names

  used for class name

  ::

    MysqlClient = {}

- lower case connected with underscore names

  used for file name, class name, function name

  ::

    local my_str = ''
    mysql_client.lua
    function do_connect(host, port, timeout) {

- upper case connected with underscore names

  used for constants

  ::

    local DEFAULT_REPLICAS = 64

- do not reinvent an abbreviation unless it is really well known

comment
#######

It's a supplement for the statements, not a repitition.

- never comment out a code block without any comments.

- sync the logic with corresponding comments

  if the logic changes, change it's comment to

- keyword
  FIXME, TODO

- comments are placed directly above or directly right to the code block
{'fraction_non_alphanumeric': 0.10696413678065055, 'fraction_numerical': 0.0079232693911593, 'mean_word_length': 2.792094861660079, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1936661', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1395, 'n_words': 603}