Archive for the ‘Coding’ Category

Working on Lisp-Like Parser (cont.)

Tuesday, December 21st, 2010

Professor.jpg

This morning I've been working more on the lisp-like parser for embedding in my projects, and it's coming along nicely. I realized that I needed to make my collections use pointers if I wanted to really use polymorphism, which just makes the housekeeping a little more, but other than that, it's fine. With that, I'm getting the right messages dispatched to the right instances, and things are moving right along.

I have been adding the function class to the code this morning, trying to get the evaluation of functions going. It's just a lot of little details and lots of writing. The base classes aren't bad, but every time you start another, you're looking at a good bunch of typing. I just need to get the first version hammered out and then I can look and see if I need to make it faster.

The rest of the day is in meetings, but it's nice to get it all moving forward this morning.

Working on Lisp-Like Parser

Monday, December 20th, 2010

Professor.jpg

One of the many potential next projects for me might be a greeks server - like I've worked on in the past. The difference here is that it's targeted to me a lot more flexible than the old MarketMash system - this one is going to allow for the clients to give it "mutations" to the center state so their numbers can be as good, or bad, as they want. I've fiddled with a lot of different schemes for specifying this kind of mutation - including muParser. But those don't seem right in this context.

The choice for this seems to be a lisp-like language that is in use in some other projects in The Shop, and it would be a natural fit to have a C++ version of this for any C++-based projects. Right now, the only version is a Java-based one, and while that's nice, it's also heavily customized to the application it sits in. What I'm looking for is a simple parser that can have variables, constants, functions all added to it - augmenting a nice set of default capabilities so the user can make of it what they want.

The language isn't really hard. The expressions are really pretty simple:

  (set boo 5)
  (+ boo 10)
  (* 12 5 3)
  (avg (min boo 5) (max boo 5))

stuff like that. Each expression has a function as the first argument, and then a series of items - which can be values or other expressions. I've just decided to make the Item a base class, subclass Value and Expression, and then start the coding.

Today was all the parsing of the input text, and it's pretty nicely compact. I'm pleased with the way it's looking. Tomorrow is the functions, etc.

Google Chrome dev 10.0.612.3 is Out – Another Quick Bug Fix

Monday, December 20th, 2010

Seems Google Chrome dev 10.0.612.3, out today, fixes a regression test with the RegEx in the engine, but that last part is an assumption that wasn't explicitly stated in the release notes. In any case, it seems that we have two regression test related fixes in just a few weeks. The engineers at Google are slipping... maybe they've had to lower their standards to get employees?

OK... maybe just sloppy - but which one is the worse explanation, really?

Lots of Meetings but Got Some Good Work Done

Friday, December 17th, 2010

Ringmaster

Today was heavy with meetings, but I was able to get some nice work done on my ticker plant - the Java guys were interested in using my security name to 128-bit int converter as it was non-lossy and bi-directional. There are times they want to use a number but not loose the ability to pull out different aspects of the instrument. What I went with was a subclass of my UUID where I added in a lot of nice helper methods:

  tInstType getType() const;
  bool isStock() const;
  bool isOption() const;
 
  std::string getUnderlying() const;
  uint16_t getExpiration() const;
  float getStrike() const;
  bool isPut() const;
  bool isCall() const;

where I've dropped the comments for the obvious nature of these methods. The point is that we aren't going to decode the entire 128-bit stream to get the one bit that's the Put/Call flag, so these guys allow you to get the one piece of data you want without having to convert it all into a string and then parse that.

I got this all in, and the tests were just fine. I even had the operator=(std::string) written so you could do something like:

  msg::ng::secID_t   id = "O:GOOG:110214:74550:C";

and it'd parse the string into the 128-bit number and be ready to go. Should save a lot of time.

Finally, I added this as a possible component of the variant class so that it could be put int he codec for the messages to the Broker. This will really help move things around as we'll be able to handle getting this as a data type in anything coming from, or sending to, the Broker. Very nice.

But then there were more meetings, and some were really draining. Still... it was nice to have a little bit of work under my belt for the day. Made it feel like it wasn't totally spent in meetings.

Google Chrome dev 10.0.612.1 is Out

Friday, December 17th, 2010

This morning Google Chrome dev 10.0.612.1 was released and represents a big jump in the browser, specifically, the new V8 engine (3.0.2.1) is in there, and the new WebKit (534.15) is in there in addition to a mess of other new stuff. I'm interested in seeing how this guy tests out as it should be a significant improvement to what I've had for a while. Exciting times...

BBEdit 9.6.2 is Out

Thursday, December 16th, 2010

BBEdit.jpg

This morning I see that BBEdit 9.6.2 is out with a pretty extensive list of fixes. I have to say, it's a sweet editor, and I wish it was embedded in MarsEdit, but hey, that's another wish for another day. Still... great editor for the Mac.

Expanding the IRC Interface to Respond to Channel Chats

Wednesday, December 15th, 2010

chat.jpg

Today I was thinking about one of the problems I was having with all these ticker plants and finding the data I needed amongst all of them. It could be a nasty little task to keep them all straight. Certainly, it was going to be a problem for the support crew. And then it hit me - what if I used the channel chats as a "broadcast" mechanism and then the "correct" ticker plant could privately answer me. If there happened to be more than one that had something for me, they would do it privately. Wow... excellent idea! I just had to make sure it was going to work.

The first thing was to realize that the only difference in the IRC message was that the "source" changes from the user (drbob) to the channel (#Hoedown). The source at the start is the same, so we can still pick off the sender, we can now just see that it wasn't a private message, but one to a channel. Sweet.

Now let's see how to put this into our IRC interface easily.

The first thing is to expand the IncomingMessage struct to include the channel. If the message is private, then the channel is empty, and if it's a channel message, it'll be filled in. Simple. Then we can add the lines in the async message reader of the protocol to check the message to see if it's any of the channels we have JOINed, and if so, then slap that into the channel part of the IncomingMessage and have it "handled" on another thread.

In the handler we just have to see if there's a channel defined in the message, and if so, we can then call onChannelMessage() otherwise we'll call the old onMessage() for the private messages. The reasoning here was just to make it clear what kind of messages you are responding to. It doesn't have to be like this, but to me, it makes it very clear what you expect, and if you don't want to mess with channel messages, then simply don't implement the onChannelMessage() method and it'll be fine.

All this coding took me all of about 30 mins, and then I started testing it with a simple command - who has AAPL?

Sweet. Worked like a champ.

Then it was a simple process of migrating a few of the private chat messages to the "public" messages with private replies. Instead of errors, I just had it return nothing. That way, if the ticker plant doesn't have anything useful to add, it's simply silent. This makes a lot of sense for these types of chats.

In the end, I have a simple way to ask the System as a whole a question and have a private response from the one guy that can answer my question. I love this interaction. Very nice.

Favorite C and Obj-C Features of the Week

Wednesday, December 15th, 2010

xcode.jpg

I'm not sure if I'll do a lot of this, but today I was working and realized that there's something I've been using in C/C++ that I really love. I also was thinking about something in C/C++ that I don't love, and how Objective-C does is so much better. So I decided to have a Feature of the Week - for at least this week.

C/C++: Assignments Everywhere

I didn't used to do it, but of late, it's made my code so much more readable to me. Maybe it's me, maybe I've gotten to be a better coder, but I used to write a lot of code that looked like this:

  variant   *a = getVariant(3);
  if (a == NULL) {
    cLog.error("unable to get variant #3");
  }
  a = getVariant(2);
  if (a == NULL) {
    cLog.error("unable to get variant #2");
  }

and it's even worse in a re-used iterator:

  std::vector<std::string&gt::iterator   it = mClients.find("Steve");
  if (it != mClient.end()) {
    // do something with the fact we have 'Steve'
  }
  it = mClients.find("Jeff");
  if (it != mClient.end()) {
    // do something with the fact we have 'Jeff'
  }

But it doesn't have to be this way. With the C/C++/ObjC ability to have assignments anywhere, you can compress this all very nicely:

  variant   *a = NULL;
  if ((a = getVariant(3)) == NULL) {
    cLog.error("unable to get variant #3");
  }
  if ((a = getVariant(2)) == NULL) {
    cLog.error("unable to get variant #2");
  }

and the re-used iterator becomes:

  std::vector<std::string>::iterator   it;
  if ((it = mClients.find("Steve")) != mClient.end()) {
    // do something with the fact we have 'Steve'
  }
  if ((it = mClients.find("Jeff")) != mClient.end()) {
    // do something with the fact we have 'Jeff'
  }

Sure, this isn't rocket science, but it's allowed my code a new level of readablility - certainly in the looping where the definition of the variable is outside the loop and the assignment is within it. There's nothing like readable code. It's a real benefit.

ObjC: The Clever Mr. nil

But one thing I love about ObjC is it's use of the nil. It's far more than the C/C++ NULL because you can message nil with anything, and that's where it's so valuable for code readability. Take the following code, for instance. It's going to get a few things in a data structure, and to do it right, and by "right" I mean safely so as not to get null pointer seg faults, we need to do something like this:

  TPClient   *boss = getBoss();
  if (boss != NULL) {
    Channel  *chan = boss->getChannel("red");
    if (chan != NULL) {
      cLog.info("red channel has %d bits", chan->getBits());
    }
  }

Sure... you can be careless, and write this all optimistically as:

  cLog.info("red channel has %d bits", getBoss()->getChannel("red")->getBits());

but if there's any problem in those calls, it's a SegFault to be sure. But ObjC and nil can handle this nicely:

  [NSLog @"red channel has %d bits", [[[self getBoss] getChannel: @"red"] getBits]];

and the latter is so much more readable. It's the fact that you have to code defensively that kills the readability of the code. Not so in ObjC. It handles the possibility of any one of these steps returning a nil, and carries on as if that's expected behavior.

There you have it. My favorite little language do-dads for today.

Tough Afternoon – Glad I Pushed Through it

Monday, December 13th, 2010

Dorey.jpg

This afternoon I wound it exceptionally hard to get motivated. I mean really, really hard. I just wanted to do something a little interesting, but that was not in the cards. I didn't have anything pressing I needed to get done, and I was still waiting for management to make some announcements they had talked about, so I was really just in the "Just keep swimming" mode.

I had things that needed to be done - there's always things that need to be done. So I got a few of them out of the way. I need to make a parser for the ticker plant responder to change values, and I really couldn't get geared up for that this afternoon. It's going to be tough, and I need to be fresh when I start on that.

So I did the grunt work that needed to be done. Script updating... made a few shell apps for some things I'll need in the coming weeks... standard, but uninspired, stuff.

But if there's one thing I've learned over and over again... it's that the individual that pushes through these tough parts and continues to create, has an incredible advantage over the one that requires motivation. Pushing through the tough parts is a skill. It needs practice, and this afternoon my "muscles" are "sore" from the "workout".

Solid New IRC Features Deployed

Monday, December 13th, 2010

chat.jpg

This morning I finished up a lot of work I had started Friday afternoon about getting some useful features into the IRC interface for my ticker plants. I wanted to be able to get people something more than a proof-of-concept, but it was taking more time than I'd expected. I wanted to make it possible for any number of users to get the sampled stats I log to the Log4Cpp file. That meant I needed to modify the ticker plant itself to have a list of "interested parties" and then run through that sending the stats.

None of it was all that hard, but getting it all together in the responder and the ticker plant was just more time than I had to give on Friday evening. After I got that all working, I wanted to add a few more things: querying an instrument for it's messages... querying a family of instruments for their messages... restricting these to a certain message type... all things that I know the support guys are going to want to do.

I have to say that I'm pretty pleased with how all this is turning out. It's very easy to add these features into the responder and into the ticker plant. But then again, I've done this a few times, and I know the problems I faced in those previous incarnations, and what really worked well. This time I only had to do the "good" stuff, and it worked wonderfully.

I'm not nearly done, but I wanted to get these all in and pushed up to the development environment where people can play with them. That will get them thinking about what I can deliver for them, and since almost all this is for the support folks, I wanted to get them thinking about this as soon as possible.

Good morning.