Monday, December 25, 2006

How to never lose ?

What's a loser ? And what's a winner ?
Traditional answer :
A loser is a person who lost something; a game, a compitition, someone etc. A winner is the one who won what a loser lost.
A loser looks down to himself in most cases, feels angry and thinks he must win in another time to have a value.
No one wants to be a loser.
But, look at it from another angle.
You lost, so you learned there is something you did that was wrong, then you learned a new thing, then you've won something that the other winner didn't win. Strange viewpoint, and I am almost sure it didn't convince you.
Ok, let's change the viewpoint even more. If you lost something, then you have less ways of losing it again! :D. Clarifying that, let's say that there is n ways you could lose a runnig race, you don't know all of them yet, so you aren't prepared for each one. So one of these ways have made you lose. The next time you know that way, so you are prepared for it, so you now have n-1 ways of losing ;). One after another, you'll eventually have zero ways of losing.
The inventor of the electrical light bulb, Thomas Addison, who performedthousands of experiments until achieving the desired result. "Who here has made that many attempts to succeed in something? Do we try more than two or three times before we give up?", "there is no such thing as 'I can't do it', there is 'I can't do it yet, and I have to keep trying'".

So personally I see each failure as a step towards success. Perhaps programming have tought me so, fixing an error after anothet till the compiler is shy from saying another error cuz keda 7aykoon beystahbel :D.
A real loser is the one who don't learn from his failures. And a real winner is the one who keeps learning till he reaches. A real loser is the person who stops trying. And a real winner is the person who never stops.
One last word, A real winner of winners, is the person who is not satisfied with the desired result after he achieves it and keeps trying to improve it further and further till he makes the best result in the history and possibly for several centuries to come. That is a real scientist mind.

So, people who read this post, if you have failed in something, don't get stuck at that and keep crying about it forever, get over it and just try another way. It is the same concept as lighting a little candle is better than damning the darkness thousand times. Don't be just optimistic, believe in your capability to do it and foresee the expected ways of failure to decrease the times you have to try.

A side note, there is a group (osra) in our college, that had failed many times, but personally, I never gave up on it; believing that as we keep trying we sure will reach isA. Even if we just reached experience of how to avoid such failures again, that would be enough. But what did I say above ? If you actually reached that, there is nothing called 'enough'.

keep in mind
ان الله لا يضيع أجر من أحسن عملا
و لا تنسوا التوكل على الله
و لا تنسوا حمد لله علي كل حاجه عشان اللي بيحيبوا ربنا هوا اللي فيه الخير بعد ما تكون طبعا عملت اللي عليك

Friday, December 22, 2006

Java :(

In our Java project, I had some frustrating errors that I can't figure out till now.
The project is video streaming and I am using JMF.

I tried to send frame by frame at first. The client only displayed the first frame and stopped althought the server is showing the video correctly. I discovered after five days of tracing and testing the BufferedImage and ObjectStream and BufferToImage, that the problem was solved when I reallocated the byte array every time instead of reusing it!

Another one, using the RTPManager of JMF, both the server and the client was on the same machine, the program never worked when using 127.0.0.1, I had to use the actual IP of my machine (I wonder what if I was disconnect and don't have an IP ?)

Today I had a strange error too, I still didn't trace it. I initialize ActionEvent(this,0,"GotPlayer"), I get an exception telling me the the source (this) is null. I tried to ActionEvent(new Object(),0,"GotPlayer"), I got the same error too!

Please somebody have an answer tell me, I really got tired of that.

Ah, by the way, sometime we got an error in our MFC project, a line that assigns a function to a function pointer, we traced it, the funtion pointer is still = null after the assignment although the watch of the function itself (the right hand side of the assignment) was not null.

Either, the evil forces of darkness has conspired upon us, or this is really some programming myths that should be reserved for history cuz maybe after 1000 years the sercret will be unvield!

Sunday, October 22, 2006

C++ in the kernel

Welcome again, it have been a long time since i wrote here, cuz my pc was damaged and etc... a long story.
Anyway, I wanna write a little about my adventure for enabling C++ in the kernel. C++ isn't like C, it needs some runtime support, for calling constructors and destructors of static and global objects, also for exceptions, RTTI, thus dynamic_cast (which is btw is like the 'as' operator in C#) , and new and delete. Just compiling C++ without giving support you will end up only having namespaces, classes and templates and other features I don't remember now.

You have 2 options either ignore those features, or integrate a standard C++ library in your kernel. Sure you won't create your own. You can use newlib, or libgcc along with libsupc++. You still have to support several functions for them, like malloc and free and abort etc. This won't call constructors for you. I found a trick but I don't know yet if it will work. To make GCC generate the _init function that does that, which is supposed to get called b4 main, and call it myself. I will try it after recompiling those libs to allow them to have weak pthread symbols so I don't have to implement pthreads now.