Try   HackMD

開發紀錄 (lab0)

tags: linux2021

contributed by <ianbig>

On Progree

  • Linked List implementation
  • integrate clang-format to vscode

Things to learn in lab0

  • GNU/Linux development tool
    • valgrind
    • Cppcheck
  • linked list
  • makefile
  • git recap (~8 hrs)
  • setjump / longjump
  • computer encoding knowledge

Goal

  • finish cmu lab0
  • use memory tools for qtest

Requirement

special case for NULL

  • null queue: pointer with type queue_t point to null
  • empty queue: member head pointer in type queue_t point to null

make test

coding style

  • use white space over tab
    • the tab have different behavior on different system > but I think is ok, since the system environment is set by users; hence, the behavior must be the most suitable one for them
    • easy for code review on course
  • a line of character < 80 characters
  • switch and case aligned
switch(c): { case 'h': usage(); break; }
  • the position of { and }
if (condition) { ... } else { ... }

for fucntion:

void func(void) { ... }
  • white space
    • usually in linux kernel white space appear after keyword, such as, if, while, do, else, for, switch case
    • But the the following it do not: sizeof, typeof, alignof, attribute
    • add whitespace around some binary operation e.g. = + - < > * / % | & ^ <= >= == != ? :
    • but do not add whitespace around 一元操作符, such as ++, --
  • pointer
    ​​​​ int *intptr; ​​​​ char *func(char *cptr);
  • the naming of variable
    • local variable or function (such as static): be concise
    • global variable of function: be decriptive

git Hooks

commit message

  • why a good commit message is important
    • help other programmers to better understand the logic of project
    • make the process of code review easier
  • what do a good commit message comprised of
    • style: Markup syntax, wrap margins, grammar, capitalization, punctuation
    • content: what information should be included or not included
    • metadata: how tracking issue, pull request numbered be referenced
  • 7 tips for writing commit message
    • Separate subject from body with a blank line
      • this can be useful for some tools (e.g. convert git message to e-mail)
    • Limit the subject line to 50 characters
      • can be 72 character (if subject line > 72, the remaining would be truncated)
    • Capitalize the subject line
    • Do not end the subject line with a period
    • Use the imperative mood in the subject line
      • If applied, this commit will your [subject line here]: this can be a rule of thumb to see whether the commit message is proper
    • Wrap the body at 72 characters
    • Use the body to explain what and why (i.e. focus on why and what, how can be explaned by code)
  • example
Summarize changes in around 50 characters or less

More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.

Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequences of this
change? Here's the place to explain them.

Further paragraphs come after blank lines.

 - Bullet points are okay, too

 - Typically a hyphen or asterisk is used for the bullet, preceded
   by a single space, with blank lines in between, but conventions
   vary here

If you use an issue tracker, put references to them at the bottom,
like this:

Resolves: #123
See also: #456, #789

Learning

Public-key cryptography

  • a.k.a asymmetric cryptography
  • message encrypted by recevier's public key
  • recevier decrypted the public key with its own private key (this can ensure only recevier can decrypted the message)
  • think about symmetry cryptography
    • the key need to be send through a secure channel (very hard to accomplish in the world of web)
  • reference:https://zh.wikipedia.org/wiki/公开密钥加密