Re: [討論] 前輩們變數都怎麼命名?左括號放那?

看板 C_And_Cpp
作者
時間
留言 0則留言,0人參與討論
推噓 0  ( 0推 0噓 0→ )
判斷式的左括號應置於何處? 原Po 研究過 Allman Style , K&R style, GNU style 還有 ISO c99 c++2011 c++2014 c++2022 實際撰寫過 Linux kernel, Zephyr, Android framework & App, Python3 AI Scala Risc-V, IOS .m .mm, trace gcc source 讀了 Weinberg 的程式心裡學 The Psychology of Computer Programming 另有 程序開發心理學 An Introduction to General Systems Thinking // 我們現在使用的 gcc g++ gdb gdbserver 仍至於 arm-linux-gcc aarcg64-linux-gcc 皆是由是 GNU 釋出的 https://ftp.gnu.org/gnu/gcc/ 使用的大括號 與 Allman style 相似就是 放在判斷式的下一行 而Linux kernel 使用的是 K&R style 放在判斷式的末尾 有人會說在下一行好 有人會說在行尾好 很多置定公司的語言規範的人 他們忘了... 1. 主管們 你有在嘗試使用別人的新語法嗎? 2. 制定者 你有在自省 大腦的組合次數 或 簡化次數嗎? 程式語義 在大腦的組合或簡化次數越少 閱讀就更輕鬆 工程師有更多時間 去注重 安全性 速度 CPU loading 不要浪費在畫作的相框 而是畫作本身 在新的python3 之中 根本沒有括號問題 簡化規範 使大腦閱讀輕鬆 才是制定的最高原則 舉三個 語義 1. if you are going to america Then you should get a passport first Check available hotels in California Otherwise if you are going to Japan learn basic greetings Check available hotels in Tokyo 2. if you are going to america Then you should get a passport first Check available hotels in California Otherwise if you are going to Japan learn basic greetings Check available hotels in Tokyo 3. if you are going to america Then you should get a passport first Check available hotels in California Otherwise if you are going to Japan learn basic greetings Check available hotels in Tokyo 對於第1段 我們相當好理解 第3段的中間 我們多組合一次不確定的思考 那現在你應該知道要怎麼放左括號了吧~~~ 這裡是開放性解答 1.了解別人的新寫法 2.反省自身對程式語義的組合次數 3.重視系統安全與Loading 你才是一個好的程式規範者!!! ※ 引述《fatalfeel2 (風在動)》之銘言: : 程式命名規則 與 Makefile : 1. 查閱了 ISO 1999 C99, ISO 2011 C++, ISO 2014 C++, ISO 2020 C++, : https://reurl.cc/gZGz6L : https://reurl.cc/XLGlq0 : ISO都有基本的命名規則 : 另查閱 微軟 安卓 程式規範 : 微軟 的 命名規則偏向 The Hungarian Naming Convention : 由2001 制定完整規範, prefix 如ch, sz, p : https://idleloop.com/hungarian/ : 2. variable prefix naming convention 一定是正確的嗎? : (a) : 北美電網程式規範與openPDC 首席設計師 James Ritchie Carroll : https://www.gridprotectionalliance.org/docs/GPA_Coding_Guidelines_2011_03.pdf : Page 12 原文貼上 : Do not use Hungarian notation : Do not abbreviate : Do not prefix enums, classes, or delegates with any letter : (b) : Linux核心的創始者 開源專案Git創始者 Linus Torvalds : https://www.kernel.org/doc/html/v4.10/process/coding-style.html : https://slurm.schedmd.com/coding_style.pdf : 第四章 原文貼上 : Encoding the type of a function into the name (so-called Hungarian notation) : is brain damaged - the compiler knows the types anyway and can check those, : and it only confuses the programmer. No wonder MicroSoft makes buggy programs. : (注意一下這兩位大神coding在意的重點是什麼) : 3. : GNU MAKE : https://www.gnu.org/software/make/manual/make.html : #dir named with www.gnu.org/software/make/manual/make.html 4.3 16.3 16.5 : SRCDIR = ./source : OBJDIR = ./obj : BINDIR = ./bin : #compile optione with www.gnu.org/software/make/manual/make.html 4.3 16.3 16.5 : $(OBJDIR)/%.o : ./$(SRCDIR)/%.cpp : $(CXX) -c $(CXXFLAGS) $< -o [email protected] : #link : $(TARGET): $(OBJFILES) : $(CXX) $^ $(LDFLAGS) -o $(BINDIR)/[email protected] : 有人習慣使用 : $(CXX) $(LDFLAGS) $^ -o $(BINDIR)/[email protected] : $^ 代表著許多 .o 檔 : $(LDFLAGS)若放在 $^ 前面 : ubuntu 16/18 x86_64 g++ link -lpthread 會找不到 : 所以 "$(LDFLAGS) 一定要放在 $^ 之後" : #Note: CPPFLAGS at www.gnu.org/software/make/manual/make.html 10.3 : CC : Program for compiling C programs; default ‘cc’. : CXX : Program for compiling C++ programs; default ‘g++’. : CPPFLAGS : Extra flags to give to the C preprocessor and programs that use it (the : C and Fortran compilers). : CXXFLAGS : Extra flags to give to the C++ compiler. : ※ 引述《heaviest (heaviest)》之銘言: : : 最近開始學C,剛剛把前幾天寫的程式,打開來看 : : 發現變數一時之間完全搞不清楚 : : 明明當初有盡力的取有意義的名稱,然後照著大寫來分開字這樣打 : : 跑去問了學長,他叫我去背單字,他說變數名字取不出來是我單字被太少QQ : : 請問各位前輩們都怎麼取有意義的名字 --
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.187.102.14 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1679243082.A.FFC.html ※ 編輯: fatalfeel2 (218.187.102.14 臺灣), 03/20/2023 00:27:11