Another win for exceptions

In C++, exceptions have many advantages over traditional “error return values”. They’re harder to ignore, they’re a lot more flexible, you can use them in constructors, they don’t use up your return value slot, etc etc.

I’ve just noticed another advantage. Imagine you’re doing old-style success/failure return values. Somewhere in a deep chain of calls there is a failure, which gets manually propogated up to the top level. At the top-level, you get a failure value but how do you find the original failure point? Usually by binary searching down through the code.

If you’re using exceptions, you can set the DevStudio debugger to stop at the point where an exception is thrown. This immediately shows you the failure point.

Then again, you could always just code in ocaml and use it’s timetravelling debugger! In ocaml, you run your program until you notice the failure, and then you go backwards in time to find the original failure point. Ocaml rocks.

C++ Templates and IntelliJ

This Kuro5hin article about ” What’s wrong with C templates?” has lots of interesting questions/answers after it.

I’ve been eval’ing the IntelliJ IDEA java IDE recently. I’m not currently writing any java programs, so I dug out my old raytracer to try out the browsing and refactoring tools on. I’ve been hugely impressed by the feature set. The basic GUI is well thought out and useable. The autocompletion and refactoring facilities work well. It has many “intentional” features – for example, you can type in code which refers to non-existant functions/classes, and it’ll provide a little icon which allows you to choose “create this class” or “rename this reference”. It is integrated with CVS, JUnit and Ant. It also has it’s own local version control system, so you can ask it “what changes did I make in the last 5 minutes”. I’ve not yet found out how it handles searching API documentation, and it does require a whole heap of memory. But, it’s definitely way cool. Java isn’t the best language in the world, but IntelliJ idea makes the whole kaboodle very attractive.

Naked Objects

From LtU, A brief introduction to Naked Objects. This sprung up in response to a question on squeak-dev along the lines of “if squeak if so OO, why do we use so much ascii text?”. This is closely related to work done on the Self language, which I looked at a few weeks ago. Self is a runtime-typed OO language, but without the notion of classes. Objects aren’t instanstances of a class. They just are. Self also has a morphic-esque direct manipulation GUI whereby you can leap in an manipulate any object directly. The big idea behind Self is one of a consistenly present world of manipulatable objects, much like the real world. Unfortunately, the Self runtime is only available on Mac and Sparc, of which I have neither, so I can’t play with it. But, the ideas are interesting. C++ certainly doesn’t present a “consistent” view of the world – using a std::map from the “source world” and using it in the “executable world” with the debugger are as different as night and day. Or at least they will be until someone writes a nice debugger plugin API for displaying custom types.

The other gem I’ve recently discovered is the ever-popular Big Ball of Mud programming pattern.

This sentence is false

  • I write programs to solve problems.
  • I spend a lot of time writing these programs.
  • During this time, problems relating to programming pop up.
  • I want to solve these problems too!

If you want to start writing tools which manipulate programs, you require a vocabulary which includes nouns like “type” and “function” and “literal”. Most sane people think of, say, mozilla as a program which you execute, but today I’m thinking of it as a dataset. I’m not going to run mozilla – I’m going to process it!
Continue reading “This sentence is false”

Visual Assist

Although I play with lots of different languages, work is a C++ shop. Until recently, I’ve used a combination of DevStudio (for code writing and debugging) and emacs (for oo-browser, pcvs and ediff). A few days ago I downloaded the eval of Visual Assist and I’m amazed that I’ve been without it for so long. Actually, I think I tried a very early version once and wasn’t impressed.

It basically does auto-completion and tool-tip API hints reliably, which is more than can be said for DevStudio. This means you spend more time editing code, and less time flicking through API documentation – a very good thing. They have a decent parsing engine in there too, so they can do “find next/prev usage of symbol” too. I’ve now written my own DevStudio addin which uses this feature to provide a “rename local variable” refactoring.

It would be very sweet if they were to expose an API to their symbol database. I could do so much with it …

Incredibuild was my other find recently. It’s a distcc for DevStudio, and again it works well. Anthony has already blogged about how we use it.

Squeak 3.5 has been released, so I’ll be looking at the improvements sometime soon.