Avoiding down-casts in C++

If you have to down-cast objects from a base class to a derived class then there’s probably a design flaw in the class structure. It might all work but it’s going to be a brittle design.

A better way to accomplish this is to give the users of your code the right tools in the first place as member functions, rather than them having to cobble together their own routines in userland:

Much better =D

Design Pattern Relationships

I’m reading Design Patterns: Elements of Reusable Object-Oriented Software at the moment, because when it comes time for me to write the biggest project I’ve ever worked on (which’ll be in a couple of months), I want it done on solid foundations, and without re-inventing the wheel. I’d heard of design patterns before but never used them in any of my code, so it’s going to be a pretty interesting learning curve – I’m actually kinda excited about it all.

Anyways, I came across this diagram in the book and thought it was pretty spiffy in the way it shows relationships between patterns, and what patterns work with others.

Design Pattern Relationships

Neat!

Linkage #8 – Random is as random does

  • What links insects, prime numbers, image-tiling and web design? Why not find out… It’s clever stuff =D
  • The art and programming behind Tron: Evolution (also, eMacs!) is pretty beautiful, especially if you like particle effects, as I do. The first Tron gave us Ken Perlin’s Perlin Noise technique, check it out to see where we’ve gone from there.
  • The Typing of the Dead was the only type-to-shoot game I’d seen with that particular mechanism, until I saw this online typing-based shoot-em-up called Z-Type. Certainly sticks it to Mavis Beacon =P
  • Fancy randomly teleporting around the world in Google Streetview? Then you’ll want to know about GlobeGenie. It’s kinda cool, and unlike Jumper, you don’t have to have been there first…

  • How a wok works, explains, well… you get the idea. If you think you already know, you might be surprised to find out just how wrong you are – or at least I was.
  • Resource Acquisition Is Initialisation (RAII) (wikipedia) is a clever way of programming interfaces to data/files/objects which puts all the initialisation and clean-up code in the constructors and destructors – but you have to be careful that your constructor can’t fail, or if it does, it’s handled properly. Still, it kinda appeals to me as an elegant method of doing things.
  • Sometimes it’s useful to be able to automatically reformat code, and knowing some of the online beautifiers in this article could definitely save you time. Also, for clearing up blocks of text there’s CleanText.org.
  • You can enhance flavours by diluting them with water? ORLY? Seems pretty counter-intuitive, but apparently so.
  • Hammer + wall + lots of nails + talent + time = unique & spiffy artwork. I don’t know if I’d have the patience for that, but hats off to the guy, it looks great. More Marcus Levine art at his site.
  • There’s a lot of great time-lapse landscape sequences out there, but this guy has to make some of the very best: The Mountain.
  • You know those things where you stare at a black and white image for 30 seconds, then look away and you can still see the imprint for the next 30? Well, this is a kind-of a strobe version of that. You don’t see an image, instead the entire room swims like you’re underwater or something. Not for people with epilepsy, but something you might want to do once just for the experience.