当前位置:网站首页>C Pitfalls and pitfalls Appendix B Interview with Koenig and Moo
C Pitfalls and pitfalls Appendix B Interview with Koenig and Moo
2022-08-01 21:05:00 【weixin_Guest time】
Alex Stepanov Hewlett Packard Labs Work A C++ library under development
Submitting STL to the standards committee and recommending its incorporation into the standard library.
On its own, C++ is a very low-level language, and high-level programs can only be written using libraries.Beginners can't construct their own libraries yet, so they either use the off-the-shelf standard library or write low-level programs themselves.There are indeed quite a few programs that should be constructed using low-level techniques, but are not suitable for beginners.
Of course the library is due to language details, for two reasons: First, students don't have to laboriously wrap low-level language details, making it easier to build a global view of the overall language and understand its true power.After students master the truthful use of the library, they will easily understand the concept of classes and learn how to construct classes.
More importantly, learning the library first can enable students to develop a good habit of reusing the library code instead of doing everything by themselves.Students who learn the language details first, tend to end up with a C-style programming style rather than a C++ style.They don't make full use of the library, and their programs are heavily C-minded -- pointers are flying, and the whole program is low-level.The result is that in many cases you pay dearly for the complexity of C++ without gaining any benefit from it.
"C++ Meditations" mentions: "C++ wants to face a community that puts utility first"
"Bad craftsmen often blame their tools?"
"When you haveWhen you hit a hammer, the whole world becomes a nail."
If you choose such a tool, then you are responsible for choosing the right design.
C++ makes a good compromise in runtime performance, striking the right balance between an "everything is an object" language and one that "avoids any abstraction".This is the utility of C++.
The "object-based" and "template-based" abstraction mechanisms take precedence over the object-oriented abstraction mechanism
The so-called object-oriented programming is programming using inheritance and dynamic binding mechanisms.In our opinion, this means that the program has two or more types with at least one common operation and at least one different operation.Otherwise, the inheritance mechanism is not needed.Furthermore, there must be a scenario in the program where one of these types needs to be picked out at runtime, otherwise the dynamic binding mechanism would not be needed.
In some object-oriented programming languages, like Python, all types are dynamic, so technical book authors don't face this problem.For example, container classes in C++ are mostly written in templates, because they can hold objects that have nothing in common, so it makes no sense to require that the element types be derived from a common base class.However, in Python, any object can be placed in a container class, so type mechanisms like templates are unnecessary.
So, I think the problem you're seeing arises from the fact that it's hard to find small, good object-oriented programs to use as examples.Also, C++ can use templates to solve problems that other languages have to wrestle with dynamic typing to solve.
Unless you've mastered the art of constructing well-formed classes in the first place, rushing to study inheritance is a recipe for growth.
"C++ Meditations" "Representing Concepts with Classes" Suppose I can remember one more sentence, what do you think it should be?
"Avoid Duplication" If you find yourself doing the same thing in different parts of your program, try combining the two parts into a subroutine.If you find that two classes behave similarly, try to unify the similar parts of the two classes into a base class or template.
There are two famous sayings in "C++ Meditations": "Class design is language design, and language design is class design"
Python and C++ programs make the perfect pair.Python programs are shorter and more compact than corresponding C++ programs, and C++ programs are much faster than Python runners.So we can construct those performance-critical parts in C++ and glue them together in Python.One of Boost's authors, Dave Abrahams, wrote a nice C++ library that handles the interface between C++ and Python well.
We should remain humble.
Become a better C++ programmer.Please give us your top 3 suggestions:
1. Avoid pointers
2. Promote the use of libraries
3. Use classes to represent concepts
Other works:
Ruminations on C++
Chinese Class Preface
Contents of this book:
Some important lessons in C programming.
Learning method:
1. To become an excellent programmer, the most important thing is to learn the details of a specific programming language, function library or operating system, and the more the better.
2. A well-indexed reference book is enough;
3. At most, a slightly experienced colleague may be needed to point out the direction from time to time;
Learning Difficulty:
The hard part is how to "use the things we already know and use them with one mind".
How to master the difficulties of learning:
1. Learn what should not be done;
2. Study the mistakes of programmers in a language;
Learning style:
For the average person, the most effective way to learn is to learn from perceptual, real-life examples,
such as one's own experience or the lessons of others.
Book Recommendations:
Programming in C: kernighan and Ritchie: The Programming Language, 2nd Edition, Prentice-Hall, 1988
C Reference Manual: Harbison and Steele: C:A Reference Manual, 2nd EditionEdison, Prentice-Hall, 1987
Data Structures and Algorithms: Van Wyk: Data Structures And C Programs, Addison-Wesley, 1988
Portability: Horton: How To Write Protable Program In C, Prentice-Hall,1989
Operating System Interfaces: Kernighan and Pike: The Unix Programming Environment, Prentice-Hall, 1984
Racked C Conundrums: Feuer: The Puzzle Book, Prentice-Hall, 1982
边栏推荐
- Goroutine Leaks - The Forgotten Sender
- C陷阱与缺陷 第7章 可移植性缺陷 7.9 大小写转换
- C陷阱与缺陷 第5章 库函数 5.5 库函数signal
- 职场如象棋,测试/开发程序员如何突破成长瓶颈期?
- C陷阱与缺陷 第7章 可移植性缺陷 7.7 除法运算时发生的截断
- ISC2022 HackingClub white hat summit countdown 1 day!Most comprehensive agenda formally announced!Yuan universe, wonderful!
- 关键字搜索:“淘宝商品 API ”
- C专家编程 第1章 C:穿越时空的迷雾 1.4 K&R C
- 位运算简介
- Goroutine Leaks - The Forgotten Sender
猜你喜欢
随机推荐
Excel advanced drawing techniques, 100 (22) - how to respectively the irregular data
C陷阱与缺陷 第8章 建议与答案 8.2 答案
附录A printf、varargs与stdarg A.3 stdarg.h ANSI版的varargs.h
C陷阱与缺陷 第8章 建议与答案 8.1 建议
C陷阱与缺陷 第5章 库函数 5.5 库函数signal
在Cesium中实现与CAD的DWG图叠加显示分析
win10版本1803无法升级1903系统如何解决
网络安全与基础设施安全局(CISA):两国将在网络安全方面扩大合作
C陷阱与缺陷 第7章 可移植性缺陷 7.11 可移植性问题的一个例子
深拷贝浅拷贝
JSD-2204-Knife4j框架-处理响应结果-Day07
tiup mirror init
响应式织梦模板清洁服务类网站
OSG笔记:设置DO_NOT_COMPUTE_NEAR_FAR,手动计算远近平面
Pytorch学习记录(八):生成对抗网络GAN
数据库单字段存储多个标签(位移操作)
C陷阱与缺陷 第7章 可移植性缺陷 7.8 随机数的大小
系统收集集
C专家编程 第1章 C:穿越时空的迷雾 1.5 今日之ANSI C
使用百度EasyDL实现厂区工人抽烟行为识别