ewanwilcox.com

October 29, 2008

WFT: The most pointless C# interface….ever?

Filed under: C# — ewilcox @ 7:27 pm

For the life of me I can’t see the point of this interface. Any ideas anyone?


public interface BaseKey

{

string ToString();
bool Equals(object obj);
int GetHashCode();

}

Just to add insult to injury the one class that for some reason chooses to implement this interface has probably the worst Equals method implementation I’ve ever seen:


public bool Equals(object obj)

{

if(obj == null)
return false;

if(GetType() != obj.GetType())
return false;

return true;

}

I’ll post again when I’ve stopped crying…

October 27, 2008

Catching the bottom of the FTSE

Filed under: Market and financial comment — admin @ 9:00 pm

With markets plummeting, the pound getting…pounded and panic gripping investors you would have thought that the best strategy would be to hide under a stone somewhere. History suggests however that when everyone is running for the hills is actually the time to start considering investing. Its called bottom fishing or “catching the bottom”. Its also known as trying to catch a falling knife if you get it wrong!

So what do I feel about the bottom and where it will be for the FTSE? Well if I look back to the 2000/01 downturn I have to think that this is more serious and therefore the bottom will be lower still. Top to bottom the FTSE fell from 6500 to 3200 odd. At its last peak this time it was 6800 and now stands at around 3900. Given this I’m afraid I think there is further to fall - maybe down to 2500 or so by the middle of next year as the recession bites (which it surely will). Do I actually think this would represent good value though? Well absolutely. I simply don’t believe that the investment and growth we enjoyed in the last five years really has vanished. Yes there was a boom but as the commentator in the Times said over the weekend - “the pendulum will swing too far in the opposite direction”. At around 3000 the FTSE is a definite long term buy. You heard it here first…. ;)

Credit crunched

Filed under: Uncategorized — admin @ 8:17 pm

I feel credit crunched. I am in a (new ish) job, I am decently paid and certainly not down to my last £10. I have paid my bills, have few debts and I could, if really pushed, survive for some time on some savings and I certainly would like to think my seven odd years of IT in the city stand me in good stead for getting a new job. Yet I found myself in a shop yesterday mulling up buying a new toy for home. Under normal circumstances I probably woudn’t have even paused for thought before buying it - it was only maybe £150 - but as it was I found myself asking myself: “Do I need this?”. I didn’t buy it and realised walking home that the reason was because I felt “crunched” and frankly prefered to have the money in the bank. I am probably one of the lucky ones out there so here’s the question - f I am feeling this how on earth are the rest of the country feeling?

October 26, 2008

Come on merv…

Filed under: Market and financial comment — Tags: , , — admin @ 9:53 pm

Picture this if you will. You are the govenor of the bank of englad and you have to make a speech to senior business leaders. The economy is fragile, investor confidence is shot and the people are looking at you for some guidance and reassurance. Do you:

a) Stand up and say there are challenging times ahead but you believe the UK economy is in excellent shape and will bounce back or

b) Stand up and admit the economy is in recession.

So hands up - who went for b? Well thats what Mervyn King did last week and he was heavily punished for it. Stock markets plunged (again) and sterling got pounded losing the most in years. Well done Merv. Have you never heard the adage - confidence breeds confidence?

Actually I’m being a little unfair here. His comments were stupid and ill timed but nowhere near the priceless quote from the head of the IMF who said recently said the “world economy was…teetering on the brink of systemic meltdown”. That’s not just stupid thats downright irresponsible.

C# Locking

Filed under: C# — admin @ 4:21 pm

Locking is an essential part of mastering multithreading in C#. Locking enables two or more threads to safely use objects without one accidentally affecting the other. For example all C# collections are by default non thread safe so if you have two threads accessing a shared collection then you will need to lock.  Here is a basic locking statement.


private List<string> m_strings = new List<string>();

public void AddObject(string name)
{
lock(m_strings)
{
m_strings.Add(name);
}
}

This is all good but its surprising how many things can go wrong. Lets look at some of the more common gotchas I have seen with this:


private List<string> m_strings = new List<string>();

public void AddObject(string name)
{
lock(new object())
{
m_strings.Add(name);
}
}

Yes I’ve actually seen this written. The problem with this is that the temporary new object created in the lock statement is instantly eligable for garbage collection so this approach does not work and is not safe. How about:


private List<string> m_strings = new List<string>();

public void AddObject(string name)
{
lock(this)
{
m_strings.Add(name);
}
}

Does this work? Yes absolutely. Is it a good idea to lock on ‘this’. Probably not. Think about what would happen if anothe thread accidentally locked on your whole object somewhere else in the system and then called your AddObject() method. Opps…. The same arguement incidentally applies when using:


lock(typeof(MyTypename)) {...}

Finally whats the difference I hear you ask between locking and using Monitor.Enter and Monitor.Exit. Well in short absolutely nothing. Indeed all the C# compiler does is convert lock statements into the equivalent Monitor.Enter and Monitor.Exit calls.

Unit tests vs system tests

Filed under: C# — admin @ 3:33 pm

I have a problem at work that I believe the current developers are not developing unit tests for their code but rather they are developing system tests that just happen to test out the class they are writing at the time. What I mean by this is that we have a typcial MVP pattern architecture for the C# GUI with C++/Java servers providing the data. Almost every unit test instead of testing say the view, or presenter, or object model actually connects to the remote server via  SOAP request, gathers real data and performs the whole display the view, test whatever and then close everything down again. This has several key drawbacks in my opinion:

1) It is incredibly slow. Our 200 unit tests take around 15 mins to run. In my last company we had 1600+ test that could easily run in under 3 mins and had just as much dependency on external systems.

2) The tests are each very complex and are invariably multithreaded which seems to be unnecessary in many cases.

3) The tests by their very nature are dependent on remote servers being available, and in some cases that the user who is running the tests have sufficient permissions to access certain features on the server. Neither of these seem to me particularly sensible and makes it very hard to get the tests run reliably as part of an automated build (in fact because of this this currently isn’t being done).

I do understand the need for unit tests to test end to end type functionality but I don’t believe that effectively unit testing our network connectivity and SOAP request functionality as part of every unit test is really necessary - mocking up servers and soap responses should be more than sufficient.

Thoughts and comments welcome please.

Comments in Code

Filed under: C# — admin @ 3:14 pm

At my new employers I have inherited a code base of roughly 200 C# classes spread out over maybe 20 projects. The code quality is of varying quality and complexity but the one thing that hit me within the first 10 minutes of looking at it was the complete lack of comments anywhere in the code. It was staggering that in a project of this size only maybe 10% of the classes had any comments at all. I feel that comments are a pretty essential part of any code base for the following reasons:

  • They help new team members come up to speed
  • They aid the forgettful developer as to what each method does.
  • By leveraging tools such as nDoc can help the code become self documenting.

In summary I can’t think of any reason why any good developer would so wilfully not write comments in code except for code obsfucation and job security purposes. Does anyone have any experience of this, especially as to how to pursaude existing developers that comments are good/essential practice? Or am I going mad?….again.

Collapse of Lehman

Filed under: Market and financial comment — Tags: , , — admin @ 2:47 pm

I was in a pretty unique position to watch the demise of Lehman Brothers working at the time in their Fixed Income eTrading IT department. I could write a lot on this life changing experience but a few comments:

  • Most employees at Lehman were as shocked at events as everyone else. On the friday before it collapsed everyone knew we were in trouble but nobody really expected us to be allowed to go bancrupt, especially after Bear Stearns.
  • Most employees at Lehman had nothing to do with the collapse and therefore no prospective employer should assume anything negative about having a Lehman employee in front of them at interview. This was a failure of leadership from the very top of the company. 99% of employees there I firmly beleive were doing a fantastic professional job right to the end.
  • Many of us felt very angry being portrayed in the media as somehow deserving to be in the situation we found ourselves in. Lehman top management should bear their part of responsibility but bottom line is that if anyone has bought something they can’t afford (i.e. a house) it is nobody’s fault but themselves and blaming the bank is ducking out of his/her responsibilities.
  • It has made me very wary about working for any company that bases a significant part of its compensation in stock options. Although i was relatively junior I still lost (from their peak value) several thousand dollars in stock. Had i worked their for 10-15 years I could easily have seen a large part of my assets gone overnight. Could I afford that aged 55? No.
  • Finally a general life lesson - sometimes if you are in trouble and you are offered help, even if on unfavorable terms, it is sometimes best to swallow your pride and take it. If Dick Fuld had accepted the offer from KDB I suspect Lehman would still be around.

I am lucky to now be working elsewhere, and indeed so are most of my ex-colleagues. This speaks in my opinion volumes as the talent and professionalism and high regard Lehman IT had in the industry. I will forever be grateful to all those I learnt from, but maybe didn’t appreciate at the time. Thanks guys!

Hedge funds in trouble

Filed under: Market and financial comment — admin @ 2:31 pm

I read over the weekend that some hedge funds are in trouble. Good! No? Lets have a look. Hedge funds play an increasingly important part of the world financial system. They in theory perform a necessary function to ensure market efficiency, particularly by exploiting market arbitrage strategies. On the flip side they were almost certainly a big part of the cause of the bubble bursting especially in their quite ridiculous explotation of commodity markets, particularly oil and food that in the end affected the man on the street so badly. Their huge leverage seems to also have exaggerated the swings we are currently seeing in financial markets and these swings have in themselves simply fed the general level of panic in the system. For what its worth I think:

  • If a few went out of business the world would probably be a better place.
  • Hedge funds should be better regulated, particularly with limits on leverage ratios they are allowed to operate with.
  • There should be severe restrictions placed on how much hedge funds can operate in commodities markets.

Should big ones be allowed to fail at the minute though? The idea of Citadel for example failing could be as equally disasterous as the collapse of Lehman Brothers to the markets. Forced selling and unwiding of positions would simply let this market mayhem continue for longer than it need to. In summary If I were the Fed (or SEC) I would be very wary of these collosal beasts whose footprints in the market we are all seeing every day.

Powered by WordPress