Saturday, December 27, 2008

Event driven programming

Most programmers think “Threads” when they are told to make a piece of code that should run concurrently. Also it hits them right in the face the last time they tried to make a threaded programs when they were faced by the usual problems (Races, deadlocks, etc) which are hard to detect, debug and at some time to reproduce. The behavior of threads is too unexpected as it's fully controlled by the threads scheduler not by the programmer. Another issue, the overhead of creating threads which sometimes is painful which produces an important question “What is the alternative ?”
Lets think of concurrency in the following way: we will receive all the requests at the same time and queue them. Then we will assign each of them to a specific function. When this function blocks (i.e. for IO requests) or finishes we will make another one start till it blocks or finishes and so on. The question you'll have in mind “Wait a minute, that's not concurrency!!”
Well, think of it this way. You have no stack management overhead, you have no scheduling overhead, you know exactly where the program is going to stop so bye bye races and deadlocks and the users gets to feel they are being served at the same time (Remember that you make all functions make the blocking calls at the same time). Is it that simple??
Lets see an example:
Threaded program will do something like the following,

   on a new event
   create a new thread that does

A simple ruby server that listens on port 9000 on the localhost will create a new thread every time it receives any message on the socket like the following,
 socket =“localhost”,9000)
loop do do |connection|
#do something with the connection
But an evented program will do something like this,

   on a new event
   if free
      assign a handler for the event
      launch the handler
      queue the event until free

It will kind of hard to demonstrate how exactly the events are handled as they are handled inside the evented library but it will look like the following using EventMachine (a ruby library). First we define a handler class (it could be named anything) with a recv_data method that eventmachine searches for in the module. Then we start the events loop. The code will look something like the following,
require 'eventmachine'
class EventHandler < EventMachine::Connection
def receive_data data
# do something
EventMachine::run {
   EventMachine::start_server("localhost", 9000, EventHandler)
Actually it's kind of hard to imagine at first and with large programs (where it perfectly fits) it's hard to debug so I wouldn't recommend it for any newbie to use. But for implementing, let's say a server, event driven programming has proved its efficiency compared to threaded programming.
Note: A lot of debate has been made in this area so you should read more to get to know the opinions of both sides and I recommend that you Google the topic if you are interested.
Waiting for your comments!!

Monday, November 24, 2008

Anohter concert, another great night

Most of my close friends know that I love attending the concerts of the BA Orchestra specially the ones conducted by Sherif Mohie Eldin. Last Monday (17th of November) there was a concert with a Spanish pianist as a guest to perform a soloist. I couldn’t miss a piano soloist for the world. As always the concert was held in the small theater with a huge number of very old people and it always amazes me the number of foreigners attending classical concerts as you can always spot at least 5 to 10 foreigners attending. It was the first time for me to attend with my camera as I had the intention of sharing this concert with you.
When I picked up the program of the concert, I was pleased to find that they were play my favorite Chopin Concerto “Concerto for piano and Orchestra No. 1, in E minor, op. 11”. I don’t know exactly what all the parts of the name mean but I know the concerto and I love it. It was so different hearing it live from hearing it as an mp3 and Jose, the pianist ,was amazing. Playing from the memory, with all the passion sparking from his face I could help feel amazed by the seen.
After the concerto was over Jose played us a solo. It was a shot amazing piece of quite and peaceful music. The orchestra took a break then when they returned they played two pieces by two composers that I don’t really know but I think if heard about one of them before. The two composers were S. Barber with “Adagio for strings” and B. Britten with “Simple Symphony”. The second piece had a part named playful pizzicato; all the players left there bows and the piece was played using there fingers without bows. It was not the first time to hear that piece but it’s always amazing.
At the end I was sad it was over but there will be a next time I hope.
Notes: This is not technical but it's kind of refreshing, all the pictures are taken by me so you can copy them, use them or do whatever you want with them and at the end don't forget to comment.

Monday, November 17, 2008

Intel Core i7 processors (Nehalem)

Core i7, that’s the name of the new family of processors (code name Nehalem) Intel is releasing this month. I couldn’t read about something as major as this and not blog about it although I am having my midterms now. Anyway the new family has some big changes in the architecture something Intel calls QuickPath which is a new way of handling shared memory and inter-processors communication. The keyword is NO MORE FRONT SIDE BUS. FSB was used as parallel way for accessing both the memory and the IO devices. The new architecture separates the IO and the memory connections, putting the memory in direct point to point connection and that means that the memory manager moved from the chipset into the processor. The IO is handled through the chipset on the motherboard. That means with those new processors come new motherboards, chipsets and everything.
One of the restrictions that comes with the new package is that although they support to have more DIMMs but the support only DDR3 (bye bye DDR2). I think that’s a change that will affect everyone interested in PCs. Hope to get my hand on one of those soon (In two years or so :D). So here are the capabilities of each member of the family
Core i7
Memory controller
256 KB L2/core
8 MB shared L3
3xDDR3 800/1066 MHz
1x 4.8 GT/s
965 Extreme Edition
3xDDR3 1333/1600 MHz
1x 6.4 GT/s
I got this table from Wikipedia so for further information about the new family and the new architecture you can visit:
Don’t forget to comment.

Wednesday, November 12, 2008

Sun Campus Ambassador - Alexandira University

It is finally official. Say Hello! to the new Sun Campus Ambassador(CA.). It has been 4 months now since I first heard of the position. It was the first day of Wikimania; I talked with the people at the Sun Microsystems booth. It turned out the one of them was the regional manager of Education and Research. He was the one that told me all about the CA position. It was really a long journey, CV sent, first phone interview, second phone interview and a lot of e-mails coming and going ever since. I hope that I’ll be able to do my job as it should be done- Of course I'll need your help to do that. I welcome feedback and at any time.
I am really happy with the activities going all over our department and I hope that it could be of great help to everyone and that I would be a good part of what's going on.
For any feedbacks or questions concerning the CA position or activities you are welcomed to comment here or send me an e-mail.

Sunday, October 12, 2008

Evri, a new way to view the internet

A few months ago I was searching for already developed semantic web application. I faced a limited access, beta version application named Evri so I registered in it. After a while I received an e-mail from Evri telling me that the service is no longer limited. I visited the site and I was instantly amazed but what it does. Evri helps you find connections between people, places and all kinds of stuff you might be reading about on the internet. It’s not a search engine so you don’t find a lot of information about the keywords you search for but it tells you what you are searching for is related to, giving you a way to find more information that might be useful to whatever you are doing. It provides a brief Wikipedia description of the keyword and the coolest Evri feature “the connections graph”. It is a simple flash graph that shows other objects on Evri that are connected to the object you are searching now. The rest of the UI is simple with a lot of information, pictures and even YouTube videos. The best way to know how cool it is is to go now and try it either by visiting Evri or using the small icon at the end of any of my blog posts.
On the technical side Evri uses a mix of natural language, learning and semantic algorithms to build its network of information connection. It’s build of the idea of giving machines the power to understand data and the relations between them not only process them as strings. That is very useful as it saves us the time we spend trying to match information and for sure it will enhances search results and enable the machine to do much more than it does now.
I am not sure if it’s going to be of daily use to anyone of us any soon, but I know that with their slogan "search less, understand more" it represents a future of easier to use internet, a semantic future.
Please comment with what you think of evri and the article.

Wednesday, October 8, 2008

A talk with Samer El Sahn The CEO of eSpace Technologies

“It's all about the team”, “The business plan comes first”, “We need more start ups”. Those are some of the sentences that was repeated during my talk with Samer El Sahn – CEO of eSpace technologies.
The business side of the developing world has always been one of my main interests so I could not waste the chance of having a conversation with the CEO of the company were I am training now. I am not a professional interviewer but I tried my best.

I decided to start by asking questions that I had when I read the IBM CEO global study for the year 2008. The study was titled “The enterprise of the future”. My first question was about the flexibility of a company and the ability to adapt market change. His answer focused on having a specific business plan that has everything obvious and clear especially how the project is going to make money. If the business plan was clear enough the manager shouldn't get carried away by all the possibilities that will appear along the way unless the targets of the project proved not to be worthy of the effort or the money. “Plans are made to be changed”, he said “As long as the change is done without losing the main focus of the project”.
My next question was about a belief I had which was that the career of any developer should end up with an office profession away from the developing and coding. I thought the seniors focus on the management and planning for a certain project or the company in general. But his answer showed that it was a wrong belief. The path of the your career is your choice.”At some point you will have to choose weather to take the managing path or the technical path”, he said. Mohamed Ali which was the CEO of eSpace chose to step down and preferred to be the CTO, and he still contributes to the codes of the products of eSpace.
Two days before I read about a technique of execution of processes. The new technique was mentioned in the last issue of the Harvard business review magazine. The technique is named execution-as-learning which was devised as replacement for execution-as-efficiency technique. So I asked about how eSpace evolved and learned. He told me that eSpace was based on learning from mistakes. He explained by saying that they found the process they are working to now now by trying different techniques and learning from the mistakes they have made. “It was all trial and error”, that's how he described it “But all of that could have been avoided if there was a system for sharing experience with investors and bigger companies”.
The following question was about how to guarantee the quality of the code that the developers produce. The answer was a little well known “code reviewing” but what is more important is what that question led to.“Developers are obsessed with their code that they forget about the user”, he said. Which brought us to an important point which is focusing on the users' need is much more important than focusing on the code as the user doesn't care about how the implementation is done; all that he cares about is the experience which he has when using the application. It's the user experience that matters. Leaving space for implementation improvement is important too, but delivering good user experience fast and often is much more important.
When asked about the Egyptian market he said that he saw it was not good. “The developing level here in Egypt is below expectations and can do much better”. I was shocked to hear that. When I prepared the question the night before I had other question depending on him saying it was good. I asked how can we improve the market here he answered without hesitation “We need more start ups”. He told me that our students now don't have the mentality of making a start up although our chances now are better as the number of investors ready to invest in start ups are more than ever. So I asked about what will he do to change that so he told me that he had planned to make sessions meant to change the mentality of the students. “It's a challenge but it pays off”, he said “You don't have to give up your right for a salary. The investors will fund your whole project. But you need to keep in mind that they are investing in you not the idea you are coming with. They are not investing in you alone, but they are investing the team. It's all about the team not the idea.”. A team that can get things done, that's what investors are looking for.
I asked him if he thought of a global future for eSpace and he said that they want to keep the structure of eSpace light and flexible, they don't want it to be a big heavy company and lose the agility they have now, and that's why they spread by making spin offs which was a new word for me. He explained by saying that they create other companies with independent management systems with eSpace having shares in it and that's how eSpace grows.
It was educating, surprising and fun. I hope you found it that too.

Thursday, July 31, 2008

MSDN Virtual Labs

I always try to find new ways to learn stuff. I don’t like what’s ordinary so as any rookie I used only introductory books to learn about new technologies and thought that I had it all then I saw tutorials. Actually for quite some time my culture about learning new stuff was “tutorialic”- when I found new technologies I got a tutorial that talked about it and that was it. Later on I got to find that that alone isn’t enough (Now all I do is reading as any of you). Along the way I started using some "on the fly" ways like Eclipse help which leads you through each step showing what was done right and what wasn’t, it was really great when I was learning about RCP. It helped me both get things done and learn fast at the same time. Two days ago I found a new Microsoft tool that I really liked; it’s really innovative and time and software resources saving. What I am talking about is –as you already know- is MSDN Virtual Labs. MSDN virtual labs is a new tool that helps a developer build applications with Microsoft’s latest technologies without having to install any application on your machine. When I used it what I really liked about it that it helped me learn about new technologies in a very interactive and interesting way. I tried it the first time just to try a new thing but I found it could be put in real use.
When you open the web site you’ll get to choose what technology or product you want to use and then choose what scenario you want to experience. After a long and boring registration phase you’ll get to use it (there is an express version if you want to try it without registration. You can find the link on the top left side of the main page). When you are done with that phase the web site will ask you to install a certain ActiveX add on. Then you’ll get to start using you session of the virtual lab. Every session is about 90 minutes (those are the ones I’ve seen I don’t know if there are any longer or shorter sessions). Through each session you will be provided with a certain exercise to do. I found that downloading the lab’s manual and reading the steps from it is better than reading the exercise from the lab’s window.
I found the experience of using that lab so amusing and educating- that’s the way I think learning should be “fun”. That lab also has some downsides which are the long and boring registration phase. Also if you don’t have a fast DSL connection, don’t even think about using it. One last thing is that you can’t get the result of your work on the exercise on your machine but if you only want to learn about a technology or a product that won’t matter to you.
If you like -or don't like- this article please leave your comment.
Bookmark and Share

Friday, July 25, 2008


Have you ever dreamed of having a project that produced a chip that did something real, something that you can make then use in the real world, instead of the digital projects that come from wonderland were people use some switches to play a game! Well, I had that dream. I love to program chips to make stuff like telling me when someone turns the light on in some room and to react to it according to some program I've already put in it. Though our beloved FPGA can do a lot of really great stuff but it's programming is frustrating. VHDL is one great-extremely-low-level language and it can teach us a lot about digital design but again if I want something to use something in a robotics project would I choose VHDL over Java?! I guess not. Sun has done it people. A programmable device that could be programmed directly using J2ME technologies. With high processing power and a lot of cool features that could be put in real use easily, I think it's everything that a programmable board should be. I was told about Sun SPOT(Sun Small Programmable Object Technology) by Juan Ramon Sun's Education & Research Manager during Wikimania. He told me -as you can find on SPOT's home page- that SPOT is not available in Egypt yet and it's really expensive but it's also kind of new so I'll keep dreaming about having SPOT somewhere in our labs maybe not for digital courses but for embedded courses. I'll list some of its features and you can also check it on Wikipedia.
Sun SPOT Processor Board:
180 MHz 32 bit ARM920T core - 512K RAM/4M Flash
2.4 GHz IEEE 802.15.4 radio with integrated antenna
USB interface
3.7V rechargeable 720 mAh lithium-ion battery
32 uA deep sleep mode
General Purpose Sensor Board:
2G/6G 3-axis accelerometer
Temperature sensor
Light sensor
8 tri-color LEDs
6 analog inputs
2 momentary switches
5 general purpose I/O pins and 4 high current output pins
Squawk Virtual Machine
Fully capable J2ME CLDC 1.1 Java VM with OS functionality
VM executes directly out of flash memory
Device drivers written in Java
Automatic battery management

I copied those features from SPOTs home page where you can find a lot more about it.
If you know about anything else like it please leave a comment about it and if you like this post -or not- please leave a comment.

Bookmark and Share

Sunday, July 20, 2008

Wikimania 2008

Four months ago I was told by a friend of mine "Abdel Rahman Gamal" that there will be a Wikimania here in Alexandria, Egypt and it will be hosted by the BA (Bibliotheca Alexandrina). He was thinking about joining the volunteers who are going to organize the event. I thought about that event for a while then forgot all about it due to all the things I had to do. About two months ago I found Abdel Rahman leading a group of volunteers and promoting for the big Wikimania conference. They had 2 awareness sessions to tell people about Wikipedia, Wikimedia and Wikimania. I loved the idea and I registered for the event I thought that it wouldn't hurt to attend some talks which I thought at the time would be all about the big online encyclopedia.
The conference ended yesterday and it was really great. I loved every single thing about it. The sessions, the people and the organization. I got to know a lot about the site I took for granted. I got to know a lot of great people and have really fruitful conversations.
I got to talk to some people I never dreamed of talking to and got to take a lot of new ideas home with me. I found out who the people behind the Arabic Wikipedia were and how the big Wikimedia foundation worked. I also got to talk to some academic people who came to show some of there results and research about wikipedia related stuff.
The research that I really like -mostly because it's all about my major- is the Semantic MediaWiki (SMW) which is done by two german researchers Markus Krötzsch and Denny Vrandecic which I got the chance to talk to both of them. Their sessions were mainly to tell people about SMW which I already knew about so I got to talk to them after the sessions about the technical parts and I found out that they didn't use an Ontology for that project and I got a general idea about the DB implementation they used. That conversation really made my day.
Today when I look back at the past three days I feel excited about the future and proud of the my friends who made that great Wikimania possible.
I choose that subject to be my first post because I think it's the biggest event I'll have this summer I hope you like it and if you do -or don't- please leave your comment.

Bookmark and Share