Saturday, February 17, 2007

Pythonic C++

Pythonic C++ may not be possible. :-) However, this simple trick will allow you to better follow PEP 8 without recurring to pre/post-fixed notations when accessing variable or function members:

Car::Car(unsigned engines) :
Vehicle(4, engines)
  // use reference instead of pointer ;-)
  Car &self = *this;

  self.position = 5;
  self.movement = 10;

Amazing, isn't it ? :-D With just a simple trick we have boosted code readability by one million. PS: how do I highlight "self" ? :-)

No comments: