Lesson to learn in the 25th anniversary of “Prince of Persia”

Prince of Persia is a fantasy platform game, originally developed by Jordan Mechner and released in 1989 for the Apple II, that represented a great leap forward in the quality of animation seen in video games. On Apr 17, 2012 Jordan Mechner released the source code of Prince of Persia.

Many gamers remember this amazing game, and maybe some of you played with it for many months.

pp0

The developers of  these days remember there was a time when a typical personal computer might have an 8 Mhz processor, 1 megabyte of memory, a 20 megabyte hard disk, and a floppy disk drive. It was a big challenge to develop a game like Prince of Persia.

Moreover in those days, Google was not there to help developers resolve their technical issues quickly; some technical problems could take the developers many days to fix them. And the cherry on the cake was developed using 6502 assembly language.

However, with all these constraints, the source code is well implemented:

  • It’s  modularized using directories and files:

Modularity is a software design technique that increases the extent to which software is composed from separate parts, you can manage and maintain modular code easily.
Prince of Persia was modularized  using directories and files, this modularity is provided by the operating system and can be applied to any language.

The code is splitted into many files, here’s a list of some of them:
pp6

  • The naming is easy to understand

When exploring the source code, you don’t find variable names such as a, b or x, like many recent developed projects. The names are well chosen and no need to comments to explain why we need them.

pp2

  •  The code is splited into many small subroutines

The 6502 assembly language is very low level, and to make the code easier to understand and maintain, the “Divide and Conquer” principle is applied. Indeed the code is splitted into many small subroutines, what makes them easy to read and maintain. Here’s an example of a small subroutine defined in its source code:

pp3

 

Even If  in 1989 many constraints complicated the task for developers, the code is very well implemented. So why in 2014 with  powerful computers, powerful languages, Many thousands of libraries and Google, some projects are bad implemented ?

Languages and frameworks are just tools to build applications, but the main actor is the developer. You can use the best language, the best frameworks and produce a bad code.

Many practices to make the code clean  are not language dependent. A good developer must have the good sense and make its code clean and easy to understand whatever the language used.

Leave a Reply

Your email address will not be published. Required fields are marked *