当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Review Set/Map basics with these two hooks
C专家编程 序
C陷阱与缺陷 第5章 库函数 5.5 库函数signal
分类接口,淘宝分类详情 API
列表页常见的 hook 封装
封装一个管理 url 状态的 hook
案例:MySQL主从复制与读写分离
Simple test of the use of iptables
R语言 数据的关系探索
【接口测试】JMeter调用JS文件实现RSA加密
面试官:大量请求 Redis 不存在的数据,从而打倒数据库,有什么方案?
织梦模板加入php代码
仿牛客论坛项目
WeChat applet cloud development | personal blog applet
MySQL Syntax Basics
LeetCode·32.最长有效括号·栈·动态规划
Qt设置应用程序开机自启 解决设置失败原因
C陷阱与缺陷 第7章 可移植性缺陷 7.8 随机数的大小
C语言之字符串函数二
R语言进行相关的操作








