当前位置:网站首页>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
边栏推荐
- C陷阱与缺陷 附录B Koenig和Moo夫妇访谈
- 15 分钟带你入门 Grafana
- 1374. 生成每种字符都是奇数个的字符串 : 简单构造模拟题
- Goroutine Leaks - The Forgotten Sender
- MySQL语法基础
- STAHL touch screen repair all-in-one display screen ET-316-TX-TFT common faults
- 如何封装 cookie/localStorage/sessionStorage hook?
- 相亲模型与有限状态机
- 图片识别商品接口 API:天猫淘宝
- JS Improvement: Handwritten Publish Subscriber Model (Xiaobai)
猜你喜欢

关于Request复用的那点破事儿。研究明白了,给你汇报一下。

Postman 批量测试接口详细教程

JS提升:手写发布订阅者模式(小白篇)

网红驼背矫正产品真的管用吗?如何预防驼背?医生说要这样做
Godaddy domain name resolution is slow and how to use DNSPod resolution to solve it

乐观锁批量跟新 纯SQL

JS Improvement: Handwritten Publish Subscriber Model (Xiaobai)

MySQL 中出现的字符编码错误 Incorrect string value: ‘\x\x\x\x‘ for column ‘x‘

C专家编程 前言

JS hoisting: how to break the chain of Promise calls
随机推荐
with语句和上下文管理器
任务调度线程池-应用定时任务
进行交互或动画时如何选择Visibility, Display, and Opacity
数据库内核面试中我不会的问题(1)
附录A printf、varargs与stdarg A.3 stdarg.h ANSI版的varargs.h
idea实用快捷键合集——持续更新
Internet使用的网络协议是什么
Questions I don't know in database kernel interview(1)
记录第一次给开源项目提 PR
织梦模板加入php代码
Pytorch框架学习记录10——线性层
Record the first PR to an open source project
StringTable详解 串池 性能调优 字符串拼接
密码学的基础:X.690和对应的BER CER DER编码
测试的意义并不是能找到全部的缺陷
字符串
技能大赛训练:A部分加固题目
tiup mirror genkey
Based on FPGA in any number of bytes (single-byte or multibyte) serial port (UART) to send (including source engineering)
Excel advanced drawing techniques, 100 (22) - how to respectively the irregular data