Diaspar Was Not Always Thus

Review: Clean Code, by Robert C. Martin

Tarzan is dreaming about code.

Clean Code: A Handbook of Agile Software Craftsmanship, by Robert C. Martin, has been an excellent resource for my computer programming projects. I am a self-taught programmer and therefore have always have a few holes in my knowledge of code-writing, mainly the fundamental theories and “best practices”. Martin’s ideas on naming conventions has probably been the most informative section for me. Aside from basic style guidelines, Martin discusses some very abstract ideas, such as polymorphism and concurrency, as well as other object oriented fundamentals. The examples in the book are all Java, which I have no experience in, but it does not deter from my ability to walk away from the book with new insight and ideas. The most interesting and valuable facet of Martin’s writing is his ability to clearly describe and explain the abstract concepts that are such a core part of computer programming. There are a number of illustrations that leave quite a bit to be desired aesthetically, but are hilarious and, nonetheless, a great addition, (e.g. The Bottled City of Kandor, Data from Star Trek, drunk sailors representing the chapter on formatting)

You can find it on Amazon and Alibris.

Bibliography:

Martin, Robert C. Clean Code: A Handbook of Agile Software Craftsmanship. Boston: Pearson Education, Inc., 2009.

June 24 2009 0 Comments

Convert Int to String [C++]

A function to convert an int to a string:

#include <string>
#include <sstream>
std::string convertIntToString (int theInt) {
 std::stringstream out;
 out << theInt;
 std::string theString = out.str();
 return theString;
}

Thanks to this post by Rares at Not So Frequently Asked Questions.

June 19 2009 0 Comments

Creating new instances of classes [C++]

When you are creating a new instance of a class in C++, and there aren’t any parameters in the constructor, then don’t define your new class with the constructor parentheses. If you do and you then try to call a method of your class, you will receive a compiler error such as this:

error: request for member `addImageNode' in `theDoc', which is of non-class type `XMLDoc ()()'|

Here is an example:

#include <iostream>

class TheClass {
 public:
  int a;
  TheClass() {
   a = 4;
  }
  int theMethod() {
   return a;
  }
};

int main () {
 //TheClass myClass(); // Incorrect
 TheClass myClass; // Correct
 std::cout << myClass.theMethod() << std::endl;
 return 0;
}

If the incorrect definition is used and then theMethod() is called, the error will show. If theMethod() is not called, then the error will not show, but the problem will still exist.

SO, if your class constructor does have parameters, define your new instance without the parentheses!

I owe it to this post at tazzdeken.wordpress.com for the answer.

June 18 2009 0 Comments

How to define a class [C++]

//class definition
class Person {
  private:
  //public variables and functions
  public:
    int age;
    std::string firstName;
    //constructor function (exact name as class)
    Person(int $age);
    //destructor function (exact name as class with a ~ as the prefix). may not take parameters
    ~Person();
};

//constructor definition
inline Person::Person (int $age) {
  age = $age;
}

//destructor definition
inline Person::~Person () { }
June 18 2009 0 Comments

New Flash Image Gallery

Check out the new image gallery I have developed in Flash and ActionScript 3.0. It is installed on my main portfolio web site. You can also download it here:

new_gallery_1

June 4 2009 0 Comments
  Copyright © Michael Moore, 2009.
  Powered by Wordpress. Theme by Michael Moore.
  Optimized for Mozilla Firefox 3+.
  Background pattern by Travis Beckham.