y is sphere surface 4pi R^2

Imagine a giant hoop passing through south and north poles. If I build a railroad along the equator and pull the hoop one complete

round, the hoop would have swept the entire surface exactly twice. The hoop perimeter is 2?R or 2? assuming R=1.

Imagine yourself holding one point of the hoop during the sweep. You can further imagine all the people (about 7,000,000,000)

holding on the hoop shoulder to shoulder from North pole to the equator. We would cover a quarter hoop. In one round we would sweep

half the sphere area. Each person's travel path distance will be different. The longest path is the equator — 2?R. At the pole the

sweep path is 0.

Q: what's the average travel among all those people? I think answer turns out to be 4R, which is slightly short of 66.666% of the

equator length.

Q: (To keep this question simpler, we can keep the hoop still.) What's the average distance from the axis? I think it's 2R/?

Advertisements

matrix multiplying – simple, memorable rules

Admittedly, Matrix multiplication is a cleanly defined concept. However, it’s rather non-intuitive and non-visual to many people. There are quite a few “rules of thumb” about it, but many of them are hard to internalize due to the abstract nature. They are not intuitive enough to “take root” in our mind.

I find it effective to focus on a few simple, intuitive rules and try to internalize just 1 at a time.

Rule — a 2×9 * 9×1 is possible because the two “inside dimensions” match (out of the 4 numbers).

Rule — in many multiplication scenarios, you can divide-and-conquer the computation process BY-COLUMN — A vague slogan to some students. It means “work out the output matrix column by column”. It turns out that you can simply split a 5-column RHS matrix into exactly 5 columnar matrices. Columnar 2 (in the RHS matrix) is solely responsible for Column 2 in the output matrix. All other RHS columns don’t matter. Also RHS Column 2 doesn’t affect any other output columns.

You may be tempted to try “by-row”. I don’t know if it is valid, but it’s not widely used.

By-column is useful when you represent 5 linear equations of 5 unknowns. In this case, the RHS matrix comprises just one column.

Rule — Using Dimension 3 as an example,

(3×3 square matrix) * (one-column matrix)  = (another one-column matrix). Very common pattern.

yield-/smile-curves are !! directly related to greeks

The yield curve and smile curve (or surface) are the output of curve fitting engines, calibrated using a lot of commercial market data, discarding outliers. These are the most valuable soft market data objects. Directly used by decision makers, including trade pricing. Each trading desk guards these curves as highly proprietary trading secrets.

However, these curves are imprecise. You shouldn’t compute the gradient at each point on these curves. The most you do with such gradient is computing the gradient at the anchor vol point, which gives you the skew of the entire curve.

In contrast, the price-vs-impliedYield curve and the valuation-vs-spot curve are a different class of curves. (The valuation-vs-impliedVol curve is another example.) I call these “range of possibilities” curves. They are mathematically precise enough to let us compute gradient at every point. You get duration and delta. These are known as sensitivities, essential soft market data for risk management.

python pseudo constructors4everyday tasks

These Python builtin functions have something in common:

* pseudo [1] constructors — manufacture an object of the specified type
* conversion constructors — converting some input value into an object of the specified type

[1] Actually builtin functions rather than ctor. I guess the fine differences between builtin functions, keywords and operators are not that important at this stage.

P64 [[essential ref]] lists these and more, as “type conversion” functions.

– str()
– dict()
– list() — see py list initialize []^list()
– tuple()
– set()
– int()

– file() — very similar to open()

linear independence ^ basis

Let’s use dimension of 3 as a simple example. A 3-dimension space consists of all points in a 3-D coordinate system (real-valued). An address (or point) in this space always has 3 real-valued coordinates – x, y and z. Linear Algebra represents such an address using a column vector
Now, a family of two, there or more vectors can be either linearly independent, or form a basis of this 3-D space, or both (or neither).
LI can be defined this way – using vector linear operations (i.e. addition/scaling) within the family, we can’t express any vector using the sisters. If we can, then one of the vectors can be linearly constructed with the other vectors. In such a case, another family member can also be linearly constructed. There’s plenty of redundancy in the family.
Now Basis (not a definition) – using vector linear operations (i.e. addition/scaling) within the family, we can express _any_ vector in the entire space. In we can, then the family qualifies as a basis of the space, but no redundancy please.
Note, since a basis is a Minimal family, a basis family must be LI. The converse doesn’t hold — A LI family may not form a basis.

event/method pairs in WPF

In learning WPF/Silverlight, I had a few confusions that are similar. These confusions probably fall into the same category. In all cases, one class has both an Event and a Method of a similar name. Here are some cases in point.

Tip: On*** is usually a method

1) Method OnPropertyChanged() vs PropertyChanged event
PC is more fundamental than OPC. PC is heart of the familiar INotifyPropertyChanged interface. As a result, wpf developers (like us) are frequently required to raise PC events explicitly. How do we raise? Often in a non-static OnPropertyChanged() method. So /there you are/, the link between PC and OPC.

http://msdn.microsoft.com/en-us/library/ms743695.aspx is an MSDN tutorial showing exactly this OPC/PC pattern.

The authoritative MSDN documentation http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx shows the same pattern except the OPC method is actually named NotifyPropertyChanged.

OPC is not a standard method name dictated by the framework. It’s more of a method naming convention.

2) This case is found in the commanding infrastructure of WPF. Method CanExecute() vs CanExecuteChanged event. Once the event fires[2] and a command source object [3] gets its callback method invoked[1], that callback method internally calls CanExecute() to check if it should paint itself dimmed.

[1] often on the GUI thread.
[2] (by invoking each callback on the inv list),
[3] (eg button)

delegate instance is passed by value@@

myEvent += myDelegate;

Q: Is myDelegate passed by reference?
A: No. member-wise copying. In other words, each item in the delegate inv list is passed in (by reference?).
A: No. The invocation list (say 2 callbacks) are appended to myEvent’s internal inv list, and new list is ReBound to myEvent internal delegate variable.

That’s a short answer. For the long answer, we need to forget events and callbacks and focus on pure delegates as list objects holding simple “items”. Suppose dlg1 variable points to address1, and dlg2 points to address2.

dlg1 += dlg2 // translates to
dlg1 = Delegate.Combine(dlg1, dlg2). // Note: re-binding dlg1

Now dlg1 points to newly allocated address11. At this address there’s a new-born delegate object whose inv list is

[item1 at addr1,
item2 at addr1 …
itemN at addr1,
item1 at addr2,
item2 at addr2, ….
itemM at addr2]

According to http://msdn.microsoft.com/en-us/library/30cyx32c.aspx, some of the items could be duplicates — Legal.

30 seconds after the Combine() operation, suppose dlg2 is subsequently modified (actually re-bound). Instead of 2 callbacks at addr2, variable dlg2 [1] now points to addr22 with 5 callbacks. However, this modification doesn’t affect the inv list at addr11, which dlg1 now points to.

Therefore, we can safely say that in a Combine() operation the RHS delegate’s inv list is copied-over, passed by value or “pbclone”.

[1] like all java reference variables, a c# delegate variable is a 32-bit pointer object. As explained in
http://bigblog.tanbin.com/2012/03/3-meanings-of-pointer-tip-on-delete.html, the compiler is likely to allocate 32 bit of heap for this 32-bit object.

y java object always allocated on heap, again

Short answer #1: Because java objects are passed by reference.

Suppose a holder object (say a collection, or a regular object holding a field) holds a Reference to a student1 object. If student1 object were allocated on stack, and de-allocated when stack frame unwinds, the holder would hold a stray pointer. Java is allergic to and won’t tolerate a single stray pointer.

Java primitive entities are always passed by value (pbclone). No stray pointer – no pointer involved at all.

Short answer #2: all pbref entities live safer on heap.

How about c# and C++? Somewhat more complicated.

java visitor pattern – overloading vs overriding, again

In standard visitor, you have a hierarchy of visitable data classes (eg Product and 30 subclasses) + a bunch of visitor classes. In
this case, i have just one visitor class, which defines overloaded methods
Visitor.visit(Option)
Visitor.visit(Bond)
Visitor.visit(Futures) etc

Now, I am given a random Product object myProduct. It might be an Option, a Bond, a Futures… but given the multitude of Product
subtypes, it’s too tedious to type-test.

I already have a myVisitor object, so I try calling myVisitor.visit(myProduct). I want it bound to the correct visit() among the
overloads, but guess what — this won’t compile because … (hold your breath)…. there’s no Visitor.visit(Product) defined.

Reason — overloaded method call is resolved at compile time based on declared type of myProduct

Solution — define
abstract Product.accept(Visitor)
Bond.accept(Visitor){v.visit(this);}
Option.accept(Visitor v) {v.visit(this);}

Now, myProduct.accept(myVisitor) would bind the method call to the correct visit(). Why? Well, accept() is resolved at runtime and
binds to Bond.accept() assuming myProduct is a Bond. Inside Bond.accept(), visit(this) is always visit(Bond) — resolved at compile
time like all Overloaded methods.

In conclusion, Visitable.accept(Visitor) is resolved dynamically and Visitor.visit(Visitable) is resolved statically.

What if I create a FriendlyVisitor type? Is accept() dynamic-and-static?

Logging – thread id discovery, parent stack frame discovery

<!– /* Font Definitions */ @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:Consolas; panose-1:2 11 6 9 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-fareast-language:EN-US;} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:"Calibri","sans-serif"; color:windowtext;} .MsoChpDefault {mso-style-type:export-only; font-family:"Calibri","sans-serif"; mso-fareast-language:EN-US;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt;} div.WordSection1 {page:WordSection1;}

Logging showcasing thread id discovery, parent stack frame self-discovery ..
    ///

    /// strictly stateless   
    ///

    class Log
    {
        private static readonly log4net.ILog log4n = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public const string FORMAT_BEGIN = ” vvv   {0}   vvv”;
        public const string FORMAT_CLOSE = ” ^^^   {0}   ^^^”;
        ///

        /// This method conveniently logs to console, IDE output window and log4net
        ///

        ///
        public static void Info(Object o, int levels = 2, bool isStackTraceNeeded = false)
        {
            /*The thread id seen by log4net. According to MSDN:
             * An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host
             * can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host
             * can use the CLR Hosting API to schedule many managed threads against the same operating system thread,
             * or to move a managed thread between different operating system threads.
             */
            var winThrId = AppDomain.GetCurrentThreadId();
            var thId = “/T” + Thread.CurrentThread.ManagedThreadId + “/” + winThrId + “/ “;
            #region locator
            StackTrace stackTrace = new StackTrace(fNeedFileInfo: true);
            var frames = stackTrace.GetFrames();
            StringBuilder locator = new StringBuilder(StackFrameToStr(frames[1]));
            for (int i = 2; i <= levels; ++i)
            {
                if (frames.Length > i)
                {
                    locator.Append(“<-" + StackFrameToStr(frames[i]));
                }
            }
            //if (frames.Length > 2)locator.Append(“<-" + StackFrameToStr(frames[2]));
            var locator2 = “{“ + locator.ToString().Trim() + “} “;
            var msg1 = (o ?? “_nul_”);
            var msg2 = thId + locator2 + msg1;
           

–>

IPC mutex #boost

favorite IV topic

Update — both pthreads mutex and pthreads condVar can be configured as cross-process. Note — both are used for inter-thread coordination. For inter-process, use semaphore.

https://stackoverflow.com/questions/6477525/interprocess-mutex-with-pthreads favors IPC mutex over IPC semaphore.

IPC mutex is supported in many operating systems such as ….?

A mutex in boost::thread is effective only within a single process [1]. To share a mutex between 2 processes, you can use either

A) an anonymous mutex in shared mem managed by your processes

B) a named mutex managed by the kernel (“hotel service desk”). They don’t live in shm. In this case, I guess the mutex is treated like a modem or any other hardware device, whereby any access is regulated by the kernel.

  • In B, the mutex is a boost::interprocess::named_mutex
  • In A, the mutex is a boost::interprocess::interprocess_mutex

If you want recursive,

  • In B, you can use a boost::interprocess::named_recursive_mutex
  • In A, you can use a boost::interprocess::interprocess_recursive_mutex

But Why bother with a shared mutex in the first place? Usually to guard a shared resource such as an object (say object K) in shared mem. By definition K is accessible from 2 (or more) processes P1 and P2. They can both ignore and bypass the mutex and access K directly. Therefore the guardian mutex lock is only advisory.

[1] because the mutex object lives in the private memory of the process

same dealers are behind mutiple mkt-data aggregators

I spoke to a derivative market data vendor’s presales. Let’s just say it’s a lady named AA.

A market data vendor adds value by “calibrating” raw data (quotes, i guess) collected from contributors. AA told me they are NOT purely aggregators.

Before calibration, basic data cleansing would include …. removing outliers.

–Anonymous quotes, Executable quotes and Busted trades —

Some vendors would reveal the contributor identity behind a quote, while other vendors keep their identities confidential. If citi is a dealer/market-maker on a particular instrument, then I guess citi is likely to give more authentic (probably tighter) quotes to the 2nd vendors.

In reality, for a given currency pair or major index (and derivatives thereof), the big dealers are often well known, so in the 2nd case it’s not hard (according to AA) to guess who is behind an anonymous quote.

Whether the contributor/mkt-maker is identified or anonymous, you can’t really trade on the quote without calling them. ECNs provide executable, tradable quotes, whereas mkt data vendors only provide informational or indicative quotes, which aren’t executable. Is the difference a big deal? Probably not. As illustrated in http://bigblog.tanbin.com/2012/07/unlike-exchanges-ecns-have-only-partial.html , unlike regulated exchanges, OTC executable quotes are not truly guaranteed because trade execution happens in dealer’s system not in the ECN since ECN don’t have capital to hold positions. Dealer can reject an order on any “reasonable” ground. In other words, the trade is subject to dealer’s approval. Either the market taker or the dealer can even cancel the trade long after execution, for example due to technical error. On the
exchange, that would be a busted trade and is always initiated and ruled by the exchange — investors have no say.

I suppose busted trades should be clearly justifiable. They are supposed to protect the integrity of the market and maintain investor confidence. It’s like public service. Therefore, they probably happen due to regulator pressure or public pressure.

c# get unique thread id

I find the thread id number typically too low and not “realistic” enough. I am looking for a unique-looking identifier, one which I can search in log files.

Here’s my attempt to get it.

            /*According to MSDN:
             * An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host
             * can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host
             * can use the CLR Hosting API to schedule many managed threads against the same operating system thread,
             * or to move a managed thread between different operating system threads.
             */

            var winThrId = AppDomain.GetCurrentThreadId();
            var thId = “/T” + Thread.CurrentThread.ManagedThreadId + “/” + winThrId + “/ “;

c# log each msg with line number + thread id

This method conveniently logs to console, IDE output window and log4net

It also logs the file name, method name and line number of top 2 levels on the call stack

        public static void Info(Object o, bool isStackTraceNeeded = false)
        {
            /*According to MSDN:
             * An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host
             * can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host
             * can use the CLR Hosting API to schedule many managed threads against the same operating system thread,
             * or to move a managed thread between different operating system threads.
             */
            var winThrId = AppDomain.GetCurrentThreadId();
            var thId = “/T” + Thread.CurrentThread.ManagedThreadId + “/” + winThrId + “/ “;

            #region locator
            StackTrace stackTrace = new StackTrace(fNeedFileInfo:true);
            var frames = stackTrace.GetFrames();

            StringBuilder locator = new StringBuilder(StackFrameToStr(frames[1]));
            if (frames.Length > 2)
                locator.Append(StackFrameToStr(frames[2]));
         
            var locator2 = “{” + locator.ToString().Trim() + “}”;
            var msg = thId + locator2 + (o ?? “_nul_”);
            #endregion

            if (isStackTraceNeeded) msg += “n” + stackTrace;

            log4n.Debug(msg);
            //System.Diagnostics.Trace.Write(“Trace is possible as well.”);
            System.Diagnostics.Debug.WriteLine(msg);
            Console.WriteLine(msg);
            return;
        }

        public static string StackFrameToStr(StackFrame f)
        {
            return Path.GetFileNameWithoutExtension(f.GetFileName()) + “.” + f.GetMethod().Name + “.” +f.GetFileLineNumber() + ” “;
        }
    }

domain ^ range of a given function

Option pricing engine is always implemented in matrices. In the math theory beneath, we encounter the concepts of domain/range of a given function.
 
If I have a function that accepts prime numbers and returns sqroot, then I guess the domain would be a bunch of positive integers and the range would be a bunch of irrationals.

Strictly, a function’s domain is a set; a function’s range is another set.
 

VBA range introspection

Myrange.Column (and Row) is a readonly property of Myrange. Absolute address. Myrange.Column == 2 if “B” is first column of the range.

(It's quite hard to find this tip online!)

Note there's no Cell object in EOM i.e. excel object model. You work with single-cell ranges instead. In VBA lingo, “Cell” or “Cells” are always (part of) property of a range or property of a sheet.

implicit objects in excel object model

In the EOM i.e. excel object model, Fully qualified form is Application.Workbooks(“Book1.xlsx”).Sheets(1).Range(“A3”)

* qq[Application. ] is always optional and implicit
* If the workbook you specified is the Active workbook, then qq[Workbooks(….). ] is optional and implicit
* if the Sheets(1) you specified is the Active sheet, then qq[Sheets(1). ] is optional and implicit

These implicits are good for impatient coders, but bad for newbies. For beginners, it’s safer to always fully qualify these references.

If your VBA code behaves strangely, you can fully qualify all EOM references. If behaviour changes, then your assumptions of the implicits are questionable.

Eg: After sheetA.copy after.workbook8.sheet(3), the active workbook switches from the parent of sheetA to workbook8. This is very implicit and caught me by surprise.

[12] locate]sentence all permutations@99words #dragonSearch

https://leetcode.com/problems/substring-with-concatenation-of-all-words/description/ is very similar

Q1: you are given a list of (possibly repeating) words denoted L that are all the same length , and a long string denoted S. Find a substring of S that is a concatenation of each word in the list exactly once and without any intervening characters. Such a substring is known as a dragon.

To simplify the problem, you can assume it occurs at least once in the sentence.

Example:.
L: “fooo”, “barr”, “wing”, “ding”, “wing”.
S: “lingmindraboofooowingdingbarrwingmonkeypoundcake”.
Answer — fooowingdingbarrwing.

For O(), let’s assume there are H characters in haystack, W characters in each word, and N words (possibly repeating)

Q1b: what if word length is not uniform?

Solution-A — See https://github.com/tiger40490/repo1/blob/py1/py/str/dragonSearch.py with O(HN)

I hope this can be adapted for Q1b — see source comments

Solution-B1 (Brute force) — For each permutation, scan by indexOf() or strstr() or string::find(). Guaranteed to find a solution in finite time. Doable if N is small, since there’s O(N!) element.

Solution-B2 (Brute force) — WN-long sliding window over haystack. Each window is examined to determine if it’s a dragon.

This is reasonable if H is small relative to N.

Solution-C — a potentially faster solution if the list is large — Permutation of 5 would be 120 😦

Phase 1: For each word in the list, i’d count how many times it occurs. The word with lowest occurrence would be a “candidate”.

If every word has the same occurrence (say 3), I think this is still faster than Solution-B, because all but one of the occurrences is a false positive. It’s relatively easy to screen them out.

As soon as I find a word with occurrence=1 exactly, I exit Phase 1 with a super candidate. For this discussion, I assume we have a super candidate.

Updae — In such a case, I can also use the Solution A approach. Even if the best candidate has occurrence = 2 I can consider this approach…

Phase 2a: remove the super candidate from the list. Blindly read the next 4 character in S after our super candidate. See if any word starts with that…..

Phase 2b: do the same leftward. Perhaps by reversing all the strings.

[12]locate]long sentence a permutation of 3 words #src

/* Requirement: you are given a list of words denoted L that are all the same length , 
and a long string denoted S. Find a substring of S that is a concatenation of each 
word in the list exactly once and without any intervening characters. 
This substring is guaranteed to occur exactly once in S.

Showcase how to populate a map containing list,
* without excessive list cloing, and
* without explicit new
Showcase auto keyword
Showcase unordered_multiset
Showcase rbegin()
*/
#include <iostream>
#include <vector>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <memory> // make_shared
#include <string>
using namespace std;

string const S = "barrfooolingmindraboofooowingdingbarrwingmonkeypounddingdingbarrwingfooocake";
vector<string> L{"fooo", "barr", "wing", "ding", "wing"};
unordered_map<string, list<size_t> > lookup; //list of positions where the word appears
unordered_multiset<string> pool; //global variable

template<typename T> ostream & operator<<(ostream & os, list<T> const & l){
  for(auto it = l.begin(); it != l.end(); ++it) os<<*it<<" ";
  os<<endl;
}

shared_ptr<list<size_t> > countOccurrence(string const & word){
  shared_ptr<list<size_t> > ret= make_shared<list<size_t> >();

  for(size_t pos=0, hit=0;;pos=hit+4){
        hit = S.find(word, pos);
        if (hit == string::npos) break;
        ret->push_back(hit);
  }
  return ret;
}
int step( bool isForward){
        return isForward? 4 : -4;
}
char search1way(unsigned int pos2try, bool isForward){
    for(int marker = pos2try+step(isForward); ; marker+=step(isForward)){
        string const & substr4 = S.substr(marker,4);
        //cout<<"substr4 = "<<substr4<<endl;

        //now lets see if the substr is one of our words
        auto itr = pool.find(substr4);
        if (pool.end() == itr) break;
        pool.erase(itr);
        cout<<"found   "<<substr4<<"  at position "<<marker<<". words remain unfound = "<<pool.size()<<endl;
        if (pool.empty())  return 0;
    }
    return 'r' ; //has words remaining in pool;
}
int main(){
  pair<string, int> winner = make_pair("", 9999);
  for(int i=L.size()-1; i>=0; --i){
        string const & word = L[i];
        if (lookup.count(word)) continue;
        shared_ptr<list<size_t> > occ = countOccurrence(word);
        lookup.insert(make_pair(word, *occ));
        if (occ->size() < winner.second) winner = make_pair(word, occ->size());
        cout<<word<<" maps to "<<lookup[word];
  }
  cout<<winner.first<<" has the lowest occurrence = "<<winner.second<<endl;

  list<size_t> const & winnerPos = lookup[winner.first];
  for(auto it = winnerPos.rbegin(); it!=winnerPos.rend(); ++it){
    int pos2try=*it;
    pool = unordered_multiset<string>(L.begin(), L.end());
    pool.erase(pool.find(winner.first)); //guaranteed
    cout<<"trying  "<<winner.first<<"  at position "<<pos2try<<" as the anchor word. Words remain unfound = "<<pool.size()<<endl;
    if (0 == search1way(pos2try, true)) return 0;
    cout<<"searching backward..\n";
    if (0 == search1way(pos2try, false)) return 0;
    cout<<pos2try<<" trial failed :(\n\n";
  }
}

arch xp is overrated as KPI #instrumentation, tools…

See also other blog posts —

// “in the initial dev stage, instrumentation is my #1 design goal”.
// http://bigblog.tanbin.com/2010/09/2-important-categories-of-software.html

Going out on a limb, I’d say that in high-pace projects GTD (Getting Things Done) is more important than many things which are supposed to be more important.

GTD is more important than … integrating deep domain knowledge insight into the system. I think such domain knowledge can sometimes be valuable. It can help dev team avoid wasting time on “the wrong things”.

GTD is more important than … quality of code. For a few months at least, the only guy looking at the code is the original author.

GTD is more important than … “quality of design”, which is seldom well-defined.

GTD is more important than … being nice to others. Many times other people can tolerate a bit of personality if you can GTD. However, you must not offend the people who matter.

GTD is more important than … impressive presentations that address many real customer pains. A user may die for a guy who “understands my pains”, but when it is time to deliver, selling/understanding is an irrelevant distraction.

GTD is more important than … in-depth knowledge of the language or of a software platform/product. Such knowledge is more important than GTD during interviews though. Threading, data structure…

GTD is more important than … uncovering the root casue of (intermittent) problems/errors/surprises — the Toyota drill-down root-cause investigation. Regex engine creator may need to fully characterise every unexpected behavior; AutomateTellerMachine error probably deserve a drill-down investigation but in enterprise apps drill-down investigation simply takes too much time. We developers are paid to build a usable tool, not a fully-understood tool. Live with ambiguity and move on.

GTD is more important than … adding an important test to the automated test suite. Sure that mistake we just found may happen again so we really appreciate adding that test, but in reality, most high-pace environments don’t have an automated test suite. If we are lucky enough to have documented manual test plan, then yes add it, but such a plan seldom is comprehensive, so after a while people won’t follow it religiously. So in reality we just hope developers learn the lesson and avoid making the same mistake. If they do, then we just need someone who can GTD. Any system to incorporate such heard-learned lesson is likely an imperfect system, and whoever investing in such a system is often wasting his/her time.  If a GTD guy doesn’t bother with that system, he will still be respected and loved by manager and users. Basically, any long-term investment is unappreciated. GTD is all about short-term results. This is the reality of quality control in fast-paced teams.

GTD is more important than … adding meaningful error messages. Anyone debugging the system would love the guy who added the meaningful error message, but he is an unsung hero. Manager love the guy who GTD fast. Code quality is invisible and therefore ignored and unrewarded.

To achieve GTD, you must solve tech problems. Tech problems could (occasionally) call for architectural perspective, but less than tool knowledge, debugging experience, or low-level system insight.

In defense of architects, architectural track record is more important in sales contexts, including selling to internal clients and business users.

I should probably get input from Raja, Xiao An, Yi Hai …

q[volatile] in c++ ^ java

Q9: What does volatile mean in C++, precisely? No easily accessible online answer, so let’s not dwell too long.
A9.1 (one of the common answers): it tells compiler to always hit hardware memory, rather than some Software cache. You can verify the assembly generated by compiler. Assembly should show CPU instructions of memory access every time rather than selectively.

Note — Upon executing the instruction, if CPU uses some sort of Hardware-based caching, compiler has no control no knowledge — Compiler did the right thing and volatile is honored.

A9.2: it means the memory location can be updated by hardware so compiler can’t “assume” this process’s threads are the only writers to that memory location. Without this assumption, compiler must always generate cpu instruction to access that memory location, instead of hitting some software cache.

http://www.ibm.com/developerworks/java/library/j-jtp06197.html java Example 3 is a memory location whose content is subject to change by external systems outside the JVM. Even if your system never modifies state of the object, it can change any time.

A9.3 (one of the common short answers): this keyword tells compiler to remove all “optimizations on the variable”, but what are they exactly?

Q10: what are the optimzations? I guess all of them are about memory/caching
A: http://en.wikipedia.org/wiki/Volatile_variable#In_C_and_C.2B.2B shows an example.

Now, A9.1 also applies to java volatile, but java volatile has additional meanings, with concurrency implications. C++ volatile has no such additional. Many authors state that volatile is worthless as a c++ threading construct.

Q: So what is c++ volatile for? Arcane question. In reality, most programmers should not use it, but interviews like c++ volatile, so here we go
%%A: tighter control over access on the memory location behind the target variable.

The primary usage of volatile keyword in java vs c++ are completely different and unrelated.

Q: other differences between java and c++?
A: java volatile is about multiple threads updating a memory location; c++ is about writers outside the current process.
A: in java, volatile keyword creates memory fence/barrier. I think this is similar to the atomic data types in c++.
A: java volatile can only be (static/non-static) fields!
A: java volatile confers atomicity on long/double fields

See also [[c++succintly]] and [[effModernC++]]

fwd class declaration illustrated #C++Succinctly

[[c++succinctly]] has a good illustration of fwd declaration — ClassB.h uses FCD for ClassA, instead of including ClassA.h. ClassA.h happens to include Windows.h.

Does this FCD help classB compilation? No. ClassB.cpp still has to include ClassA.h (and things like Windows.h — even though unneeded.) because the Implementation of ClassB methods would probably [1] need to “unwrap” the ClassA pointers (or ClassA references) to access ClassA members.

[1] otherwise, we may erase ClassA completely from ClassB source code.
Allow me to repeat —
ClassB.h is physically smaller thanks to FCD, but that doesn’t simplify ClassB compilation.

In that case who, if not ClassB, does this FCD help?

A: any class (like ClassK) header files that include ClassB.h.
A: any class (like ClassK) implementation files that include ClassB.h.

Compiling ClassK could be much faster thanks to this single FCD.

So here’s the takeaway — a fwd class declaration of ClassA only helps “grandchild” ClassK and doesn’t help the immediate downstream ClassB.

By the way, as pointed out in [[c++succinctly]] this FCD would be impossible if ClassB.h were to use any nonref variables of ClassA. Nonref means sizeof(ClassA) is needed to compile ClassB.

[[effC++]] goes one step further to introduce pimpl, which is closely related to FCD

MSVS – adding x-proj reference within a solution

Say you are developing Project1. If you refer to stuff in a sister proj (Project “PROJA”) within the same solution, you must include PROJA in Project1’s References. You must see PROJA when you expand [1] Project1’s References list.

 

Now watch out. When you addReference -> Project, you may see PROJA. Now you must click OK. If you click Cancel, you will see PROJA not added to the References list.

 

[1] using that tiny “+” sign