Archive for September, 2011

Cool Sequence Diagram Web Site

Thursday, September 29th, 2011

This is another of those really neat web-based tools for documenting your code: websequencediagrams.com. What a cool tool! This guy allows you to type in your transition diagram and then it'll render it for you in many different styles - including a very nice looking hand-drawn style. This is perfect for those times you need to whip up a simple sequence diagram and don't feel like all the mess and fuss of something like Visio.

Take a look. Pretty sweet.

Cool Little ASCII Flow Charting Web Site

Thursday, September 29th, 2011

I saw on the ZeroMQ mailing list this morning a slick little web site, asciiflow.com, that allows you to easily draw ASCII flowcharts and then grab them for text documents. It's nothing that you can't do with vi or any other editor, and it's not as nice as Visio, or something like that, but it's nice for those times that you need an ASCII-art representation due to the document requirements you have.

It's interesting. Worth remembering.

Why Do We Write Code?

Tuesday, September 27th, 2011

Building Great Code

I had a somewhat heated discussion with a co-worker this morning and he's been at The Shop for a number of years while I've only been here a little over one. He's adapted to how this place measures success, and I can't blame him for it. He's tried to write code to the best of his ability, and when he thought he was being successful, he's been told it was a failure. He is reacting to the measurements of success and failure that he's seen, and in that sense, it's completely understandable why he sees things the way he does.

But that's harder for me to deal with. Much harder.

All the time I was talking to this guy I was thinking How can I tell him why I write code without coming off as a jerk? Which lead me to this post. I can't really tell him, but I can tell you, and maybe you'll understand.

Writing code isn't just about a paycheck for me. In fact, I'd say that if it ever becomes just about a paycheck, I think I'd get out of it. Coding is about the creation of beautiful, functional, code that fulfills a specific need in an elegant and awe-inspiring way. I'm not niece enough to think that all code will be this wonderful an experience, but that's the goal. When code is being written, it ought to have all of these factors in mind: simplicity, clarity, style, function, and design.

So why do I go through all the headaches? Why put in all the hours? I believe it's because when I get the opportunity to create software, I will create something I'm proud to have my name on. It'll be something that has a good number of those idealistic qualities, and I'll be glad I put forth all the effort.

So when I hear a good developer talk about essentially "looking on the bright side", I get a little worried because I think I've lost a fellow Creator. He's become a worker - happy to deliver whatever it is that management asks for - no matter how outrageous, and unrealistic. It makes me sad.

Everyone has bills. Everyone needs a paycheck, and I'm no different. But I think there's a way to pay those bills and do something that's aligned with your moral compass. And as extreme as that sounds, I think it is a moral issue. Someone can ask me to deliver them something that's unreasonable, but if I let them believe that it's OK and reasonable, then that's my fault. If, after I tell them it's unreasonable, and I'll try, but won't write junk, they still want me to do this, then I'll give it a try. But we all have to live with ourselves, and thankfully, I've been given a set of talents that allows me to be a little picky in the work I choose to do.

I have to feel that my life has been something good. I'm almost 50 years old. If I don't do that now, when will I?

Trying to Find the Passion in the Work Again

Monday, September 26th, 2011

I was talking to a friend today and realized that I'm really suffering a mini-crisis of faith in the work I'm doing. There are plenty of times that I've really loved the work I was doing, but when I stepped back, and took a real look around, I wasn't as thrilled with the environment I was working in. While no place is perfect, I've found myself more than a little disappointed with the environment on issues that are becoming fundamental to my opinions about work and management and responsibilities.

Maybe it's because I'm getting older. It's certainly possible. I also don't claim to be the most patient person in the world. But recently, the effort I've been putting in seems to be very one-sided, and as I heard a friend say a few weeks ago -- relationships need to be give-and-take, not one-sided, to last. And right now, I feel very one-sided on this working relationship.

So rather than think about the situation I'm finding myself in, which I know I can do precious little about at this time, I'm trying to find the passion I had for the work so that I can at least feel good about the work I'm doing. Unfortunately, I'm finding it harder and harder to do.

I'm finding myself thinking more about writing code for my Mac, and even if it's financial, it's mine, and it's doing work on a platform I really like, and the undercurrent is that it's for something that matters to me, not The Shop. But that's not happening these days… I'm working just too much, and there's no time at all for extra coding.

Maybe I just need a vacation. When this project is done, maybe I just need to take some time off and come back when I feel ready to enter this place again. Hard to say… the concern would be that I never wanted to come back, but I guess that's something to think about as well.

For now, it's something I'm working on… I just wish I were having more success.

On Leadership and Management

Monday, September 26th, 2011

I was going through my weekend Twitter backlog and came across this tweet from Rands. It's solid gold:

Managers think it's a science. Leaders know it's an art.

What a beautiful expression of the difference between the two. One will look for formulas, and apply patterns, but the other will realize that each step is a new canvas, and that you can't expect to create something great without putting a little of yourself into it.

Cool C++ Stuff

Friday, September 23rd, 2011

cplusplus.jpg

I was working on my Greek Engine today and ran across a problem that I didn't know the answer to. I had a base class: instrument, and on this base class I had a virtual method: getBestPrice(). This method looked at the last trade price and last quote price for the instrument, and based on that, returned the very best price for the instrument. It's pretty standard stuff.

I also had a derived class: option, based on instrument, and it had an overridden version of the getBestPrice() method. The problem was, I was in a situation where I wanted to always use the instrument version of the method - even when I had an instance of option. How do I do it?

Well… I knew that if I was in a method on option, I could simple say:

  double option::doThis()
  {
    return instrument::doThis();
  }

and it would run the super class' version. But that's not what I had. I had a pointer to an instrument instance - or maybe it was an option instance. Who knows? But the instrument method had to be run.

My co-worker googled this and found that the correct syntax for this is quite simple:

  instrument   *inst = NULL;
  ...
  double  price = inst->instrument::getBestPrice();

and even if inst points to an instance of option, we'll be executing the instrument's version of the method. Sweet!

I'll be checking it on Monday. Pretty nice thing to remember.

Interesting Performance of snprintf() on Linux

Friday, September 23rd, 2011

Speed

I was trying to speed up the conversion of floating point numbers to integers today, and I came across some really interesting data. My initial code was very straight forward: I'd multiply the double by 1000, make it an integer, snprintf() it, and then look at the last character to see if it's a '0' - if it is, I remove it, if not, I keep it. Then I place the decimal point where I know it needs to be.

The code is simple, and not very creative at all:

  char      buff[16];
  bzero(buff, 16);
  snprintf(buff, 15, "%d", (uint32_t)(value * 1000));
  size_t  len = strlen(buff);
  size_t  lm1 = len - 1;
  size_t  lm2 = len - 2;
  size_t  lm3 = len - 3;
  if (buff[len] != '0') {
    buff[len] = buff[lm1];
  }
  buff[lm1] = buff[lm2];
  buff[lm2] = buff[lm3];
  buff[lm3] = '.';

This runs, and while it's not perfect, it's pretty fast. It's certainly faster because I precompute the index values, but that's just smart work. What I found was that using pointers and not doing the references really isn't any faster than using the references.

Then I looked up fast C++ integer to string and saw what a was out there. One guy wrote about this amazingly fast system he had written, so I gave it a look. What was interesting to me was the second place in the speed race was won by an STL string method that built up the number in reverse order by dividing by 10 and then doing a modulo on each digit, and finally reversing it.

So I tried it.

Not even close to the snprintf() version I had.

His results could have been for an older version of the compiler, or something, but I didn't see snprintf() as slow -- in fact, it was faster than anything else I tried. Amazing.

You just have to trust the compiler, and the OS. It'll get you there most of the time.

Upgrading to PostgreSQL 9.1.0 from KyngChaos

Friday, September 23rd, 2011

PostgreSQL.jpg

I have been a big fan of the KyngChaos builds of PostgreSQL for quite a while. After Marc L. stopped posting his, it made sense to find another source, and while I've heard that Apple's Mac OS X Lion Server has PostgreSQL as opposed to MySQL which it had in Snow Leopard, I haven't seen a lot about this part of Lion Server, and I'm consequently a little nervous about getting Server on my laptop and not being happy with the burden it places on my box. If I had a nice Mac Pro, I'd get it - but that's not (yet) the case.

So here's what I noticed in the update from PostgreSQL 8 to 9.0.4, and on Mac OS X Lion. There's a lot of little things, and it made for a somewhat hybrid scheme that I'm going to try and get rid of today with the upgrade to PostgreSQL 9.1.

First off, Mac OS X 10.7 has psql on it already. It's got a complete PostgreSQL client in it. It happens to be 9.0.4, which is nice, as that matched the version I was targeting. Given that, it's only the server I need to install. Not bad, but it's all a package anyway, so no big deal.

Secondly, in 10.7, the PostgreSQL user is _postgres and it's not a user that can login. This means that a lot of the update schemes that I used to use don't work because you can't log in as the postgres user any more. However, there seems to be a better scheme - assuming you're migrating from a recent version. The update procedures are detailed in a file in the disk image you download from the site, but I haven't been able to get it to work. I'll try on the next update again, but this dump-and-load works really well for me and does not require that we have a postgres user to log in as.

Step 1 - we need to get a complete dump of the database. It's pretty easy, just get to anyplace you can write a file - I used my home directory, and issue the following command as yourself:

    /usr/local/pgsql/bin/pg_dumpall -U _postgres -o > pgbackup

Step 2 - stop (unload) the existing version of PostgreSQL. This is going to shut it down, but it's possible to pull it back if you need to:

    sudo launchctl unload \
      /Library/LaunchDaemons/org.postgresql.postgres.plist

Step 3 - install the new PostgreSQL package from the site. I noticed that I had to install it twice in order to get the contents of the /usr/local/pgsql-9.1/data directory, so if you don't get that, then install it again, and it should get installed properly.

Step 4 - start the new version. The launch daemon file should be installed properly and you should be good to go, but it never hurts to check:

    sudo launchctl load \
      /Library/LaunchDaemons/org.postgresql.postgres.plist
    ps -ef | grep post
      …lots of postmaster processes listed...

Step 5 - reload your database. Be in the same place as Step 1 and you can simply issue:

    /usr/local/pgsql/bin/psql -U _postgres -d template1 \
      -f /full/path/to/pgbackup

Check with psql and maybe a simple PHP script, and you should be good to go. Once it's all OK and running, you can remove the old install:

    sudo rm -rf /usr/local/pgsql-9.0

At the same time, if you have the old postgres user still installed, you can delete him as well - there's nothing you need from him any longer. Lion's _postgres user can handle all the chores from here quite nicely.

If you run into problems, check the permissions on the directories. Because I was switching from the postgres user to the _postgres user, I needed to make the old install usable by the new user:

    sudo chown -R _postgres:_postgres /usr/local/pgsql-9.0/data
    sudo chown -R _postgres:admin /usr/local/pgsql-9.0/var

PostgreSQL 9.1 has a ton of interesting features. I'm using the replication at The Shop, and it's working like a charm. I'm a big fan, and these updates are really exciting to see.

Google Chrome dev 16.0.889.0 is Out

Friday, September 23rd, 2011

Google Chrome

Seems the posts were right, Google Chrome dev 16.0.889.0 was released this morning and I picked it up. I had suspected that they'd move a major version number soon, but as I've known for a long time, it's the third number in the version that really matters, and it'll be interesting to see what happens when it tops 1000 - will they move up the next number or not? I'm guessing they're a bunch of engineers, and because of that, they'll have numbers like 20.0.1011.0… we'll have to see. For now, it's nice to see that they have updated the V8 javascript engine and done more with the Mac port.

…and there are times I really want to just SCREAM

Thursday, September 22nd, 2011

cubeLifeView.gif

Today started out badly. I get to the Naperville Metra train station on time (4:30 am), and they aren't running the trains this morning. At least not yet. Seems there's a freight train that's in the way of all the commuter lines and nothing is leaving Aurora on the way to Chicago. Since I'm not about to want up Liza to take me downtown, and I'm not about to drive myself, it's time to settle in for a little delay.

I had no idea it would be 90 minutes before we'd see a train!

When it arrived, the people who were waiting less time than I had been waiting, decided it was time to play NBA, and started throwing elbows to get on the train. It's an amazing display of a complete lack of decency, which is why I like catching the early train as it's at least got decent people. I guess getting up that early, you appreciate what it takes for others to do the same, and you are a little more respectful of your fellow man.

So over 90 mins late, I arrive at The Shop, and I'm settling in. Trying to put my day back on track, and get into the swing of things so I can forget about this horrible commute.

In general, things are going well until I have to get in on a phone call with the lead developer for another group. This call is about the fact that in order to save space and make comparisons easy, virtually all of the floating point numbers in the system are available as doubles and as integers - signed or unsigned, as the case may be. The decimal representation in an integer is pretty easy - just multiply by a constant and then you have a fixed-precision decimal number. Easy.

So about six or seven months ago, I was building exchange data feeds, and we needed to identify the instruments in a way that allowed the value to be generated at the source - regardless of the instrument. This precluded the existing method which was a database IDENTITY column value that needed to have a stored procedure run if a value didn't exist for a given instrument. This database dependency was horrible, and that's why I invented the SecurityID and SecurityKey. The ID is a 128-bit number that packs in all the details of the instrument in a 128-bit number, based on the UUID, that is suitable for putting in tables, hashes, etc. The Key is a string representation of the same information, and the SecurityID class can take a Key in it's constructor, and generate a Key from a toString() method.

Since OSI came into being, the strike has been a decimalized integer with an offset of 1000. That's what they say, plain and simple. In my SecurityID, I decided to use the same thing so that I could accurately represent any strike without wasting space - after all, I know had 128 bits.

The point of this is that I defined it for the feeds.

Fast-forward to today.

I wrote the C++ classes and gave them to the Java developers for their conversion. I could have written it in Java as well, but they wanted to do the conversion. Turns out, they can't read code to save their lives. They implemented it completely wrong, and yet never asked for verification of the information. They didn't even check the SecurityKeys (string representations) to make sure they were equivalent.

So today this lead developer asks about the decimal multiplier for the strike. They chose to use 104 for all their decimal numbers, and even though this should be an easy conversion for them if they extract the strike from the SecurityID, they wanted the multiplier in the SecurityID to be the same as theirs -- as opposed to the value it's been defined to be for more than 6 months.

The catch was, they already built a lot of code based on this "implementation" they had, and rather than fix it, or correct it, they wanted us to change it. I immediately knew I was messed over because in this place, expediency wins out over everything else. The existing code - forget that they had something to work with for months - forget that they should not have been hitting the SecurityID for the strike in more than one place in the code int he first place - all that mattered was that I now appeared to be asking them to change.

So I had to change instead.

I was silent, for I knew there's nothing I could do or say to change the facts. This was going to be something I had to change. But I'd change it on my terms.

The multiplier was still 1000, but when you asked for the integer value of the strike, it'd add that extra factor of 10 for them. In the string representation, we weren't going to leave it an integer, for it might be OK to look at O:AAPL:20111022:365000:P and know what it was, doing so for another factor of ten on the strike was too much. So I went decimal on the strike, and told them this is what we're doing and why.

I feel that O:AAPL:20111022:345.00:C makes it very clear what the individual components are and what the value of the strike is. If there's a need for the third decimal digit to the right of the decimal point, it will be there, but if it's a zero, then it's drooped. I made the changes to my code, and then had to retrofit it into my Greek Engine and the Ticker Plants.

But wait, there's more…

When my co-worker and I went to tell our boss about this, I was very quiet about the situation because I knew my opinions and feelings had no relevance to this issue, and in fact, were counter-productive to getting things done quickly and efficiently. I could, and would, write the code, but I wasn't going to like it, and I certainly wasn't going to appreciate the way in which this was handled.

After the situation was explained, my boss asked me "What do you think, Bob?"

"My thoughts on this would be counter-productive at this point." I said.

"No, really, what do you think" he reiterated.

"Really. Seriously. They'd be counter-productive" I tried to stress.

"He's right", my co-worker chimed in. "They'd be counter-productive."

"No, really, what are they?"

And so I started to tell him. I was trying to stay a little on the humorous side, but there was no way to hide the fact that I was not happy with the fact of what was happening and why. Midway in this tiny rant he puts up his hands and says "Wow! Bob! I get it!"

Here's the thing: If you don't want to hear the uncomfortable answer, then just don't ask! If you do, then at least be courteous enough to shut up and listen! To forcibly ask me to answer a question that I've already said would be "counter-productive" and then not listen to the answer is, in my opinion, unkind.

Ask or not. But if you ask, listen.

It's then when I came back to my desk and just wanted to scream. But I wrote code instead, and that's what I have to focus on: I write code. I create. The rest of this is lunacy. Stay focused.