Archive

Archive for September, 2009

p-OOP-y

September 28th, 2009 admin No comments

paradigm-shift-cartoon

OOP (“Object Oriented Programming”) is a programming paradigm meant to encapsulate data in unique structures or “objects.” An example would be to create a class named Fruit. From fruit you could derive a class for an Apple and an Orange. From there you could go to a vendor Class so maybe Gala Apples. And so on.

The problem is that OOP is overused, poorly taught, and badly implemented. I’ve read a few blogs lately that mirror my own opinions of OOP. In theory the concepts are sound, in practice they create a layer of abstraction that only serves to confound other programmers. As a general rule of thumb I will never subclass more than 1 or 2 levels deep, if that. Luca Cardelli wrote a really good piece on the properties of OOP and why it fails in it’s current incarnation. He offers some advice as to how the it can be expanded to use better engineering practices.

Trivial example of how I might us oop:

// OOP.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <vector>
enum TYPES {OGENERIC,OFLOAT,OINT};
class Object {
public:
	Object(){
		_data = new unsigned char[6];
		_type = OGENERIC;
		_size = 6;
	}
	virtual ~Object(){if(_data){delete [] _data; _data = NULL;}}
	virtual void *GetData(){return _data;}
 
	size_t GetSize() const {return _size;}
	TYPES GetType(){return _type;}
 
protected:
	void *_data;  ///Pointer to class specific data
	TYPES _type;
	size_t _size;
};
 
class Object_Float : public Object {
public:
	Object_Float(){_data = new float[13]; _type = OFLOAT; _size = 13;}
	~Object_Float(){if(_data){delete [] _data; _data = NULL;}}
};
 
class Object_Int : public Object {
public:
    Object_Int(){_data = new int[10]; _type = OINT; _size = 10;}
	~Object_Int(){if(_data){delete [] _data; _data = NULL;}}
};
 
class ObjectManager {
public:
	ObjectManager(){
		_objectList.push_back(new Object_Int());
		_objectList.push_back(new Object_Float());
		_objectList.push_back(new Object());
	}
	~ObjectManager(){
		for(size_t i = 0; i < _objectList.size(); i++){
		        Object *tmp = _objectList[i];
		        if(tmp){delete tmp; tmp = NULL;}
	        }
        }
 
	void TestGet(){
		float *tmpFloat = NULL;
		int *tmpInt = NULL;
		unsigned char *tmpUC = NULL;
		size_t size; 
 
		for(size_t i = 0; i < _objectList.size(); i++){
			switch(_objectList[i]->GetType()){
			case OFLOAT:
				printf("Object of type float was found\n");
				tmpFloat = (float*)_objectList[i]->GetData();
				size = _objectList[i]->GetSize();
				for(size_t k = 0; k < size; k++){
					printf("  - Data[%d]: %f\n",k,tmpFloat[k]);
				}
				break;
			case OINT:
				printf("Object of type int was found\n");
				tmpInt = (int *)_objectList[i]->GetData();
				size = _objectList[i]->GetSize();
				for(size_t k = 0; k < size; k++){
					printf("  - Data[%d]: %d\n",k,tmpInt[k]);
				}
				break;
			case OGENERIC:
				printf("Object of type unsigned char was found\n");
				tmpUC = (unsigned char *)_objectList[i]->GetData();\
				size = _objectList[i]->GetSize();
				for(size_t k = 0; k < size; k++){
					printf("  - Data[%d]: %d\n",k,tmpUC[k]);
				}
				break;
			};
		}
	}
	void TestFill(){
		printf("Filling arrays\n");
		float *tmpFloat = NULL;
		int *tmpInt = NULL;
		unsigned char *tmpUC = NULL;
		size_t size;
		for(size_t i = 0; i < _objectList.size(); i++){
			switch(_objectList[i]->GetType()){
			case OFLOAT:
				tmpFloat = (float*)_objectList[i]->GetData();
				size = _objectList[i]->GetSize();
				for(size_t k = 0; k < size; k++){
					tmpFloat[k] = (float)k + 0.4f;
				}
				break;
			case OINT:
				tmpInt = (int *)_objectList[i]->GetData();
				size = _objectList[i]->GetSize();
				for(size_t k = 0; k < size; k++){
					tmpInt[k] = (int)k;
				}
				break;
			case OGENERIC:
				tmpUC = (unsigned char *)_objectList[i]->GetData();\
				size = _objectList[i]->GetSize();
				for(size_t k = 0; k < size; k++){
					tmpUC[k] = (unsigned char)k;
				}
				break;
			};
		}
		printf("/Filling arrays\n");
	}
protected:
     std::vector<Object*> _objectList;
};
 
int _tmain(int argc, _TCHAR* argv[])
{
	ObjectManager *mgr = new ObjectManager();
	mgr->TestFill();
	mgr->TestGet();
	delete mgr; mgr = NULL;
 
	return 0;
}

An obnoxious use of OOP:

class Polygon{
public:
	Polygon(){}
	~Polygon(){}
};
class Triangle : public Polygon{
public:
	Triangle(){}
	~Triangle(){}
};
class Octagon : public Polygon{
public:
	Octagon(){}
	~Octagon(){}
};
class Decagon : public Polygon{
public:
	Decagon(){}
	~Decagon(){}
};
class Square : public Polygon{
public:
	Square(){}
	~Square(){}
};
class Rectangle : public Square{
public:
	Rectangle(){}
	~Rectangle(){}
};
class Rhombus : public Square{
public:
	Rhombus(){}
	~Rhombus(){}
};

This is the type of fluff bullshit I see all the time. Basically using class name to describe use rather than simply doing something like: Polygon square; -or- Polgyon triangle; At some point you’ve deconstructed the object too far. Honest to god I was handed a library once where each class variable was given it’s own class. There were circle and sphere classes. In the circle was float origin2D[2] and in the sphere was float origin3D[3]. Never mind that circles can have 3D origins too… what a god awful waste of space.

theshadow

But what true evil lurks at the heart of bad OOP? Propagation error. The sins of the parents are visited upon the children. In other words: if you fuck up in the parent class you screw up the children and errors like these can be extremely hard to track. Never mind the nightmare you’ll have if we get in to multiple inheritance. Or my personal favorite, multiple inheritance of template specialization classes. It’ll make you cry.

Over reliance on popularized paradigms is a problem endemic to most computer science(CS) & software engineering programs, the latter being slightly more resistant. Colleges push the memorize now, use later approach. Students are left with thought exercises that tax only the theoretical side of programming leaving little room for practical application. The end result is a body of programmers ill prepared to deliver production code. You’ve met these programmers; they’re the ones who use each and every meeting to extol on the virtues of their revolutionary framework, the ones who learned the hottest “it” language, and the ones who think rote memorization is a skill.

Categories: Uncategorized Tags:

Game design fail

September 24th, 2009 admin No comments

The first 1:30 of the video explains the premise and also clues you in to the secret. If you want to be surprised I recommend skipping that first section and watching the rest of the video. I’ll briefly spoil it below.

GRRF – The Last Lecture from Lumalin Productions on Vimeo.

We’ve all been there: You’re up against a deadline and you’re asked to do some sort of demonstration. So you cobble together the latest build, find religion, and start praying that whatever deity you’ve chosen isn’t capricious enough to punish you for years of non-belief. The video does a great job of demonstrating what can happen when things keep failing. Even knowing the setup is fake I found myself cringing every time something failed and watching as the poor demoer spirals out of control. Good for that girl in the front row who beat out the bystandard effect (also known as the “Genovese syndrome”) and helped the presenter retrieve his fallen computer.

Categories: Uncategorized Tags:

Verizon and the little engine that couldn’t

September 2nd, 2009 admin No comments

Let me share with you a story of Verizon’s epic fail setup process.

Faerie Tale Version:

It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness;  Really only foolishness.

In Massachusetts there lived a man, a man who only wished for ‘teh internets’ at his new apartment.  One day the magical tubes of internet spit forth the glowing faerie of net packagery.  And lo’ did she say to the man “Leave you the Comcast behind and seek the Verizon for she is good and pure.”  And so the man did seek the Verizon.  But this is not a happy tale.  No, the man’s trust was misplaced in the little net faerie.  For you see, the Verizon is powered not by pixie dust and child laughter but by the soulless machinations of Ogrism and Douchebaggery.

For several hours did the man do battle with the minions of Verizon.  Pushing, as best he could, through the labyrinthian quagmire of  indolent helpers that serve the great beast.  At long last, when all seemed at an end, there was hope.  A glimmering beacon amongst the gray brown apathy with which he had thus far dealt.  Just as the man’s hand closed about the life giving pulsar it was snatched away.  Dashed by the great Verizon beast against the rocks lest future generations find similar hope.  Like I said, this isn’t a happy tale.

English Translation:

I signed up for Verizon at my new apt.  This is a transcript of what follows:

  1. Signed up online for the basic internet package
  2. Received a confirmation email telling me how to modify my account and check my order status
  3. Can’t log in to the website, it told me my # and name were incorrect
  4. Tried calling support.  After a sales pitch the rep. realized I just wanted info. and transferred me to tech. support.
  5. Tech. support gives me my account number but transfers me to billing to fix my account since they can’t.
  6. Billing puts me on hold to “talk with a manager”  30 minutes later I hung up.
  7. Tried logging in with my new acct. number, it doesn’t work.  Surprise surprise.
  8. Went to Verizon contact page for the local number.  It tells me I can use a “chat online” feature.
  9. I enter my question in to the chat online client.
  10. AFTER I put in my question and hit submit the client tells me: “I’m sorry, this service is no longer available.”  That’s fucking nice, maybe the Verizon site could stop including it as a contact option when trying to get a phone number.  Even a pre-warning that the service no longer works just in case I like submitting questions to the ether.
  11. Called Verizon again.
  12. Women seems genuinely able to help me
  13. Hope is dashed, again, when I’m told that no matter how the order is placed the system won’t let me schedule an installation earlier than the 15th of September, I move in to my new place on the 5th.
  14. Still waiting to hear back.

Setting up net access, in this day and age, should not be hard.

And a small note to Verizon if this pops up in a consumer google search:  I get that you want people to sign up for the whole package or at least to have a Verizon phone.  That doesn’t mean you need to assume the default is that all new users should have a Verizon phone number forcing the rest of us to search for the “I don’t have a Verizon phone” option.  Your system is rife with stupidity and annoyance.

I get the feeling Verizon is mainly focused on supporting FIOS.  This would be fine if my area supported FIOS, but it doesn’t.  I’m also struck by how convoluted their internal structure seems to be.  I’ve been transferred to many different departments.  It’s almost like I’m one of the family now, trapped in transfer hell.

Update [09/03/2009] – Oh my god it just keeps getting better:

  1. Called Verizon to see if can expedite the installation date.  Why must it be 2 weeks out?
  2. Customer Service informs me that I need to speak with E-Services to modify an order placed online.  Nevermind that my order was redone by a Verizon rep.
  3. Waited on hold for 20 minutes only to be put back on hold.
  4. Got disconnected
  5. Called back to simply cancel the order.  At this point I’ve probably spent 3 or so hours on the phone.
  6. 20 minutes of hold and I’m told we can expedite the process but that they can’t give me a date.
  7. Canceled the order

Finally I gave up.  I called Charter and it took all of 15 minutes to get me up and running for this weekend.

Categories: Uncategorized Tags:

Not dead yet

September 1st, 2009 admin No comments

The Dead Collector: Bring out yer dead.  [a man puts a body on the cart]
The Dead Body That Claims It Isn’t: I’m not dead.
The Dead Collector: ‘Ere, he says he’s not dead.
Large Man with Dead Body: Yes he is.
The Dead Body That Claims It Isn’t: I’m not.
The Dead Collector: He isn’t.
Large Man with Dead Body: Well, he will be soon, he’s very ill.
The Dead Body That Claims It Isn’t: I’m getting better.
Large Man with Dead Body: No you’re not, you’ll be stone dead in a moment.
The Dead Collector: Well, I can’t take him like that. It’s against regulations.
The Dead Body That Claims It Isn’t: I don’t want to go on the cart.
Large Man with Dead Body: Oh, don’t be such a baby.
The Dead Collector: I can’t take him.
The Dead Body That Claims It Isn’t: I feel fine.
Large Man with Dead Body: Oh, do me a favor.
The Dead Collector: I can’t.
Large Man with Dead Body: Well, can you hang around for a couple of minutes? He won’t be long.
The Dead Collector: I promised I’d be at the Robinsons’. They’ve lost nine today.
Large Man with Dead Body: Well, when’s your next round?
The Dead Collector: Thursday.
The Dead Body That Claims It Isn’t: I think I’ll go for a walk.
Large Man with Dead Body: You’re not fooling anyone, you know. Isn’t there anything you could do?
The Dead Body That Claims It Isn’t: I feel happy. I feel happy.
[the Dead Collector glances up and down the street furtively, then silences the Body with his a whack of his club]
Large Man with Dead Body: Ah, thank you very much.
The Dead Collector: Not at all. See you on Thursday.
Large Man with Dead Body: Right.

:)   There isn’t a day in my life that can’t be explained through a Monty Python bit.  (The inverse is not true, I have not tried to return a dead parrot nor do I leap through doors yelling “Noooo body expects the Spanish Inquisition!)

I’m posting this small bit to say that I’m not dead despite the lack of blog updates.  Been busy packing up the apartment, getting ready for graduate school, and stressing out over my upcoming wedding.  I look forward to the day when all I have on my plate is work and school.

Also just got back from seeing Nine Inch Nails in Chicago.  Chris and I flew down for their last tour.  Aside from not playing “Closer” the concert was a blast.   We managed to snag front row seats on the balcony.  This might not sound great but keep in mind that the entire concert is general admission and the floor is standing room only.  Being the old men that we are we wanted the best possible vantage the required the least amount of exertion.  My phone has a few photos from the show that I’ll post so ppl. can see how good our view was.

Peace.

Categories: Daily Life Tags: