Thursday, 3 March 2011

Never Reinvent the Wheel

In these days I'm writing a small roguelike. I started it in Java, but soon I moved to LÖVE, a framework for 2D games based on OpenGL and Lua. After some days I've got "something working" (moving camera, smooth characters, entities, doors, items) so I reflected about the "reinventing the wheel anti-pattern".
As a programmer, I enjoy to write code. I tried many times to write an OpenGL 3D engine; I tried many times to write a 2D platform game engine. But after all, is a good idea to write yourself all this code when somebody already did it?
Obviously no, but believe me: to reinvent the wheel is a strong temptation and, often, we follow it unconsciously.
Don't invent your own configuration language: there's already Lua.
Don't write your own 3D engine: there's Panda 3D, Crystal Space, Irrlicht Engine, Ogre 3D, the various ID Tech (now they're under GPL).
You'll earn time and you'll see result sooner then you think, allowing you to give more attention to the most important things of your program.

Wednesday, 2 March 2011

The endless VIM vs EMACS debate

Many programmers prefer using VIM instead of EMACS. They claims it's better because it's faster, smaller and easier to configure.
What to say about?
In these days I wrote a small iPhone framework in python. It requires a TAB-separated-Table as input. I used Aquamacs to write this input file and my program crashed. Why? Aquamans inserted some tab characters, I don't know why.
I rewrite that input with VIM and all worked well.
Another "life case": I tried to install lua-mode on a Windows 2000 workstation and on my MacBook Pro. I failed in both cases. I think after two tries, a system is not enough user friendly, so i give up.
Confused? It's normal. VIM has a easier learning curve. It's boring to write tons of code, but it could be more usefull than EMACS. EMACS is good if you accept an "evolutionary model", where you write day-by-day your .emacs file.

And if you are tired, there's always JEdit :)

Wednesday, 16 February 2011

No classes and objects in Lua. So...



So let's use old-C structs :D
How?
Image a struct to define a 2d point. It will looks like

struct Point2DStruct{
    double x;
    double y;
};

typedef struct Point2DStruct Point2D;

Point2D* new_Point2D(double x, double y){
    Point2D* result;
    result=(Point2D*)malloc(sizeof(Point2D));
    result->x=x;
    result->y=y;
    return result;
}

How we can do something similiar in Lua? With a table!

function new_Point2D(newx,newy)
    result={x=newx,y=newy};
    return result;
end

Easy, fast, and good looking. Well, you can also implement objects and classes using metatables. But I prefer using this "structured" way, because it's easier to read a to write.

Tuesday, 15 February 2011

No Memory on iPhone?

A rumor about new iPhone nano: they could be sold without memory, downloading dinamically from network. A storage location already exists: it's MobileMe.
It could be an interesting idea: but how much will cost in Italy, where our 3G network is expensive as gold?