Q: you said you write code on Windows, but production platform is linux, so how do you test your code?
Q: difference between a C struct and a C++ struct?
Q: have you used memory leak detectors?
Q: How do you link c and c++ code? dlopen()?
Q: have you used memory leak detectors?
Q: scope resolution operator?
Q: default constructor?
Q: what other things are synthesized?
%%A: dtor, copier, op= but c++11 add some move operators
A: indeed, c++11 would synthesize 1) move ctor and 2) move-assignment operator under strict conditions. See http://stackoverflow.com/questions/3734247/what-are-all-the-member-functions-created-by-compiler-for-a-class-does-that-hap
Q: given template<typename T> void f(T a, T b), can f(3, 0.8) compile?
Q: how do you use gdb to view a core file?
Q: write a sqrt(int) function without using the math library. Estimate to 0.01 precision.
Q: UDP vs TCP?
A: virtual circuit. Single remote socket. In contrast UDP can send to multiple receivers efficiently – broadcast or multicast. A: transmission control, with data loss prevention
Q: what’s wrong with multiple inheritance? How do you deal with it?
%%A: diamond problem. I don’t use virtual inheritance. I use MI when base class is an interface without any field.
Q1: how do you create a thread in c++?
A: std::thread is RAII so the constructor starts the thread, and the dtor must run after joining or detaching.
Q1b: Have you used posix_thread?
A: it’s a c library, so no constructor magic. Probably some pthread_something() function. Correct! pthread_create()
An interviewer once asked Q: with some of the c++11/14 features, there’s a concern that c++ is slowly becoming more and more like java and losing its advantage over java. What do you think?
A: I lack the deep insight and expertise and therefore not confident to answer this question, but personally I disagree 90%. Java is a very “clean” language compared to C# and c++ in many ways such as
- Every object is on heap. All custom types are constructed on heap.
- Every object is passed by reference; every primitive is passed by value.
- Non-static method are virtual by default.
- no pointer; no direct access to addresses
- much simpler templates, with type erasure
- higher-level, abstract concurrency constructs
- simpler multiple-inheritance
- strings are immutable
Java /restricts/ us to use a smaller set of higher-level tools, with a reduced level of control and restricted access to the lower level resources such as memory, sockets, kernel … Java is an automatic car, while c++ is a manual race car.
C++ offers a richer toolbox to the programmer. Messier, dirtier and more complex. Many of the power tools are fairly lowLevel. Beside auto_ptr, C++11 doesn’t remove from the toolbox. Therefore, you can use c++11 same way as c++03, OR you can use c++11 more like java.
Q: Is there a trend to use c++ more like java?
A: I notice growing adoption of references (instead of pointers), vector (instead of raw array), std::string (instead of c_str), smart pointer (instead of raw heap pointer) but they have nothing to do with c++11.
We can also examine the key features added to c++11. I think none of them is like java:
- move semantics — not like java at all
- smart pointers
- concurrency — completely different from java
- unordered containers
static methods in interface (SIM for short) is a minor feature of java8, fairly low-level and only interesting to java language students like me.
Two noteworthy points are raised in [[mastering lambdas]] P172 footnote (yes the footnote)
- A “traditional” static method (i.e. defined in a class) is inherited, but SIM is not inherited, Consequently …
- A “traditional” static method can be invoked using myObj.staticMeth1() but SIM can only be invoked using myInterface.staticMeth()
These two restrictions remove “loose” syntax around traditional static methods.
contract work Usually requires less of a struggle with existing codebase. Look at
* 95 Green? all interfacing with existing system is via Ravi, so no struggle at all
* volfitter? the c# codebase was not so well established and not such a struggle. The FMD sheet was a struggle but … expectation was really low.
* reo? I was transferred to BAU projects but expectation was low. * nextgen circuit model bulider – some java code was already there before I joined so I had to understand it — a struggle
In general, high rate contract is usually funded by a development project. Not so much prod support, difficulty laser surgery on a overgrown legacy codebase which require lots of local system knowledge.
– Anyone (even a non-pianist) could teach piano to a kid, but perhaps not correctly;
– Anyone could teach swimming, but Qiu Yi has insight;
– I would guess any medical undergrad could treat patients, guided by a textbook – Management consultants — These guys go by case studies. Not experts in my industry. Why would I listen to them?
– Application design, low or high level, is an art. An inexperienced guy could go by textbooks, but actually, fine judgement needed at every turn.
In Stirt and Macquarie, how fast you get things done is not as important as getting things done right. Managers here are very particular about the details. I think they want things done right and stick to that long term. I can only guess they have seen hasty code that didn’t last, that required massive rework. Example
* the 2 earlier Error Memos coders
* Some of the code in CAOS (account opening)
This is one reason they want older guys with deep experience and strategic insight.
agile – …
coupling – less coupling between client and server, so server side changes are easier. I think SOAP requires client rebuild.
b2b – still dominated by SOAP
resource-oriented services – …
object – each URL logically represents an object, which you can Get (query), POST (create), PUT (update its content) or DELETE
Q: is REST simpler than traditional SOA or SOAP web services?
Q: the concept of “resource” — does it sometimes mean a database record?
I told many of my Singapore techie friends about the US job opportunities. All of them are resistant. They aren’t sure if they can make it in the US.
Indeed among the Indians, Chinese etc, some did succeed and other didn’t.
It’s remarkable that in New York I came across much fewer Singaporeans than Malaysian Chinese, Taiwanese or Hongkongers (and Koreans too, but that’s too different a nation to compare). I feel Singaporeans favor Australia and Britain over US/Canada. I guess largely because of friends and family, the familiar vs. the unknown. Chinese and Indians often settle down in the US and bring over their relatives.
A related factor is the “comfort zone”. Singapore life is too comfortable, too convenient… US is like a buffet dinner – go get it yourself.
Change is uncertain, challenging, requires analysis, observations, opinions, bets … There’s no way to avoid it actually. Change happens to us. Some would say we can take advantage of changes…. think of big data, c++, west coast, python..
In a way, my recent discomfort and dissatisfaction in Singapore is a divine message, and breaks the comfort zone.
One of my growing discomforts in this “comfort zone” is the position/value of specialist vs generalist leader.
Dilip had an elegant solution by hand.
3:15 — MH is at 90 degrees; HH is slightly over 90. It’s 1/4 way towards 120 degrees i.e. 90+7.5 degrees. Therefore, the answer is 7.5 degrees
3.10 — MH is at 60 degrees; HH is slightly over 90. It’s 1/6 way towards 120 degrees, i.e. 95 degrees. Answer is 95 – 6 = 35 degrees.
Note the MH is always at an integer degree but HH can be at a xxx.5 degrees.
For a whitebox coder self-test, it’s tough to come up with real possible corner cases. It takes insight about the many systems that make up the real world. I would argue this type is the #1 most valuable regression tests.
If you see a big list of short tests, then some of them are trivial and simply take up space and waste developer time. So I’m a big fan of the elaborate testing frameworks.
Some blackbox tester once challenged a friend of mine to design test cases for a elevator. Presumably inputs from buttons on each level + in-lift buttons.
Hi Prof Lee,
Thanks for the lunch (including the advice part). I came up with some ideas about this brain teaser —
Q: which is bigger e^pi vs pi^e
One solution I can think of is, suppose e has a value close to 2 and pi is much larger.
Suppose e = 2 and pi = 10. Clearly e^pi wins.
Another way is, define 2 functions
f1(x) = 2.718281828^x and find the growth rate when x is slightly above e. This growth rate is e^x,
f2(x) = x^2.718281828 and find the growth rate when x is slightly above e. This grow rate is e/x * x^e, which is smaller, since x is slightly bigger than e.
Therefore, f1 grows faster than f2, over the range of (e , 3.15). Therefore e^pi wins.
Q: how many days (immersion) do you need to get back to shape for coding interview?
A: a week to 2 months
This question becomes more relevant when you realize your proficiency is way off your peak level achieved x years ago.
xp: I was full time job hunting after layoff from BofA. At the same time Ashish was also trying. He took a few months to get into shape.
Note “shape” doesn’t involve advanced skills. It’s all about basic know-how. Therefore, this goal is a relatively low-hanging fruit and within my reach. Therefore, I feel motivated. I feel (including coding) interview preparation is my favorite sport. I fee like a prize fighter. When I prepare for this, I never feel spinning my wheel as I feel in other endeavors. My spare time utilization is highest in this area. In this area, I can more easily sink my teeth in, engage, and dig in my heels (as in tug-of-war)
- review my eclipse IV code in java and c++. Real code supposed to help memory more.
- review the tricky algo in my blog
- books like [[Elements of Programming Interview]]
- careercup? less ideal than EPI
- paste everywhere tiny stickers with Q&A? less important for pure algo quizzes
- self-tests like gaokao
See also the similar pripri post about “beat us”.
I really don’t care that much about zbs needed in a project:
* the so-called architecture expertise is overrated and overhyped. See my post on
** software architect vs enterprise architect
* the optimization expertise is … similar
Next level requires .. more knowledge. See post on “Yaakov”
Next level requires .. more practice with Facebook algo questions.
Next level requires .. IDE coding against simple problems like codility.
Next level requires .. more mileage with hands-on dev.
Next level requires .. more “best practices” like google style guide
In c++11, a throwing dtor triggers std::terminate(), due to noexcept.
However, std::thread dtor triggers std::terminate() unconditionally, with or without exception, so we need to either detach() or join() on each thread handle object unless main thread runs forever.
Real story — you buy some landed asset which causes pollution. You are liable for the clean-up cost.
Real story — buy a rundown house at a dirty cheap price. Unable to sell, you still need to pay property tax.
[[FRM1]] P127 gave an example of this common failure by risk mgmt department — historical data (even very recent ones) could be misleading and under-report the VaR during a crisis.
I guess it takes unusual insight and courage to say “Historical data exhibits a variance that’s too low for the current situation. We must focus on the last few days/hours of market data.”
[[FRM1]] P126 gave an example to illustrate a common failure of risk mgmt in finance firms. They fail to anticipate that correlation of everything, even correlation between credit risk and mkt risk, will increase during a crisis.
I remember the Goldman Sachs annual report highlighting the correlations between asset classes.
Increased correlation moves the distribution of potential loss, presumably leftward. Therefore a realistic VaR analysis need to factor it in during a crisis.
- regression — beta is named in the context of a regression against the market factor
- cov/var — beta is defined mathematically as this ratio
- excess return — in the regression, both the explanatory variable and the dependent variable are excess returns.
- portfolio — (due to regression) a portfolio beta can be computed from weighted average
above 1 — means the regression slope is steeper than the “market”
equals 1 — is the market itself or any “normal” security
below 1 — means the regression slope is more gentle than the “market”