c++ - 如何毫不费力地阅读代码

标签 c++ design-patterns

我是专业发展的新手。我的意思是我只有 5 个月的专业发展经验。在此之前,我自己或在大学里研究过它。所以我在查看问题,发现这里有一个关于代码质量的问题。我自己也有一个与此相关的问题。如何提高我的代码理解/阅读能力?它还会提高我将编写的代码质量吗?有比匈牙利语更好的代码表示法吗?有没有关于 C++ 设计模式的真正好书(或者语言无关紧要?)? 提前感谢您回答这些问题并帮助我改进:)

附: - 另外我忘了告诉你我正在使用 C++ 和 C# 语言进行开发。

最佳答案

我发现只有一种方法可以更好地阅读其他人的代码,那就是阅读其他人的代码,当您发现您不理解的方法或语言结构时,请查找并使用它直到您理解为止这是怎么回事。

匈牙利符号很糟糕,今天很少有人使用它,它更像是程序员之间的一个笑话。

事实上,匈牙利符号这个名字本身就是一个笑话:

"The term Hungarian notation is memorable for many people because the strings of unpronounceable consonants vaguely resemble the consonant-rich orthography of some Eastern European languages."

来自 How To Write Unmaintainable Code

"Hungarian Notation is the tactical nuclear weapon of source code obfuscation techniques; use it! Due to the sheer volume of source code contaminated by this idiom nothing can kill a maintenance engineer faster than a well planned Hungarian Notation attack."

而广受欢迎的 linus 对此事有几句话要说。

"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."

- Linus Torvalds

编辑:

取自 Tobias Langner 的评论。

“有关 Apss Hungarian 和 Systems Hungarian 之间的差异,请参阅 Joel on Software”。

Joel on Software 提供了有关如何阅读他人代码的提示,称为 Reading Code is Like Reading the Talmud .

关于c++ - 如何毫不费力地阅读代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1206829/

相关文章:

c++ - 如果A类的成员函数改变了,A类的客户端二进制文件需要重建吗?

c++ - 我应该用 'if' 语句统一两个相似的内核,冒着性能损失的风险吗?

file - 对大型模式文件使用 grep

java - 为什么我要在 switch 语句上使用责任链

java - 在运行时访问对象!

c++ - 如何为未完成的枚举到字符串转换生成编译错误?

C++:使用重载的复合赋值运算符时出现运行时错误

javascript - 如何在网站上实现 "drag n drop"用户界面?

c# - 我如何构建一个包含大量 IF 语句的程序(进程)

c++ - 为什么 OPENFILENAME lpstrFileTitle 参数是 LPSTR 而不是 LPCSTR?