C++进阶引导

1.C++的用途和意义


t0185b047e29feffc26.jpg


总体来说,C++作为一门软件开发语言,它的流行度是在减少的。主要原因在于语言的复杂和灵活导致软件开发成本提高,这体现在开发周期和人力上。它不适用于startup公司的快速开发,也不适合用于普通的对性能要求不高的软件系统中。C++的优势体现在语言的灵活和对底层的控制,比如内存分配和释放,和其他硬件的交互能力上,这导致在对性能要求高的系统中它能够体现价值,在金融业常用于两类系统,衍生品定价系统(包括风险控制的计算系统),以及低延迟交易系统。这也是为什么金融行业对Quant常常要求C++的原因。因为C++用途的局限,一般建议程序员应多学一些其他语言,如Python, JavaScript, R, Java, Scala等。

  1. C++入门

C++入门最推荐的书是C++ Primer (注意,不是C++ Primer Plus) ,或者The C++ Programming Language,二者选一即可。读之前最好已经有一点编程的基础,不管什么语言。这些书内容很多,应该侧重于理解概念,而非单纯记忆。重要的概念理解后自然会记住,一些不是很重要的概念一时记不住也没有关系。C++的概念和规则很多,就算是有经验的C++程序员有时也需要google一些语言规则。在这个阶段应该掌握重要的概念。

这一阶段以后可以思考下面这些问题。

Difference between pointer and reference?

i++, ++i, which one is better?

Why use virtual destructor?

What is the signature of a copy constructor/ assignment operator?

How to specialize a class template?

What are the four types of casts in C++? Usage?

etc.

  1. 算法和数据结构

对C++来说,首先要了解Standard Template Library中提供的数据结构的复杂度以及常见的实现。了解各种算法,可以参考算法导论CLRS前17章,Cracking coding interview等书,这些书所采用的语言并不重要,主要是了解算法。Leetcode的easy和median难度的题目可以用来练习。可以思考的问题有:

What does reserve() do on std::vector? What is the complexity of adding element to a std::vector?

Underlying data structure of std::map/std::unordered_map? Implementation outline.

K-way merge sort.

How would you implement atoi and itoa functions?

Max sum subarray problem.

How to compute max drawdown of a price time series?

  1. C++进阶

可以阅读Effective C++, Effective STL, C++ FAQ(website) 和一定编程规模(数千行代码量)的project。只有在Project中才能真正学习。C++ standard library 的实现也是很好的学习工具。它有几个不同的实现,GCC, SGI, Clang等。Clang的实现比较清晰,如果用GCC作为编译器的话了解GCC的实现对有效使用library中的container是很有好处的。对于Quant来说不一定要掌握到这个部分所提到的内容,有兴趣的话可以学习。

这个阶段以后可以思考下面这些问题。

What is strong exception guarantee? Cost of exception handling? Why C++11 deprecate exception specification?

What is type trait?

What is smart pointer? Difference between std::shared_ptr<T> and boost::instrusive_ptr<T>? Implementation outline.

How is virtual function call implemented? What is the cost of virtual function calls? What is CRTP? What is the limitation of that?

What is the runtime cost of a lambda function? What is the cost of std::function compare to a function pointer? *What does std::function gain from that cost?

注1:带*号为难度较大的问题,Quant或初学者可以不在这上面浪费时间

注2:本文所提的思考问题仅是一些有代表性的问题,仅代表C++知识的一小部分。

  1. C++11

C++ Primer第五版已经涉及,另外还有Effective Modern C++. C++11很重要,有很多改进需要了解和掌握,在程序中善于使用。这里举一些比较有代表性的, move sematic, rvalue reference, range based for loop, override keyword, static assert, initializer list, lambda, etc. Boost library的最常用内容已经包含在C++11中,建议先掌握C++11再关注Boost的其他内容。

  1. 软件开发环境

Version control. Git是主流,在老的开发组里可能还在使用SVN或者CVS。这是团队开发必须掌握的工具。

Testing. production code的设计要考虑到其可测试性,所有的代码在release之前都要经过测试。测试的设计,自动化等工作也是需要功夫的。

Build system. 常见的C++ build system有Make, CMake, Automake, scons, Visual Studio等,至少会使用一种。了解Gcc的使用,了解如何使用第三方库。

Debugging/Profiling tool: Valgrind memcheck, Cachegrind, gprof, OProfile, etc.

7.行业相关:衍生品定价系统

这样的系统以计算为核心,需要数值计算,并行计算的知识。现在GPU也比较流行,一般使用nVidia的CUDA. 并行计算也有使用MPI的。另外系统的跨平台特性和其他系统和语言的接口也是开发的要点之一。

8.行业相关:低延迟交易系统

交易系统注重对底层的了解。Memory alignment, multithreading, networking communication, cache friendliness, 如何保证系统的高可靠性,这些都是值得注意和学习的地方。建议学习SEC对Knight Capital trading error事件的调查报告https://www.sec.gov/litigation/admin/2013/34-70694.pdf, 以及SEC对Tower Research RegNMS violation的调查报告http://www.sec.gov/litigation/admin/2015/34-76029.pdf.

学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入学习交流群
639368839,我们一起学C/C++!

原文地址:https://www.cnblogs.com/jiaoyu121/p/6944571.html