当前位置:网站首页>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
边栏推荐
- Pytorch框架学习记录9——非线性激活
- Transplant MQTT source code to STM32F407 development board
- JSD-2204-Knife4j框架-处理响应结果-Day07
- C专家编程 第1章 C:穿越时空的迷雾 1.2 C语言的早期体验
- Godaddy域名解析速度慢问题以及如何使用DNSPod解析解决
- Classification interface, Taobao classification details API
- 写给刚进互联网圈子的人,不管你是开发,测试,产品,运维都适用
- 仿牛客论坛项目
- Imitation cattle forum project
- 如何封装 cookie/localStorage/sessionStorage hook?
猜你喜欢
随机推荐
Classification interface, Taobao classification details API
Pytorch框架学习记录9——非线性激活
使用员工管理软件,解锁人力生产力新水平,提高人力资源团队灵活性
R语言 线性回归的有关方法
Nacos 配置中心
Simple test of the use of iptables
相亲模型与有限状态机
R语言 pca主成分分析的主要方法
封装一个管理 url 状态的 hook
Pytorch框架学习记录8——最大池化的使用
深拷贝浅拷贝
列表页常见的 hook 封装
SkiaSharp 之 WPF 自绘 五环弹动球(案例版)
Graph adjacency matrix storage
C专家编程 第1章 C:穿越时空的迷雾 1.4 K&R C
和我一起写一个音乐播放器,听一首最伟大的作品
织梦模板加入php代码
OSG Notes: Set DO_NOT_COMPUTE_NEAR_FAR to manually calculate far and near planes
附录A printf、varargs与stdarg A.1 printf函数族
StringTable Detailed String Pool Performance Tuning String Concatenation