Archive for January, 2010

Narcis For Linux - Revision 3 - Screenshot

I’ve been playing around with the full-featured English-Persian dictionary named Narcis. Narcis has been provided as a Windows application and AFAIK the development has been stopped. Just found it useful to have their rich database, so wrote some python scripts to decode the character set and export it into C++ source code format. Now I’m writing my Linux port using QT, C++ and Sqlite :). For more information on the project, refer to the N4L wiki page.

Post Mortem

Author: sohrab


Recently I took part in a group project. The time line was very severe and we were exhausted from our previous activity.

We started working with a rough design and split tasks. One day before the deadline we gathered to integrate our codes. My part included something unfamiliar, complex and tremendously unpleasant. After 5 hours of pulling out my hair off my head, I managed to do that. Now only a few lines and  it would be finished. As I was very tired, I decide to pair program this part to avoid errors. My partner and I did that in a few minutes we had and then released the code.

When I was preparing my code for the main event, I realized something was wrong. Some couple of hours led me to an obvious error. A single line that was placed 4 line above it’s correct location!

Well, this bug was found too late and rendered all our results based on the code unreliable and false. So the project failed.

Under the following circumstances, it’s not recommended to code:

1) After over 8 hours.

2) When you’re too tired or distracted.

3) Whenever you cant concentrate.

But it’s sometimes unavoidable to w0rk in some (or all) of these conditions specially when you can’t appoint the deadline yourself.

Then, what measures are to be applied to prevent errors and bugs that may result in a total failure?

I’ve come to the following methods:

1) Test each and every module you write.

2) Spare additional functionality in favor of reliability.

3) Have a firm and clear time line for testing.

What you pay vs. what you gain:

Testing is time consuming and requires extra effort. Most times you are writing parts that get input from other unfinished parts (e.g. written by other team mate). This means that to test them you need to provide test data. But the extra time pays off! Tested part lets you focus on other parts and give you a good idea where to NOT look for it, saving up some time debugging and probably prevents some undesirable results.

In the future posts I’m going to explore major testing methods as well as the ways proposed by some well-known SDK’s such as eclipse and Visual Studio.

Post Mortem is when you discuss what happened in a project after it’s finished. It literally means done after death or after an event (definition from merriam-webster).

You know about effects of advertisements in business context. When a new product is born, the company not only needs to introduce the product, but also should make demands for it. You see lots of things we’re using on a daily basis which aren’t really necessary and our predecessors were living happily without most of them. I don’t ignore the technology and the simplicity of human life caused by it but have you ever noticed your status before and after an advertisement for a cool product ? You were living without it, but after you knew about the product and the way it was shown to you, You would think about it and the way you can reach it !
Yes, Its trivial and wise, a common property of human kind.

But I was thinking about the way of life we choose for ourselves, in most cases we don’t take decisions based on a predefined road-map. Evidently there are lots of advertisements around us for different kind of tasks we can choose to do. As an example when you meet a musician playing a really beautiful and nice music, what your eyes see and your ears hear is considered as an advertisement for the music art/task. In such a situation, if there doesn’t exist any predefined road-map, you’ll choose to become a musician, or at least you would think about it. Or when you meet a poet or a computer scientist or a professional doctor that have chosen their jobs based on interest and have devoted their life into what they really like.

The above sentence might seem wrong since when you meet the musicians you usually don’t sense any effects or interests. Probably you haven’t meet the one who can really introduce/advertise their fields of interests correctly. Profession in a task is not considered as a prerequisite for advertising it, but it does actually help and is important. The other reason you might be affected by already, is that your current way of life forces you to do an specific task to gain some goods and you don’t want to risk and leave the current one for a new and interesting field.

It seems odd, since you’re judging about your self and claim that you have an interesting predefined map, but have you ever asked yourself What way exactly you’ve chosen the current one. Or What other fields you have ignored to choose this one ? How did you decide ? There is a time frame in everybody’s life time, in which he or she is not forced to do something and he can select among the fields or interests that are being advertised around him.

I want mainly conclude about the parameters affecting a person while he or she is in such a situation. Normal people usually obey the “what comes best and first algorithm” (AKA Greedy algorithm in computer science), ignoring the long time effects and so. Wise people usually list the different factors in their mind and consider the long time effect of each one, Sum it up and decide. The interest might be considered as one the factors beside the others.

And finally the Exceptional group of people, look only at their interests and choose the way, they are really interested in right away, While ignoring other parameters such as monthly rate for the job, reputation and popularity and the reflections in people’s mind, and so. They only consider them selves (and yes, this means they’re very selfish in this case) and won’t let other people and parameters choose their way of life.

So idealistic ? No, they’re out there, take a look.

Depressing life?

Author: sohrab


Once I heard that if you put a frog in a glass of water and then heat it gently, it wont move till the water reaches boiling point, and the frog dies. But if you throw it right into the boiling water, it will jump out immediately, it will be hurt, but it will survive!

Change the routine now, it WILL hurt, but it’ll refresh.

Happy New life!

In the past 6 years I’ve seriously started coding, and tasted many programming languages and syntaxes including C, C++, Java, Python and some others.  As you know, depending on your application domain and the problem you’re going to solve, each of them provide a degree of support on that domain. For example if you’re going to build some sort of heavy physical simulation program which needs real-time speed, I’m sure won’t choose Java or Python or any non-native and high-level language to do the computation in 1.4x time compared to C and C++.

Since last year when we started developing iPhone applications, I found interesting things in Objective-C language which I’m going to summarize them here.

The Syntax

As a matter of fact, Objective-C like C++ is derived from his parent, The C Language and both of them has moved toward adding Object Oriented Programming (AKA OOP) capabilities to C. So much of the syntax is shared between those three and we’re going to discuss the differences here.

One of the major concepts is defining the object itself (known as Class) and modeling the communication between them. Obj-C calls this communication a Message and C++ calls it a Method.

If you haven’t seen objective-c syntax, here I’ll present a few samples comparing to C++ to achieve a basic idea of the language. As the first example if you have an object instance named myObject and you want to call a method named myMethod from it, you should write something like this :

ObjectiveC C++

[myObject myMethod];

| |

And here is a sample code for defining a class in both of these languages :

@interface Car : parent {
// instance variables
+(int) getDefaultModel: (int)parameter;
-(void) Beep:(float) frequency : (float) duration;
-(int) setColorTo: (int) color andModelTo:(int)model;
class Car : parent {
// instance variables// Class (static) functions
static int getDefaultModel(int parameter);
// Instance (member) functions
void Beep(float frequency, float duration);
int setColorAndModel(int color, int model);

Since, I’m not writing an objective-c tutorial, you can take a look at references and links to find out more examples.

Header and implementation files

Both languages use separate definition and implementation files. In short, header for a class specifies the tasks it can do and the data it can contain while the implementation shows how it will do the tasks. The naming conventions suggests the .h extension for header files and .m extension for implementation files in Objective-C and in C++ you might see .h / .hpp for header files and .cpp / .cxx for implementation files.

A common practice for large projects, resulting in large objects, is to organize different parts of implementation in separate files. In C++ you can define a single header file for a class and split the implementations over multiple CPP files. This is done via Categories under Objective-C. In a category you add methods to the class, even if it is not defined in the original prototype. In other words, categories allow the programmer to extend class functionality. A common example for categories is to add resizing functions to UIImage class for example, so you would be able to re-size any UIImage after that.


In the Persian Poem Book project, we had really large books and we faced lags while the user was browsing the books. So we implemented a data pre-fetching logic in a separate thread. And this is exactly where we faced a synchronization problem. Having the system programming and C language experience, I thought, we should start using semaphores via the Posix API.  But I found that, just like Java, it’s as easy as placing a @synchronize keyword and the compiler will support you in that block of code ! Hurray !


Ok, Ok, the answer for C++ is almost anywhere !  Objective-c is natively supported and improved by Apple and you can use it for Mac and iPhone development. In addition you have a choice of GNUStep on many other platforms. From the :

The purpose of GNUStep project is to provide a Free Software version of the Cocoa/OpenStep APIs available on as many platforms as possible. GNUstep seeks to be source code compatible with Cocoa and OpenStep. GNUstep currently supports GNU/Linux, NetBSD, OpenBSD, FreeBSD, Solaris, Darwin and Windows and should be capable of being built and used on any POSIX compliant UNIX platform which has gcc and/or LLVM/Clang.

Standard Libraries and ports

I had an small experience in developing for Symbian mobile operating system. As you probably know, the SDK is based on C++ language. As a typical C++ programmer, I expected to have STL ported into that platform but there were no official support for it. Consider yourself writing C++ code while having no stacks, queues, vectors and even no std::strings ! Although there are some unofficial ports which has memory management problems when I tested them.

When I entered the world of iPhone development, I expected kinda poor support for libraries but thanks to Apple, you have almost everything as you have in a MacOSX development, since they’ve ported the Core Foundation completely plus a really useful documentation and reference.


Objective-C just like its brother C++ and their common parent C, is considered a low-level language, so it won’t have any overhead of Virtual Machine or Interpreter and your application runs as a native machine code. Comparing to Java, you have most of the capabilities and object oriented modeling syntax, while keeping it native and speedy and without any pointers. C++ tries to be much like his parent and in a real coding scenario, you should still use function calls and pointers and so. As a teacher, my experience shows that the pointers was the hardest thing to teach in the whole C++ programming syllabus !

Dynamic typing

Objective-C is dynamically typed. Dynamic typing means that if you have a reference to instance of an object, the type of object will be looked up in the run-time while in C++, you specify the type of object in the code and then start working with it. This implies faster development with Objective-C, the resulting application will be highly extensible after development and allows using dynamic loading easily. It also makes the coding easier to learn since you no longer need to specify the type of object and then start working with it. In contrast the problem with dynamic typing is that this will shift the errors to run-time while you can simply realize the method call errors in compile-time with C++.

Garbage collection and Memory management

C++ introduces two new operators compared to C to allocate and free the objects. the new and delete operators. You should manage the memory yourself and keep track of the objects you create to clean them up.

In Objective-C, the base class NSObject introduces the alloc and release messages to create and destroy items and is not considered a completely managed language (e.g Java and .NET are managed environments) but it introduces a common programming practice to avoid memory leaks. The first cool point is that you can count the object references using the retainCount message and increase or decrease it using retain or release. In addition it introduces the autorelase pools which you can create the object and add it to the autorelease pool so that it will automatically clean up your object at the end of event loop.

Mix them together

C++ adds lots of new features to the C language: classes, virtual methods, non-virtual methods, constness, templates, friend classes, multiple inheritance, pure virtual functions, operator overloading, function overloading, private, public and protected members, constructors etc. Objective-C on the other hand add very little, it is just classes, methods, categories and protocols.

Objective-C is could be considered as just a pre-processor to the C language plus a run-time library. So you may want to use C++ features beside Objective-C. This is nowadays possible using a compiler mode named Objective-C++. Yeah, this time Objective-C is extending C++ :). In development environments such XCode, this would be possible by renaming objective-c implementation file from .m to .mm.

See Also :

The GNUStep Project

GNUStep Objective-C is Fun – (Tutorial for beginners)

Objective-C – Wikipedia Entry

C++ vs Objective-C Quick Comparison

Memory Management in Objective-C

Load Code: Why Objective-C is cool

In fact the worst thing with upgrading your operating system is that there are always some features that you miss in the new one or it is broken by mistake ! I was using Ubuntu version 8.10 and when I upgraded to version 9.04, realized that intel driver that is included in this release is in beta stages and the performance was really poor. Then I downgrade to 8.10 and again with the release of 9.10 (karmic) my vpn and openvpn configuration using Network Manager did not work.

I decided to stick with Shell again, and connect using my OpenVPN configurations by a simple openvpn command.

It is as simple as running a single command, you should first switch the directory to where your config files exist and type :

sudo openvpn --config myclient.conf

Two weeks ago I had upgraded my Windows XP SP3 to Windows 7 and guess what, The openvpn-gui package wasn’t working either.

Taking a look at openvpn log, I found that it has routing problems with the following error and can’t set the routes, so the windows network applet says “No internet access” for that.

ROUTE: route addition failed using CreateIpForwardEntry: One or more arguments are not correct.

It seems that some forwarding structure and API has been changed since Vista and openvpn version 2.0.9 is not aware of them. After googling around, I found that the latest official OpenVPN release had fixed these issues. And it is interesting that they’ve included the GUI for windows in the official release. You can download version 2.1.1 from :

and take care, you should put it into “Windows Vista” compatibility mode and run it as administrator.

After installation, you should copy your config files into C:\Program Files\OpenVPN\config\ and run OpenVPN GUI from start menu. If you got into routing problems again, try running the OpenVPN GUI as administrator too.