Object-oriented programming, where is it now? When I was at college we learnt a little about object methods and techniques and when I left I kept reading about them. I remember in the 90s I was incensed that an employer was NOT using object methods appropriately. I EVEN read books about it. You could say I was an object fan-boy. But even I have to admit that OOP didn’t exactly deliver how I expected it would.

You may say that this is a crazy talk and that OOP was/is hugely succesful. Shark-jumping mumbo jumbo. But I might disagree. In fact, sometimes I think the object-baggage we’ve inherited is perhaps as much a hinderance as it is a help. The wake-up call came a few months ago when I realised that almost every piece of code that I’m in contact with these days makes only limited use of object-techniques.

Before I talk about all the ways that OOP is dead let me be clear in the ways that it is not. Because when I say OOP is mostly-dead, I mean it is mostly dead to me. In some areas OOP has delivered in spades. For example in modern OO programming languages nearly all come complete with large object libraries. This much is true. There’s objects in them-thar binaries for sure. But my code? Not so much.

Here’s all the ways I manage NOT to write truly object-oriented software:

The Task is Too Small

Some systems are just too small to develop a complex object class hierarchy for. It would be a waste of time to do so. I estimate these ‘glue’ applications could take up as much as 5% of the total LOC of a large enterprise system. It doesn’t matter whether these glue applications are written in Java or Python or Bash because really they’re just scripts. Scripts are their own thing. I would argue that the less scripts you have in your system the better you designed it because you’re not just duct-taping over the seams.

The Spreadhseets Rule

I would also estimate that some appreciable percentage of your enterprise is run entirely from spreadsheets. Whether you know about it or not. Be it phone book, accounts, trading system or stock inventory. These little beauties contain little or-no object code and are spread far-and-wide. I’ve ranted about the pervasiveness of spreadsheets before, no need to go over it again. However, as far as I know, no-one has implemented the idea of an OO spreadsheet. For that we can all be thankful.

World Wide Wasteland

Although the web does lend itself beautifully to model-view-controller, on the client side a lot of it is only markup and Javascript. Neither markup nor JS have particularly strong OO characteristics and both are hugely succesful without those OO characteristics. Indeed many WWW apps are really CRUD applications.

CRUD

The create-update-delete application is everywhere. Be it web-or-desktop. These apps are effectively database front-ends that organise the interactions between user and DB in a more user-centric way. For example in .NET there’s not much need nor desire to map your data into real-objects because the data-binding layer is phenomenally powerful at making data-bound apps quickly. There’s no support to help you map from data to objects to Infragistics. Indeed, nor should there be.

Enterprise Business Objects

JSP And this is the bit that makes me a bit sad inside. This is what OO was really meant for. I used to have arguments with business-analysts about the right object model to use and whether a method should exist in a base-class or a derived-class. But now it doesn’t seem like anyone, including me, really cares. It’s just that somewhere along the line it became a little irrelevant. Don’t get me wrong, I work with objects all the time. But they’re not really objects that were sold to me.

They’re just data-holders or as our fathers used to say: data-records.

No Methods? No Object

The thing is that to me at least, without methods on your objects there’s literally no object. If objects doesn’t respond to messages they’re just data-records transferring data to some other module that can operate on those records. Usually this other module takes the role of a controller. This, to me, sounds very similar to the programming that our fathers used to-do before C++ and Java 1.1. So much so that it’s tempting to break open my book on JSP.

I think there are two fundamental areas where objects failed to deliver.

Finance This

Firstly, whilst OO techniques are very flexible in some business domains they aren’t flexible in exactly the right ways for all business domains. I’m thinking particularly about my own area of expertise, which is financial trading systems.

The objects in trading systems tend to be difficult to compose into a meaningful hierarchy that is both expressive and not too abstract. I think ultimately this failing is because financial instruments are actually themselves models of physical events. This means that it’s straight-forward enough to construct an object-model of financial instruments. However as soon as I start innovating with my financial instruments (i.e. construct new financial models from old ones) the original object models tend to break-down pretty fast.

The Technology Stack Sandwich

The second reason is that there are too many different technologies involved in many enterprise-sized solution stacks to make consistent application of OO methods viable. What does that mean? Well this is perhaps a post in itself but essentially as soon as you are using two or more programming languages that must share objects you’re essentially entering an object-desert.

The End?

Oh no. Very definitely not. Objects are the only way to make sense of a deep-and-wide library. If the domain allows it they are the only way to go.

The surprise is that objects just didn’t deliver in the way that I thought that they might for me. Which is kind-of interesting because it suggests to me that perhaps me, and a lot of people like me, might benefit from forgetting about objects sometimes and just Programming Like It’s 1995.

For some reason the Git that ships with Cygwin (v1.6.6.1) won’t do the right thing with NTLM proxies. It seems that Git uses cURL underneath and that cURL can correctly handle NTLM authentication if the options are set correctly.

However, the version of Git I have isn’t capable of passing this information through. In fact, some browsing of the issues that people have with this suggests that there is more than one part of Git that isn’t able to work correctly with NTLM. So even if you’re able to get past the initial connection you probably won’t be able to fetch any of the tree.

The solution, in full then, is to use ntlmaps to act as a proxy to the proxy. All you need to do is to download the latest version of the app from: ntlmaps. Change the config file to include your authentication and proxy details, start it up and then set the proxy to be your new local one:

git config --global http.proxy http://localhost:5865

I can confirm that it works just fine. Not only that you can use it for any app that requires NTLM authentication but does not provide full NTLM support.


Excel screen shot of XL-Gambit

XLREPL



In the spirt of shoving Lisp where Lisp should-not-go I have jammed Gambit Scheme into Excel.

If you’re interested in trying it out you should go and get the files RIGHT NOW at GitHub. You just need to add the compiled .XLL into your add-ins and use the formula =GAMBITC(“(+ 1 1)”) in a cell of your choosing.

Please note this is a proof-of-concept. You probably shouldn’t use it for anything important, most importantly because it probably leaks like a sieve. You should also know I only really tested it on Excel 2003. It should load into Excel 2007 but I didn’t try that yet.

Why? Because it’s there, and I’m here

Why did I do it? Well the rationale behind doing this was that I wanted to write an app for Excel in Scheme. I want to do that because I think it would be vastly superior to using .NET or VBA or COM. Having spent a few hours on it I think I could definitely achieve what I set out to do but whether I’ll actually go this route in the end I’m undecided about. More on that later.

Mature like a good cheese

The Excel API, as it turns out, is … well … mature. Now I like old things quite a lot. I’m old, and I like me just fine. One consequence of age is that we get a little extra baggage on the way. This is true of Excel too.

Now, IMHO one of the more challenging aspects of programming a long-lived project is version management. Especially version management of an API. Broken backwards/forwards compatibility of those APIs could be serious impediments to a new Excel’s acceptance. Unsurprisingly then Excel has a number of APIs that have all undergone various enhancements over the years. To me though the switch from Excel 2003 to Excel 2007 was the most significant, requiring the most additional cognitive load to work with. For now, and for simplicity, I have chosen to totally deny the existence of Excel 2007. But I’m coming back to it, oh yes I am.

I Eat Pain For Breakfast

I had read a bit online about the Excel C API and found it all hugely confusing. So I bought a book thinking that that would make it clearer. Although the author does attempt to explain how you might write an Excel add-in he does it in a way that makes programming from it hard. For example, the information I need is spread all-over the book. Answering a single question about Excel’s behaviour with respect to calling the core Excel4/Excel12 function necessitates flicking between the index and more than 10 different page sections.

The reason for this is probably that Excel is really a very versatile tool which is why a lot of the world’s business (large and small :)) seem to operate their database, accounts and customer details from it. So there’s not really one track through the development process. There’s literally hundreds, limited only by your imagination!

Having said that the book in combination with the Excel 2007 SDK was sufficient to pick through the rubble and build something workable. Maybe I’ll try and produce some guides/tutorials of my own to make the topic clearer. Maybe.

On the Gambit side there’s not much more documentation than what’s on the manual HTML page to help. Like the Excel book it is also very densely populated with information. IMHO its main failing is that it could really do with having more documentation of the C macro functions. Did I ever mention that I hate C macros? Well in Gambit these undocumented C macros are effectively what Gambit Scheme is written in and you kind-of need a fairly thorough explanation of how it all fits together to be able to make an effective glue with them. I will be coming back to this later when I try and construct lists from cell ranges.

Finally I decided to do this all in MinGW rather than the more usual VC++. Whilst going this route did cost me a bit of time I’d much rather use the GCC toolchain because I understand it better.

Where-to-now

Now that I have the interpreter in Excel I will probably work on tidying it up for Excel 2007. More importantly though, I want to see if I can exploit Excel 2007′s all important multi-threading capability.

If that all works out I might use it to make a custom add-in. I will develop the app from the REPL in Emacs using Gambit Scheme. When it’s done I’ll compile it up into a standalone XLL with Gambit. That’s the plan anyway.

Let me know if you like it, or can see a use for it. Encouragement is always good.

My eldest daughter has been getting maths homework for a year or two now. We try and do the homework together and I try and make it fun but it’s hard. It’s hard because if she doesn’t understand something by the second time I explain it, then to her I become like the teacher in Charlie Brown. Blah Blah Blah. This is especially true if when I’m explaining elementary mathematics, I make a mistake in my explanation. This happens often and only causes to confuse her royally.

And so it was with the topic of number bonds. My wife discovered, by attending a parent’s maths workshop at the school, that the children were learning that certain numbers in base 10 arithmetic are bonded. The bonds are simply as follows:

  • 1->9
  • 2->8
  • 3->7
  • 4->6
  • 5->5

It’s fairly trivial but also fairly powerful in that once you know these bonds it’s a shortcut for mental arithmetic. We, as adults, know these ‘bonds’ so well that we probably don’t even recognise that we use them. The challenge then is to teach children this trick and thereby speed up their arithmetic ability.

One of the techniques that my daughter’s school uses is to send home ‘games’ that try and reinforce the learning they have done in the class. These games usually consist of a laminated sheet of instructions, a dice or two or other simple props. Usually these games are quite good and instructive. Some times they are totally confusing because they are meant to reinforce what was learnt in class and that doesn’t come across in the instructions. You’d think that I could ask my daughter to explain ‘how’ they should be doing it. It doesn’t work. Kids just aren’t that ‘meta’, that’s why they’re so much fun.

Now I have observed both my children playing on friv and Club Penguin. They are totally immersed in the most crappy Flash apps (although I have to say that most of them are actually quite fun!). So I thought I’d try and see if I could make a Flash game that would teach a little mathematics.

A while ago an ex-colleague posted about a super-cool Flash application he’d made. From that I figured out I could download the SDK and most of what I needed for free. However I thought I’d try the 60-day trial of Flex Builder. The added comfort of Flex builder is that it’s a pre-configured Eclipse for building Flash apps, so progress is pretty smooth-and-fast. Not sure I’d spend the $299 for a personal license though. It’s not that good.

I had always thought that Flash development was complex but it turns out that it really isn’t. If you can program Javascript, then there really isn’t that much extra to learn to make it work because you can use ActionScript (which is a derivative of ECMAscript as Javascript is). The biggest difficulty I found was with laying out text. Something that HTML laps up, but turns out to be really cumbersome in Flex. I’m probably just doing it wrong.

And so the unimaginatively titled ‘Number Bonds’ was born. Enjoy.

If you’re interested in the code it’s here. It’s pretty messy though. I’ve also made a back-story-free page about ‘Number Bonds’ here.

This week a colleague pointed out this comment from an Ask Reddit:

danceswithwolves 62 points 4 days ago* [-]

I went to a job interview and the interviewer told me I would get the job (my first full time job ever) if I could answer this math question which is supposedly a middle school grade question. I had no clue how to solve it so I’m jobless now and suffering. To this day I never figured out the answer. http://img691.imageshack.us/img691/2192/mathv.png (The lines are curved if that makes a difference)

Basically the problem asks you to find the area of a sort-of-square, inside a square of side 4. Each corner of the outer-square is joined to the adjacent one by an arc of angle pi/2 radians (90 degrees) of radius 4. The sort-of-inner-square is outlined by the four crossing arcs. See the link above, or the picture below for a diagram.

Normally when faced with puzzles of this sort I try and pretend I’m too busy to figure them out. Partly because I’m belligerent, bordering rude, and partly because I know I’m a bit dumb. If my life depended on getting the answer I’d be dead already. So it was a strange thing indeed that I found myself working on and actually enjoying this particular puzzle. I did, of course, out of all of my colleagues get to the answer last.

It then occurred to me that I could regain some cool by trying to draw a better diagram (than the one in the comment) using the Common Lisp vector drawing package Vecto. It was actually a lot easier than I thought it was going to be and came out quite nice, the result is here: Area of shape the code is here.

After arriving at our respective numerical answers some bright-spark said that it should be possible to verify our results using Monte-Carlo methods. I thought about this for a bit and then concluded that it would actually be quite easy to do, especially in Lisp where functions are first class objects. You can see the code here.

As fun as it was to find the answer by Monte-Carlo it was a bit of a waste of time since I could have just as easily subdivided the area into a grid of tiny squares and then counted the ones that were inside and outside the shape. This would have been simpler to code and it would have been more accurate too.

Pythagoras would probably have known that of course.

Next Page »