Welcome to my new blog: lets see what is under the hood
Posted on: Thu 24 Dec 21:12:00 2009 under technology
I used to be a prolific blogger, having blogged almost every third day for a number of years. Unfortunately, that slowed since 2006, for a number of reasons, mostly time, software and the rise of "social networking"
Not anymore.
For three months on and off, I have been building the Really Awesome Blogging Software Solution™ I wanted something that suited my vision, and now its here
Hit 'more' to read about what powers this new website
Lessons learned on C++ and OOP in general
Posted on: Thu 24 Dec 19:23:52 2009 under technology
This blog was the first C++ project I have done from scratch (as opposed to hacking on existing projects like I have done before), that served a functional purpose.
One of the features of C++ is that it gives "choice"; one could write programs in either procedural or object oriented style. Object oriented is popular: Java, C++, Python, Ruby, C# and Objective-C just to name a few are object oriented languages. Meanwhile, C (which C++ extends) is a procedural language.
Lesson #1: "Pick a side"!
Writing parts of the software outside class objects simply broke my work flow later on, trying to context switch between two different modes of operation. Sure, in these cases the functions involved had no need to be wrapped in objects, but it proved better to make them into static class methods.
There isn't anything wrong with procedural programming in general, it just makes it easier for you to shoot yourself in the foot. A well designed procedural API makes it easy to create and do operations of data. One well designed example is CFString in Apple's CoreFoundation which really beats working with C's <string.h> any day of the week
Lesson #2: Abstract early and often
This is probably the most important lesson out of all. Early on I had built the blog post and comments view by simply extracting data from the DB at those points. No attempt to wrap the data in an object was made. Then I had to access that data elsewhere within the application, sometimes operating on one object or operating on several. So I finally built an OOP interface there. Had I done it right away in prototype stage I would've saved time.
The object models proved much better to work with in the end
Lesson #2.1: Model-View-Controller rules. Use it
This goes with the above, once Model and Controller are sorted, adding more functionality (i.e different ways to get data) by creating more views is trivial.
