RSS
Facebook
Twitter

Monday, May 23, 2011

Getting around a bit

I'm honoured to now be listed on three aggregated blog feeds:

The pressure's on to try and write useful stuff.  Oh OK, I'll settle for "entertaining".

Friday, May 20, 2011

Why Java developers hate .NET

I have been struggling with .NET.  Actually, I have been fighting pitched battles with it.

All I want to do is take our existing Java client example code and write an equivalent in C#.  Easy, right?

Trisha's Guide to Converting Java to C#

Turns out writing the actual C# is relatively straightforward.  Putting to one side the question of writing optimal code (these are very basic samples after all), to get the examples to compile and run was a simple process:

1. Find-and-replace the following (only you can't use Ctrl+R like I expect.  Sigh.)

final = readonly (but remove from method params)
System.out.printf = Console.WriteLine
Map = Dictionary
BigDecimal = decimal
Set... oh.  I have no idea.

2. When using callbacks, replace anonymous inner classes with delegates


Java
something.doSomething(new SomethingRequest(),
new SomethingCallBack()
{
public void onSuccess()
{
System.out.println("Action successful");
}

public void onFailure()
{
System.err.println("Action failed");
}
});

C#
private void foo ()
{
_something.DoSomething(new SomethingRequest(),
SomethingSuccess,
SomethingFailure);
}

private void SomethingSuccess()
{
Console.WriteLine("Action successful");
}

private void SomethingFailure()
{
Console.Error.WriteLine("Action failed");
}

I rather like this pattern actually. You can't really tell in the noddy example above, but the C# code is generally shorter and more reusable.

3. Replace getters and setters with properties


Java
private class MyClass
{
private BigDecimal myField = new BigDecimal("-1.0");

public BigDecimal getMyField()
{
return myField;
}

public void setMyField(BigDecimal instructionId)
{
this.myField = myField
}
}

C#
internal class MyClass
{
public decimal MyField{ get; set; }
}

What the... where did all my code go??

My Thoughts

I was pleasantly surprised with the language. In general, for what I was doing, the equivalent C# was a lot less code. The fact that the syntax is not wildly different from Java made the transition relatively easy, even if I don't get all the nuances.

I didn't really like the enums - I can see what purpose they serve, but I quite like the way the Java ones are pretty much classes in their own right with properties of their own - it allows you to encapsulate some of your simplest domain objects. But it's a minor point, not a deal-breaker.

The C# capitalisation makes me queasy though. I just can't get my head around it. In Java, if I say:
com.mechanitis.foo.Bar
I know the class is Bar and the rest is the package (or namespace, or whatever). This is more useful when you're using static methods and so forth:
com.mechanitis.foo.Bar.thatThingIWantToDo()

In C#, I know the thing at the end is a method and the thing before that is a class, but it doesn't jump out at me:
Com.Mechanitis.Foo.Bar.ThatThingIWantToDo();

And if you're using a property:
Com.Mechanitis.Foo.Bar.MyProperty;

The whole thing makes me dizzy.

You could argue that all this is redundant with modern tools and IDEs doing all the heavy lifting for you - nice colourisation etc.

Which brings me to The Rant.

Oh My Dear God What Is Wrong With Visual Studio?

C# needs to be a shorter, more succinct language because it takes three billion times longer to do anything in Visual bloody Studio.

I'm coming at this from a Java, IntelliJ point of view, so there's always the possibility it might be lack of familiarity with the tool, rather than the tool itself, which is the problem.  It's a long time since I used VS, and that was back in the 90s when I was doing ASP and COM (shhh, don't tell anyone).

But things shouldn't be this hard.  I was ready to accept, due to my newbie status, the IDE not helping me. I didn't expect it to actively hinder me.

For example: it took hours of my life that I will never get back to discover that you can't simply run a class that has a main method by right-clicking and selecting "run" (note: I'm not even trying Ctrl+F10).  No.  I have to select, at a Solution level, which Projects are runnable.  Then I have to select at the Project level the class with the main method I actually want to run.  Then, it opens up a terminal window and runs it in there, which promptly disappears when the program errors or finishes.  What's wrong with outputting in the output window of the IDE? Is that not what it's for?

Finally I worked out how to run the cursed program (seriously, like that's not the first thing everyone wants to do?  How do people write "Hello World"?).  Now, where are the command line arguments?  Of course, they're at the project properties level too, because each project only has one entry point.  I seriously had to Google that too because I couldn't work it out from the IDE alone.


The next day, my ReSharper licence had expired.  I decided I should attempt to limp on without it, after all hundreds of developers must be surviving with just Visual Studio.  How bad could it be?

Very bad, it turns out.

All those helpful little squiggles I was leaning heavily on to convert my Java to C#?

  • The red to tell you you're utterly wrong.
  • The orange to tell you could be using less code.
  • The blue to remind you to stop thinking in Java and helpfully offer corrected naming.
  • The green to suggest stuff that C# could do differently.

Yeah, all gone.

How do people code like this?  Do they really just do a build to check if it's all wrong or not?

Next, I try to find a class.  I actually have no idea how to do this, because I can't use Ctrl+N.  So I Ctrl

I realise this is a waste of time anyway, because one thing that really annoys me about Visual Studio is that I can't find a way to sync the project tree to the class file I'm looking at.  I can't get it to jump to highlight where I am.  When I'm using IntelliJ, I find this dead useful when I want to see other stuff in the same package.

Less than ten minutes after attempting to use Visual Studio without ReSharper, I've abandoned the fight and tracked down a licence and installed it.

Documentation isn't a standard function of .NET?

What sort of message does this give developers?  Documentation isn't important?

I always thought Javadoc was pretty ugly and clunky. In addition, now our IDEs generate so much, it's frequently meaningless.  But it is generated by standard Java tools, and HTML is a standard format that can be read on pretty much any computer with any operating system.

I could not believe how hard it was to get the XML comments out of the C# into something the user can actually read.  Thank goodness, some enterprising member of the team had already done that for us.  All I needed to do was hack/crowbar the tutorial I'd been working on into the generated documentation, so it ended up in the Windows help files in some fashion.

I know there's a way to get HTML/XML files into the end result using Sandcastle, but hours of Googling only told me it was possible, not how to do it.  I still have no idea what the correct question is to ask to find the solution.

Right now, this is an unsolved mystery.  Our .NET client users will have to read the plain HTML I'm afraid.

In Conclusion

Are we lowly Java developers spoilt with our shiny IDEs?

Or is there such a fundamentally different approach to development for .NET people that all the functionality is there, I just can't find it?

I'm disappointed if I'm honest.  I'm sure the .NET camp used to tout their tools as their superiority.  I ended up feeling sorry for the poor NET people.  Is there anything they can use that isn't Visual Studio?


In Conclusion: Despite the nasty capitalisation I found myself surprisingly taken with C#.  But until they can give me a proper development environment, I won't be tempted by the dark side any time soon.

Monday, May 16, 2011

As an associate member of the London Java Community (LJC), I'm very pleased with the news that we won an Open seat on the Java SE/EE executive committee.  The results show that we got an astonishing 47.5% of the vote - if an MP got voted in with that percentage the newspapers would probably be using the word "landslide".

It's quite exciting to be one of the two user groups involved.  We hope to balance some of the larger corporate organisations, we're the voice of real life Java developers who use the language every day, for enterprise development or open source projects.

You can argue Java is dying, but the community is not.  And I think we're exactly the people to guide its future.


PS (Warning: gratuitous plug incoming) If you're at all Java-curious and you like drinking and attempting to be social, join us this Tuesday for our monthly Developer Sessions at the Porterhouse in Covent Garden.

Tuesday, April 26, 2011

Cyclist tribes

Living and working in central London, you quickly learn that the fastest way around town is to cycle.

My extensive research into this activity has shown there are a number of different cycling tribes. Of course, I have split them into the two groups that are most appropriate to me: 1) slower than me and 2) faster than me. You can probably tell what sort of a cyclist I am by my attitude to the two groups.

1. Slower than me:
  • Wicker shopping basket. Doesn't matter what the rest of the bike looks like, or the biker, I will always try to get ahead of these.  The extra scary ones are the women in flowing dresses who might be university professors.
  • Boris Bikes.  When there's a tube strike, Avoid At All Costs.  These people probably haven't been on a bike since they were in school, and it shows.
  • Hoody (always a male) on a BMX-style bike with the seat far too low, riding in too low a gear, with baggy jeans that show their... well... everything. Never have lights on their bikes.  Always has a satchel / record bag for maximum inappropriately-dressed-for-cycling points. These buggers are a pain because they never obey traffic lights and will join the road from the pavement on either side, cutting you up in the process. Getting past them is easy, keeping them behind you is much harder. 
  • Not wearing a helmet. Probably not a serious cyclist, so probably easy to overtake. A similar category to the hoody, doesn't obey traffic laws and enormously unpredictable. Otherwise known as an organ donor.
  • Wearing a skirt. Of course, this doesn't apply to me. In the same category: jeans, sandals, high-heeled shoes (not all at once). 
2. Faster than me:
  • Cleats. If you have cleats on the bike I'm going to let you go first from the lights. You'll be fast and possibly suicidal when weaving through traffic.
  • Lycra, especially on a guy. Even if they're not faster than me, they will always overtake, and always pull in front of me at lights. It's an ego thing.  Something about those tight shorts possibly.
  • Panniers. Generally, but not always, a “proper” cyclist, even if they're on a rubbish bike. These guys have experience.
One to watch: businessman in a suit on a Brompton. You can't trust these guys, they can be deceptively fast. It's always embarrassing to be overtaken by them. How do they not sweat into their Armani?


Who does that leave?

Well, my lot: helmet, high vis jacket, shorts (knee-length with pockets). Usually obeys the lights, quick enough, some unpredictability when over-/under-taking. Most of these guys will weave to some extent, but not suicidally.  My tribe is probably one of the biggest, and it leads to lots of subtle negotiation at traffic lights - sizing each other up - checking the bike, the kit, the shoes - to decide whether or not to pull ahead or drop back.

But I mess with people's heads in summer by occasionally wearing a short skirt (with shorts underneath, I'm not out to cause accidents) and wedge sandals, and cycling at 20mph.

I hate to conform to expectations.

Monday, April 18, 2011

I attended TradeTech last week, an annual event about Equities and Derivatives trading. I assumed from the title that there would be a reasonable focus on technology, but I found it was more “Trade” and less “Tech”.

The fascinating thing to me was how different this is from the sorts of technology conferences I've been to. For example, I popped into JAX this week (albeit in the evening for drinks). At technology conferences (<gross-generalisation>) people tend to subscribe to a variety of dress codes and fashion clans, usually from jeans through the range of business casual, including your fair share of goths and alternatives. Suits would be unusual (</gross-generalisation>). At this place, people were scarily conformist. A few years back, the suits at least would be different colours – navy, greys and black – and may or may not include pin stripes. On Thuresday, almost everyone was wearing a particular shade of tasteful dark grey.

I was also pretty shocked at the time people snuck off to go to the pub. Don't get me wrong, I'm all in favour of imbibing alcoholic beverages as frequently as possible.  And I prefer networking in the pub to poncing around in some conference centre. But I feel it's Bad Form, and I was surprised (and a little bit jealous) that it seemed to be the norm. I felt for all of the later presenters.

Still, I showed my support for them and I turned up to some actual presentations.  The most interesting ones to me were Baroness Eliza Manningham-Buller talking about her time as head of MI5, and Richard Peterson going Inside the Trader's Brain.

The Baroness was talking about leadership during times of crisis – she was in charge shortly after 9/11. What I found interesting, and resonated with me, was her focus on her people. An intelligence organisation is all about the people who work for it. She stressed that it was important to bring fun into the work place, especially because it was a particularly traumatic period to be working. She instigated family days and helped the employees show their families what it was they did. I'm not quite sure how much they could show, given the nature of that industry. But I liked that she understood the people were more than just minions, workers in a hive, that they had families and that they wanted to be proud of their work and share it with the significant people in their lives.

She also refused to take credit for anything for herself, but talked about her team, about the people around her and in the organisation. I like leaders who recognise that it's not all about them.

The thing that stuck with me the most is she said that leaders who take themselves too seriously are not taken seriously by their underlings.

Richard Peterson's presentation was about the risk-taking and risk-avoidance areas of the brain. He showed how your risk-taking behaviour is influenced by bias, and how subtle it is. There was a lot of interesting stuff in this, which scratches my random-interest-in-psychology itch, and confirms what I've been reading/hearing about how behaviour can be triggered and changed.

Ultimately he gave some advice for how to reduce the impact the rest of the world might have on your trading strategy, which is applicable to all of us:
  1. Maintain healthy routines
  2. Take time to reflect daily
  3. Letting go
  4. Gratitude
The ulterior motive for me to be at TradeTech was to watch my boss's “How To Do 100,000 Transactions Per Second At Less Than 1 Millisecond Latency?” presentation. This was a cut-down and updated version of the one he and Mike gave at QCon last year. If you are at all interested in concurrency, high performance, or programming generally, it's well worth the hour to watch it. It outlines the architecture we use at LMAX to get very high performance from our exchange without using anything particularly special in terms of hardware. All it takes is good design and something Martin calls mechanical sympathy.

Anyway enough corporate plugging.

Overall I came back from TradeTech with lots of ideas of things I wanted to do at work and ways to help us market the platform in future. I also came back with a certain cynicism for these types of very vendor-heavy events. However, I did meet some interesting people, and it was a different crowd to my usual technical comfort zone.

 And it did get me thinking, which is really all these things should do.

Tuesday, April 12, 2011

First, an apology.  I will be using the British spelling for "centre", because, well, I'm British.  But it gets really confusing because you have to use the American spelling in the code.  And doesn't "Centring" just look wrong?

Part Five: Horizontal and Vertical Centring
One of the most common things you want to do with blocks of content is to centre it.  In particular, you would think that vertically centring content would be straightforward, but it turns out that in HTML/CSS it just isn't.

5.1 Horizontal Centring
Centring a paragraph of text is clearly easy - all you need is text-align: center.  However, sometimes you want to centre a block, something like a div, without having all the text centred as well.  This is slightly trickier than you might expect, because the only CSS attributes you have are for centring text.


<html>
<head>
<title>Horizontal Centering</title>
<style type="text/css">
#div1, #div13 {
background-color: #DDDDDD;
}

#div2, #div14 {
background-color: #BBBBBB;
}

#div3, #div15 {
background-color: #999999;
}

#container, #container5 {
border: 1px solid black;
margin: 5px;
}

#container5 {
text-align: center;
}

#to-center {
margin-left: auto;
margin-right: auto;
width: 200px;
border: 5px solid red;
}

#to-center2 {
margin-left: auto;
margin-right: auto;
width: 200px;
border: 5px solid red;
display: block;
position: relative;
text-align: left;
}

</style>
</head>

<body>
<div id="container">
<div id="to-center">
<div id="div1">One</div>
<div id="div2">Two</div>
<div id="div3">Three</div>
</div>
</div>
<div id="container5">
<div id="to-center2">
<div id="div13">One</div>
<div id="div14">Two</div>
<div id="div15">Three</div>
</div>
</div>
</body>
</html>
Using margin-left: auto and margin-right: auto on the block you want to centre is a neat trick for doing this.  And it works fine in Chrome and Firefox.  However, it's not so great in IE 7:


The trick for getting it centred here (the second block) is to set text-align: centre on the div containing the block to centre (container5), then reset the text-align to left on the centred block (to-center2) so the text isn't centred.  Yes, a total faff.

However, there is some good news.  You can get IE to behave the same way as the more sane browsers by setting it into Strict Mode:


Remember kids: Strict Mode Is Your Friend.  And all you need to do is add the following to the top of your HTML file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
5.2 Vertical Centring
<html>
<head>
<title>Vertical Centering</title>
<style type="text/css">
#div1, #div4, #div7 {
background-color: #DDDDDD;
}

#div3, #div6, #div9 {
background-color: #999999;
}

#div5 {
height: 40px;
line-height: 40px;
background-color: yellow;
}

#div2 {
height: 50px;
background-color: orange;
vertical-align: middle;
}

#div8 {
height: 40px;
line-height: 40px;
background-color: cyan;
font-weight: bolder;
}

#container1, #container2, #container3 {
border: 1px solid black;
margin: 5px;
}

</style>
</head>

<body>
<div id="container2">
<div id="div4">One</div>
<div id="div5">Two</div>
<div id="div6">Three</div>
</div>
<div id="container1">
<div id="div1">One</div>
<div id="div2">Two</div>
<div id="div3">Three</div>
</div>
<div id="container3">
<div id="div7">One</div>
<div id="div8">Massive line of text that needs to wrap to show the centering totally doesn't work when you have more than one line of text.</div>
<div id="div9">Three</div>
</div>
</body>
</html>
Given some of the problems with horizontal alignment, it shouldn't come as a surprise to find vertical alignment is not simple at all.

Us straightforward developer types would expect to be able to put vertical-align: middle on a div and expect all content inside that div to be, well, vertically aligned in the middle.  However this is not the case - see the orange block above.  A quick Google will tell you why this doesn't work, and I don't intend to duplicate the explanation here.

There is a nice hack which works for single lines of text though: if you set the height of the container and the line-height to the same value, the text will be vertically centred within that container (see the yellow panel, div5, above). This works really well for things like buttons or icons.

However, it doesn't work so well for paragraphs of text or sentences that might wrap, line-height is for a single line of text only.  See the cyan panel above for what happens if your text wraps.

I'd love to give you an answer on how to get this to work for text that wraps, but I haven't found a satisfactory solution yet.  What I usually do is set a fixed height on the container and then set the margin on the text so that it sits in a way that looks vaguely centred.  Not a solution I'm happy with, because a) it can sometimes render slightly differently on different browsers b) it's a very fragile solution if you're going to internationalise your page as some languages will have longer or shorter paragraphs and c) it feels like a massive hack.

If anyone has a nice solution for vertically centring paragraphs of text I'd love to hear it.

Monday, April 4, 2011

How to show your employees how much you hate them

Due to a combination of my restlessness, my consulting experience, and employers that insist on moving offices frequently, I've had the dubious honour of working in a variety of environments.

Today I will teach you, the employer, how to show your staff just how much you hate them.

The Kitchen Is Not For Eating In
Since eating and drinking is unfortunately a fundamental part of being human and staying alive, you will need to provide your staff with a space that pretends to address these needs.

The best example I have seen so far has been a "kitchen" with: no sink; no kettle; no microwave; a tiny under-counter fridge for employee food (for approx 50 employees); nowhere to sit and a maximum capacity of 3 people standing. You're probably wondering how I knew it was a kitchen.  Well, it had a counter top. And a coffee machine which also dispensed slightly warmed water.  And The Largest Drinking Water Dispenser In The World1.

The most important thing to remember here is that This Is Not A Communal Space.  Heaven forbid that your minions actually talk to each other.

For bonus points: if you really want to show your code monkeys how much you despise them, you can dispense with the coffee machine entirely and supply only Nescafe Gold Blend instant coffee.  Honestly, developers don't care what form their caffeine comes in2.

The Importance Of The Loo/Bathroom/Restroom
(Note for our North American brethren - there's no bath in there and I certainly don't go there to rest.  Can we call them toilets and be done with it?)

If the cubicle door looks like it's already come off the hinges a couple of times and been sellotaped back on, if the cubicles are made of plywood, if there's a genuine chance that someone could get trapped in there by the dodgy door lock, if the loo paper is that tracing paper you used to get in school, perfect. You've managed to convey to your staff just how little they mean to you.  If you have been successful in this, your employees will show you exactly how they feel about you by the state they leave the bathrooms in.

For bonus points: don't pay the cleaning staff enough so the paper and towels aren't replaced frequently.

The Office Canteen Is Also Not For Eating In
If you've done your job correctly with the kitchen and the toilets, your employees are probably desperate for somewhere they can congregate.  You must not allow this - if they get together, they could have Dangerous Conversations, where they Share Ideas and Collaborate.

A rookie mistake would be to not provide a canteen at all.  Do not fall into this trap! If you don't provide food on site, your staff will leave the building, and who knows where they're going to go, what they'll get up to, who they might meet?  No, you want to provide them with facilities you control.

However, you want them to go to their miserable little cubicles to eat, so make sure there isn't enough space for them to sit in the canteen.  For best results, provide a couple of tables and chairs but ensure they're always filled.  That gives them elusive hope that maybe, some day, they will be the ones on that table.

For bonus points: have a separate management restaurant.  This should be visible enough that your employees are aware it exists and that it's better (table service, for example), but private enough that it becomes a mythical place. Then you must make sure they know, every day, that they are not allowed to use it.

Go For Tones Of Grey And Brown
Nothing says "your life is worthless" like a 1970s-council-style-office.  If it's made of concrete and has laminated mirrored windows, so much the better.  To go the extra mile, put up 10 foot high "inspirational" photos of people playing on beaches, in black and white.  That way your employees will remember that there is an exciting world out there, but they can't get to it, and they can't even enjoy it by proxy in this miserable, monochromatic office.

For bonus points: your cupboards should all be laminated Formica, in murky brown.

Reduce Natural Light Sources
I used to think that working in a basement was the worst fate that could befall me. After I did it twice, I swore to never again work in an office with no natural light.

However, there is an even more devious way to make your staff miserable. Ensure there are windows in the office, nice big ones.  Then build cubicles throughout the floor, so that your employees can see there is a window, but they cannot see out of it, or receive any actual light from it.  Watch them pine and fade away, or fight over the desks close to the window.

For bonus points: make sure the people closest to the windows have their monitors angled for maximum screen glare.  Then these unfortunates will close the office blinds voluntarily, and really minimise vitamin D production in your minions.

Provide Beds/Bedrooms In The Office
Now, you might be thinking that this is a little cushy for your minions.  I can assure you, the drain on morale is worth it.  By providing beds, you don't have to shell out for expensive hotels for visiting employees, or for taxis for those who have to work late.  It gives your staff the message that they belong to you, you even own their sleeping hours.

For bonus points: put the bedrooms on the Management Floor (you know, that special floor for those who have Made It), so that your lowest-level employees have to walk through this opulent splendour in order to grab a couple of hours of poor quality sleep, before being herded back into their cubicles to put in another 20 hour day.


In Conclusion
It doesn't matter what size company you are, by following some or all of these rules you can successfully communicate to your Peons just how meaningless their little lives are to you.  Large companies seem to be particularly good at this, but a determined start-up can also alienate all three of its employees if it tries.

By showing your staff how much you hate them, you are sure to attract and retain the best quality people, and motivate them to work hard and efficiently to realise business value for you.

Oh wait....



1 It was the size of a wardrobe. All it did was filter and UV "purify" tap water. It also claimed to be smart, it would dispense a cup if you needed one and detect if you didn't. It attempted to determine the size of the container you placed in it and fill it appropriately (and failed every time). It would tell you how many seconds were left until it had finished filling your vessel, but not give you the option to stop it, or to continue for longer. Seriously. A tap would have been fine. 


2 In case you don't know - they really DO care.