c# log level +! log4net or NLog

I guess c# has builtin support but the log is written to the MSVS output window by default. If you want to also log to a file, you

can add a TextWriterTraceListener

The app.config can contain a TraceLevelSwitch like in DEBUG/INFO/ERROR log levels of log4net. This is probably a runtime change,

since the config can change after compilation.

[ Conditional (“TRACE”) ] also affects the logging, but at compile time.


c# captured var in closures

Local vars may live “beyond” the closing curly bracket. Local struct vars may no longer live on the stack as in java…

Most complicated scenario — local variable declared inside a loop. This is uncommon, considered code smell, and can be avoided. Note for(int index = ….) declares a variable OUTside the loop.

private bank trade/order/quote/execution flow

Remember — Most non-exchange traded products are voice executed. Only a few very dominant, high volume products are electronically executed. Perhaps 1% of the products account for 99% of the trades — by number of trades. By dollar amount, IRS alone is probably 50% of all the trades, and IRS is probably voice-executed, given the large notional amounts.

The products traded between the bank and its clients (not interbank) are often customized private offerings, unavailable from any other bank. (Remember the BofA puttable floats.)

RM / PWA would get live quotes from dealer and give to a client. Sometimes dealer publishes quotes on an internal network, but RFQ is more common. Any time the quote could be executed between RM and client. RM would book the new position into the bank's database. As soon as as executed (before the booking), the bank has a position but dealer knows the position only after the booking, and would hedge quickly.

Dealer initially only responds to RFQ. It's usually executed without her knowledge, just like an ECN flow.

I think in BofA's wealth management platform, many non-equity products (muni bonds are largely sold to retail clients) trade in the same way. Dealer publishes quotes on an intranet website. RM negotiates with client and executes over the phone. During trade booking, the price and quantity would be validated. Occasionally (volatile market), trade fails to go through and RM must inform client to retry. Perhaps requote. Fundamentally, the dealer gets a last look, unlike the exchange flow.

I believe structured products (traded between bank and clients) are usually not fast and volatile — less requote. However, when dealer hedges the position, I think she often uses vanilla instruments.

Terminology warning — some places use “trade” to mean many things including orders. I think in exchange flow, “order” is a precise word.

y learn Trace/Debug classes in dotnet

I believe log4net (and others like NLog) are better than the built-in, but the built-in has one nice feature — In visual studio, the output window conveniently shows the log messages if you use Trace.WriteLine or Debug.WriteLine.

Note output window isn’t the console.

Can log4net write to the output window? See http://angledontech.blogspot.sg/2011/08/direct-log4net-output-to-visual-studio.html. A bit of work. When I start a new project and have no time to set up log4net, then I use Trace/Debug to dump to the output window automatically, by default.

Reason2 – some projects may use the builtin not log4net.

Reason3 – some projects use other logging frameworks, so you may need to learn multiple logging frameworks. If you are lazy and you can decide, then the builtin is a basic solution always available.

y destructors should never throw #le2LinYu

Hi Lin Yu,

You once asked me exactly why destructors should not throw. I just read about it. Compiler would turn a blind eye if your destructor calls some function1 (that in turn calls some function2, that in turn calls some function3 …) that could throw an exception. Over 5 years in production the destructor may not throw, but what happens when it does throw? Maybe nothing bad happens, but maybe one of these things happen

– if the destructor is invoked as part of stack unwinding, then system would probably terminate
– If your object’s destructor has the hidden (destructive) power to throw exceptions, then the STL containers won’t store this object. If you still put this object into an STL container, then I don’t know what happens. Perhaps undefined behavior. If your class is to be used with the STL, then the STL explicitly forbids exception throwing from your class destructor.
– your class can’t be used as member or base-class of another class

Even though the consequence is not documented, the language standard DOES specify when and where destructors should NOT throw. Looks like you might (in theory) get away with an exception thrown from a destructor, but many parts of c++ language do not allow it. In reality, the consequence is probably harmful rather than harmless.

I hope this letter clarifies the issue rather than add to your confusion. Feel free to reply.

Tan Bin

one event delegating to another event – WPF

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090030 shows an interesting mini “pattern” of one event (“event-pseudo-field”) delegating all its add/remove logic to another event (pseudo-field).

public event EventHandler CanExecuteChanged{
  add { CommandManager.RequerySuggested += value; }
  remove { CommandManager.RequerySuggested -= value; }

This reveals the true meaning of an event member. If an object studentA (of class Student) has an event pseudo field evt2, this field is basically a chain of callbacks (or notification targets, or event handlers). The evt2 field is nothing but a handle to add/remove on this chain.

In many cases, the callbacks run sequentially on the same thread as the event-firing code.

See also http://bigblog.tanbin.com/2010/06/field-like-event-syntax-restrictions.html

get class file physical location of a java object #home made

<![CDATA[ private static String getMetaData4Obj(Object o) { return getMetaData4Class(o.getClass()); } private static String getMetaData4Class(Class clazz) { String className = clazz.getName(); className = className.replace(“.”, “/”); className += “.class”; URL location = clazz.getClassLoader().getResource(className); return clazz + ” loaded from ” + location; } ]]>

the q[assembly] concept in dotnet – phrasebook

– An “assembly” sounds like purely logical but no no no it is also a physical File — either an EXE or a DLL, which could be an app

or a lib.

– Access modifier “internal” — is defined for an assembly

– unit of deployment

– unit to be versioned

– qualified type name — 2 assemblies “Soccer” and “Guitar” can both export Player class. The fully qualified Player type is

qualified with the host assembly.

– strong name — special subset of qualified type name


– private unshared assembly – used by 1 app

new MyDlg ^ delegate {} – confusing syntax

1a) equivalent forms:
button.Click += new EventHandler(Method1);
button.Click += delegate { /* the code in the body of Method1 */ }

Action action = new Action(Method5);
Action = delegate (int a) {/* the code in Method5 body */ }

new Thread( new ThreadStart(MyMethod2) );
ThreadStart ts = delegate { /* the code in MyMethod2 */ };
new Thread(ts);

The a) form is useful when an existing method hosting the logic is available. The b) form is useful if you have just a few lines of code and want no method created. In both cases, people often simplify this long-winded coding style. However, if it confuses you then you should use the un-abbreviated form.