1.C++的用途和意義

總體來說,C++作為一門軟件開發語言,它的流行度是在減少的。主要原因在於語言的復雜和靈活導致軟件開發成本提高,這體現在開發周期和人力上。它不適用於startup公司的快速開發,也不適合用於普通的對性能要求不高的軟件系統中。C++的優勢體現在語言的靈活和對底層的控制,比如內存分配和釋放,和其他硬件的交互能力上,這導致在對性能要求高的系統中它能夠體現價值,在金融業常用於兩類系統,衍生品定價系統(包括風險控制的計算系統),以及低延遲交易系統。這也是為什么金融行業對Quant常常要求C++的原因。因為C++用途的局限,一般建議程序員應多學一些其他語言,如Python, JavaScript, R, Java, Scala等。
- 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.
- 算法和數據結構
對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?
- 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++知識的一小部分。
- 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的其他內容。
- 軟件開發環境
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++!