c++nlg pearls: xx new to refresh old 知新而后温故

Is this applicable in java? I think so, but my focus here is c++.

— 温故而知新 is less effective at my level. thick->thin, reflective.

— 知新而后温故 — x-ref, thin->thick->thin learning.

However, the pace of learning new knowledge pearls could appear very slow and disappointing. 5% new learning + 95% refresh. In such a case, the main benefit and goal is the refresh. Patience and Realistic expectation needed.

In some situations, the most effective learning is 1% new and 99% refresh. If you force yourself to 2% new and 98% refresh, learning would be less effective.

This technique is effective with distinct knowledge PEARLS. Each pearl can be based on a sentence in an article but developed into a blogpost.


Q: biggest c++dev experiences #$5k DBS

In 2015 I toyed with the outlandish idea of applying for a $5k/M DBS job just to get a hardcore big-project c++ dev experience. Luckily I didn’t get into that job, as such a learning experience would be underwhelming, not enriching.

The criteria for “big” depends on the specific skills (zbs/GTD or IV) you want to demonstrate or learn.

  • If you mean navigation, tracing, build, enhancement, large team BestPractices,,, in a large codebase, then MS is largest, followed by Macq MTS and Macq quant.
  • If you mean substantial source code size that demonstrates data structures, threading,,, then my NYSE integrated feed parser is largest
    followed by my weekend coding interview projects. Mvea is next biggest.

It’s therefore worthwhile to review those weekend projects, mostly hosted in cppProj.

— How about “expert” status? I would say none of these large projects are relevant.

In interviews and online discussions, the acid tests for “expert” is invariably some low-level, theoretical details.

c++TMP^other QQ topics #java

Alexandrescu’s TMP techniques (not “designs”) are very tricky (not “complex”). They require absorbency, but do they enhance latency? Do they get you higher jobs with lower stress?

I need to make time-allocation decisions among QQ topics, including TMP

In terms of latency, Well, java can now rival c++ in latency. The technical reasons are not obvious nor intuitive, but not my focus today. Just an observed fact which discredits conventional wisdom and our assumptions.

— zbs, based on continued relevance :

TMP is needed when reaching next level in c++ zbs.

TMP is more time-honored than many c++0x features.

Many new c++0x features were added for TMP. I feel TMP is the main innovation front across c++ language n standard development. C++ lost many battles in the language war but no other languages offer anything close to TMP features.

— As QQ

Will C++TMP (and rvr) QQ turn out similar to java bytecode engineering, reflection, generics? (Even in such a scenario, TMP still offers better roti than Qz.) Actually TMP is quizzed more than those. The c++ guru interviewers often adore TMP.. cult following.

EJB is an add-on package .. different category, not an advanced core language feature.

When TMP is not quizzed you may still get opportunities to showcase your halo. Many interviewers ask open-ended questions.

TMP techniques would remain a halo for years to come. Classic QQ topic.

— GTD: templates are never needed in greenfield projects. Occasionally relevant in understanding existing code base such as etsflow, STL, boost..

Q: are there rare projects using TMP and offer me an opportunity to outshine others, gain GTD advantage ..?
A: I guess it’s one in 10 or 20. Here are some factors:

Within a given project codebase, TMP is a powerful tool for DRY improvement and re-usability , but such reusability  is over-rated in most projects.

DRY (don’t repeat yourself) is practiced more widely, but I feel TMP techniques replace 100 lines of code duplication with 20 lines of unreadable code.


11 notable features added to c++

https://en.cppreference.com/w/cpp/language/history briefly mentions

  • [90] exception handling
  • [90] templates
  • [98] cast operators
  • [98] dynamic_cast and typeid()
  • [98] covariant return type
  • [07] boost ref wrapper .. see std::reference_wrapper
  • [11] GarbageCollector interface .. See c++ GC interface
  • [11] std::next(), prev(), std::begin(), std::end() .. see favor std::begin(arrayOrContainer)
  • [11] exception_ptr? not sure how useful
  • [14] shared_lock — a RW lock
  • [14] shared_timed_mutex .. see try_lock: since pthreads
  • [14] std::exchange — comparable to std::swap() but doesn’t offer the atomicity of std::atomic_exchange()

new c++features=mostly4lib developers

In C++0x, Half of the major new language features are designed for the standard library developers.

  • The unspoken assumption — these features are equally useful to other library developers.
  • The follow-up assumption — app developers also need to use some (and understand all) of the nitty-gritty details.

In reality, these nitty-gritty details are Not relevant to GTD for app developers.

c++QQ/zbs Expertise: I got some

As stated repeatedly, c++ is the most complicated and biggest language used in industry, at least in terms of syntax (tooManyVariations) and QQ topics. Well, I have impressed many expert interviewers on my core-c++ language insight.

That means I must have some expertise in c++ QQ topics. For my c++ zbs growth, see separate blog posts.

Note socket, shared mem … are c++ ecosystem, like OS libraries.

Deepak, Shanyou, Dilip .. are not necessarily stronger. They know some c++ sub-domains better, and I know some c++ sub-domains better, in both QQ and zbs.

–Now some of the topics to motivate myself to study

  • malloc and relatives … internals
  • enable_if
  • email discussion with CSY on temp obj
  • UDP functions

##10 c++coding habits to optimize perf

Many of these suggestions are based on [[optimized c++]]

· #1 Habit – in c++ at least, ++counter performance is strictly “better or equal to” counter++. If there’s no compelling reason, I would prefer the former.

· #2 Habit – in a for loop, one of the beginning and ending values is more expensive to evaluate. Choose the more expensive one as the beginning value, so you don’t evaluate it over and over. Some people object that compiler can cache the more expensive end value, but 2016 tests show otherwise.

· If a method can be static, then make it static. Good for performance and semantics.

· For a small if-else-if block, put the most likely scenario first. May affect readability. Worthwhile only in a hot spot.

· For a long if-elif-elif-elif-elif block, a switch statement performance is strictly “greater or equal”

· For-loop starts by checking the condition (2nd component in header). If this initial check is redundant (as often is), then use a do-while loop

· Call a loop in a function, rather than call a function in a loop. Another micro-optimization.

##boost modules USED ]finance n asked]IV

#1) shared_ptr (+ intrusive_ptr) — I feel more than half  (70%?) of the “finance” boost usage is here. I feel every architect who chooses boost will use shared_ptr
#2) boost thread
#3) hash tables

Morgan uses Function, Tuple, Any, TypeTraits, mpl

Gregory (RTS) said bbg used shared_ptr, hash tables and function binders from boost

Overall, I feel these topics are mostly QQ types, frequently asked in IV (esp. those in bold) but not central to the language. I would put only smart pointers in my Tier 1 or Tier 2.

—— other modules used in my systems
* tuple
* regex
* noncopyable — for singletons
** private derivation
** prevents synthesized {op= and copier}, since base class is noncopyable.

* polymorphic_cast
* numeric_cast — mostly int types, also float types
* bind?
* scoped_ptr — as non-copyable [1] stackVar,
[1] different from auto_ptr

##some benefits@learning c++, even if no salary increase

  1. After learning c++, i am fairly confident I could if I must pick up c# in a few (4?) months and start passing interviews. C++ is inherently tougher than java and C#. Java and C# both have large libraries, but the core languages are significantly simpler/cleaner than c++.
  2. After learning C++, i have found python and perl easier to understand and master since both are written in C/C++. I now believe some people who claim they could pick up a new language in a few months. Those languages have their roots in C/C++.
    • The basic challenges of scope+namespace, object lifetime, heap/stack, pointers, memory allocation, object construction, pass-by-ref/value, arrays, function pointer, exceptions, nested struct+array+pointer… are faced by every language designer. Many of these challenges depend on basic library, which is invariably C.
    • The common OO challenges of inheritance, virtual, static/non-static, HAS-A/IS-A, constructor, downcast, … are faced by every OO language designer. Many of them borrow from java, which borrows from C++ and smalltalk
  3. threading — java remains the gold standard but c++ currency support is more complex, harder to understand and offers some low-level insight
  4. memory management — c++ offers insight into JVM and CLR
  5. c++ gave me other insight into java, esp. GC, JVM, overriding, references, heap/stack, sizeof, …

##GTD topics for c++ coding drill

After I gain confidence with the basic tasks and move on to higher tasks, i frequently found gaping holes in my foundation. I then face a scary choice. If I admit and shift to the lower gear, I subconsciously feel fake and deeply disappointed with my progress — “after so many years, still at Level 1”. Well, truth is, even after 10 years of java (or c#, SQL or perl) most developers would lack some of the Level 1 skills, because they didn’t need to use them. Basics such as equals/hashCode, wait/notify, interrupt, most basic operations on threads, bigO of collection operations (basic), overriding vs overloading…

— Here are some __coding__ practice areas for GTD (not IV) improvement in c++:
* basic array, pointer/reference, free functions, func pointers. No classes. Plain C
* basic class inheritance, virtual function, new/delete, big3
* string manipulation? understated in books but heavily quizzed.
* basic IO using console and files
* consumption of existing templates. Vast majority of Wall St c++ teams don’t create templates (or design thread constructs). That’s the job of specialists in the bank.
* STL – basic and advanced.
* basic macros including assertion
* a lot of multi-unit compilation topics — much trickier than you think
* static
———-See separate blog posts on the most essential skills with STL

** containers are the real reason to use STL. Iterators and algos are reluctantly adopted.
** remove isn’t common. Add, lookup, find and interation are popular.
** …

–less quizzed
* basic operator overloading
* basic smart pointers

## loaded words in c++ literature

“safety” means exception …
“resource” is always represented by an object on heap (accessed via a pointer).
“life cycle” means destructor
“owner” means deleter of a heapy thingy. Non-heap objects need no owner. Owner has just one job — deletion.

“static” is often used without qualification and by default means the most common/popular static object — the locals
“functor” often includes function pointer, at least in some contexts
The “resource” in RAII means any memory allocated from the heap

master list — home grown c++ jargons

(keep in the this blog …)
* a dummy type name  or a type-param is the T in
* a CONCRETE-template-class is an INSTANCE of a template, with a defined actual type or TYPE-ARG

copy-controls — copier, assignment, destructors. [[c++ primer]]
nonref — a variable that’s not pointer or reference
primitives — primitive types, primitive vars ie non-class types
copier — copy constructor
noarg — the noarg constructor
heapObj — not “heapVar”
lval — lvalue
locals = stackvars — local auto vars
virtuals — virtual methods
pbclone, pbref
mutators, inspectors — non-const and const functions (including “methods”)
getters, setters — methods

## low-level c++(vs java) sys design considerations #1st take

Compared to java architect, a c++ architect needs to worry about more things —

* memory management — avoid double delete, dangling ptr access, leak…
* ptr ownership (who will delete) scheme
* smart ptr — when, where
* copy ctor, op=
* what objects to put on heap ^ stack ^ global
* choose methods ^ static methods ^ free functions
* when to use templates, with the benefit and complexity

##y c++has no Java features like …

* packages? There are. See the book on large scale c++ system
* interfaces? Well, the pure abstract base class in c++ is the best practice for MI.
* VM? i think c++ app runs in a runtime environment just like a Perl script.
* VM threads? i think only the standard OS threads are available? Wrong. See the c++ thread book.
* reflection? RTTI is limited in feature. Python has significantly richer reflection features than compiled languages.