السبت، 22 يناير 2011

كن طموحاً

في صيف العام الدراسيّ 2009/2010 قدّمت محاضرات في التدريب الصيفيّ في كلية الحاسبات، وكانت عن لغة السي شارب والبرمجة بالأشياء (OOP) للفرقة الأولى. كانت تجربة: ماذا لو جربت، بأقصى ما لديّ من خبرة ومعرفة، أن اعلّم تلك الدفعة محتوىً يؤخذ في المعتاد في النصف الدراسي الثاني من الفرقة الثانية، أي أن اعلمهم ذلك المحتوى قبل عام ونصف من موعده التقليديّ؟

(حتى الآن لا أعرف بدقة نتيجة هذه التجربة، والسبب في ذلك أنه لم يوجد أمامي وسيلة لقياس النتيجة. كان عليّ أن أخطط لهذه النقطة بشكل أفضل، حتى ولو باستبيان)

هذا ليس موضوع مقالي على أية حال..

في العام الماضي قضيت وقتي في كتابة لغة برمجة للأطفال. بداية هذا الموضوع مقال قديم كتبته في 2008، ثم اكتشفت بعد ذلك أن الموضوع مرتبط الآن بمجال بحث علميّ هو التفكير الحوسبي (computational thinking). صار سؤالي الآن: هل يمكن التفكير في طريقة مبتكرة لتعليم أي شخص البرمجة، أياً كان سنه أو خلفيته؟

ثم في عطلة نصف العام القادمة أنوي إن شاء الله تقديم مجلس للعلم فيه شرح بعض الأوراق العلمية لطلبة الكلية مرة أخرى، على أمل إشعال شرارة البحث العلمي معهم. تقديم البحث العلمي في مرحلة مبكرة من الدراسة، بأسلوب مختلف عن الطريقة الجامعية المعروفة. ما نتيجة هذه التجربة الجديدة يا ترى؟

هناك شيء مشترك يربط بين النقاط الثلاثة السابقة: إنها محاولات لإنجاز أهداف يُرى في ظاهرها أنها صعبة أو غير ممكنة أو غير واقعية-- هكذا نكون قد وصلنا لموضوع مقالي هذا! هناك عدد كبير من الناس يرى أن الطريق للتقدم يكفي فيه أن نفعل الأشياء المعروف بأنها ممكنة، فقط نحتاج لأن نقوم بها بكفاءة أعلى أو ننشرها بين الناس. أرى أنا أن هذا لم يعد كافيا...إن الفرق العلمي/الاقتصادي بيننا وبين أمم أخرى قد صار كبيراً، والمشاكل الداخلية والخارجية تزداد عسراً، والطرق التقليدية لها حدودها.

إن أردنا التقدم فعلينا أن ننقل أكبر عدد ممكن من الأفكار من خانة "ما يُظنّ أنه مستحيل" إلى خانة "ما ثبت أنه ممكن". لو ظللنا فقط نمارس الأساليب المعروفة فأتوقع أننا في أحسن الظروف سنظل كما نحن، وفي أسوأها نزداد تخلّفاً. لو أردت نتائج غير تقليدية، عليك باستخدام طرق غير تقليدية.

لابد أن يأتي أشخاص طموحون يجربون كسر القواعد والخروج عن المألوف. الواقعية لا تعني الاستسلام للحالة الراهنة، والذين ينادون بهذا المعنى للواقعية ينسون أن الواقع يمكنه أن يتغير.

على أية حال فتجاربي هذه ليست أقصى شيءٍ في الطموح والجرأة. ليست فكرة "متمردة" جدا تعليم #C للفرقة الأولى أو ما شابه، لكنها خطوة: الوقوف على الحافة بين العمل العادي والعمل ذو التحديات. ربما لو اقتربنا من الحافة لقدرنا بعد ذلك على تجاوزها.

الأحد، 16 يناير 2011

الجمعة، 31 ديسمبر 2010

لغة برمجة عربية تعليمية: بعض الاعتراضات والرد عليها

الاعتراضات
  • الموضوع مجرد قواعد وتركيبات؛ لا يوجد فارق فكري بين 'if' و 'إذا' أو 'while' و 'طالما'.
  • لو صنعنا لغة برمجة عربية ستكون ركيكة وغير منسجمة.
  • نريد أن نعلم المبتدئين لغة يستطيعون أن يتوظفوا بها مثل ++C أو Java أو #C...الخ، وهذه كلها انجليزية.
  • كيف سيتابع المبرمج أحدث التطورات التكنولوجية أو يشارك في البحث العلمي بدون أن يعرف الإنجليزية؟
الردود

الموضوع مجرد قواعد وتركيبات؛ لا يوجد فارق فكري بين 'if' و 'إذا' أو 'while' و 'طالما'.

الكلمات لها معنى وليست مجرد صور رياضية. المبرمج الناطق بالانجليزية لديه فرصه ليربط بين كلمة function وفكرة الدالة الرياضية، بين كلمة class وبين فكرة التصنيفات أو الفصائل، بين كلمة structure وفكرة التركيب العام أو البنْية.

أما المبرمج الذي لا يعرف الانجليزية ستكون الكلمات بالنسبة له رموز صماء يعرفها كما هي. ما هي كلمة class؟ هي كلمة تكتبها في البرنامج عندما تريد كذا، وينطبق الأمر على سائر المصطلحات.

الشيء الآخر أنه حتى هذه الكلمات الصغيرة ستعوق الكثير من أفراد المجتمع عن المشاركة. ماذا عن الصغار الذين لا يكتبون بالانجليزية بعد ويحتاجون لحفظ هذه المصطلحات كشرط لتعلم البرمجة؟ لماذا نضع أمامهم عائقاً إضافياً؟

نحن نريد أن يشارك المجتمع كله في التقدم العلمي، بدءاً من الأستاذ الجامعي وانتهاءاً بطفل القرية، ولو جعلنا نسبة بسيطة من دارسي الانجليزية هم فقط الذين يشاركون فسيساعد هذا على أن يكون موقفنا العلميّ -احم- مثل ما نحن فيه الآن.

لو صنعنا لغة برمجة عربية فستكون ركيكة وغير منسجمة

أمتأكد من ذلك؟ انظر لهذا البرنامج في لغة كلمات (على سبيل المثال) من مثال افتراضي عن لعبة طائرات:

قل لي بصدق..ألا يُفهَم هذا البرنامج بمجرد قراءته، حتى لو لم تعرف اللغة أصلا؟ :)

نريد أن نعلم المبتدئين لغة يستطيعون أن يتوظفوا بها مثل ++C أو Java أو #C...الخ، وهذه كلها انجليزية.

وما نقترحه يسهل لهم طريق التوظيف، بأن نفكك لهم عملية التعلم من خطوة واحدة كبيرة (تعلم الانجليزية والبرمجة معا) إلى خطوتين كل منهما مستقلة عن الأخرى ويمكن للمبتديء أن يتعلم كل منهما في الوقت المناسب لإمكانياته.

ثم أنه لو تعلم الفرد البرمجة جيداً بلغته الأم وتشرب مبادئها فليس من العسير بعد ذلك أن يتعلم أن 'فصيلة' معناها 'class' أو أن 'تعبير' معناه 'expression'...الخ لو أراد الانتقال للغة مبنية على الإنجليزية.

وعلى المدى الطويل، لو انتشرت البرمجة في المجتمع فسنجد بإذن الله أجيالاً جديدة من لغات البرمجة العربية الاحترافية التي يمكن إنجاز الأعمال بها في المؤسسات.

كيف سيتابع المبرمج أحدث التطورات التكنولوجية أو يشارك في البحث العلمي بدون أن يعرف الإنجليزية؟

فلندعهم يتعلمون البرمجة أولا ثم ننظر للتطورات والبحث العلمي! نحن الآن أمام موقفين محتملين في المجتمع:

الموقف الأول:
  • نسبة قليلة من المجتمع تعرف الإنجليزية
  • نسبة من هؤلاء تهتم بالبرمجة
  • نسبة من تلك النسبة من نسبة تتابع الأبحاث العلمية
الموقف الثاني:
  • المجتمع كله يعرف العربية
  • نسبة منه تهتم بالبرمجة
  • نسبة من هؤلاء تتابع الأبحاث العلمية، وقد تجاوزوا عقبة كبيرة (البرمجة) وبقت عقبة عادية (الانجليزية)
قل لي الآن أي هذين الموقفين تفضل.

الخميس، 30 ديسمبر 2010

Computer Science and great products

Do you need a good knowledge of computer science to make a great product? It certainly depends on what you're trying to do, but an important point is that the more CS you know the more enabled you are to make useful and impressive software.

The rest of this blog post is a case study in how CS is being used to shape my homegrown programming language for children, كلمات.

First the obvious: It would not have been made without knowledge of compilers. We got that out of the way.

Another thing is that it runs on a small virtual machine called (appropriately) SmallVM. Basically it's a program that reads assembly-like instructions and executes them. Do you know the "basic computer assembler/emulator" sometimes given in computer architecture courses? It's like the big brother of that :)

SmallVM doesn't just run instructions though; it also knows about classes and objects and has a garbage collector. That means it required knowledge about language runtimes in general.

Notice that currently the language runs programs at an acceptable speed. If I want programs to run really fast I need to go deeper: Compiler optimizations, better garbage collection, and perhaps modern VM tricks like polymorphic inline caches.

Do you know that with these techniques a language like Java or C# can reach performance comparable to C++? I hope that I or someone after me learns from those techniques and further improves on Kalimat/SmallVM.

All of this has been about the current version of the language, what about future versions? Here are some ideas I'm thinking about and how computer science can help...

Future idea #1: Gradual typing.

Currently Kalimat is dynamically typed. This means that a variable can take values of any type in the language, and obviously there are no type declarations. This is an example of a program that uses dynamic typing:


Notice how (a) There are no type declarations for the parameters or return value and (b) The program accepts any array of objects as long as each object has a method called نتيجته.

Now I've been thinking: If a child learns my language and afterwards wants to "graduate" into something like C++ ...etc then type declarations and static typing would be new to him or her, but on the other hand if I change Kalimat to require type declarations then it will be harder to teach it to children since the program will require type declarations everywhere, and those will (a) Need explaining (b) Need more syntax memorization and (c) Distract from the actual programming ideas like loops...etc

So the solution? Gradual typing! It means that the language is dynamically typed as usual but with optional static typing. When you declare the type of a variable the compiler will enforce it; otherwise the variable is dynamically typed.

If I decide to implement this feature, I imagine a future version of Kalimat where children would learn programming without being confused by types, and then at some future learning stage they would be introduced to type declarations, watch how the language checks for type errors, and see autocomplete at work!

Future idea #2: GUI programming.

Kalimat currently supports simple graphics like lines and rectangles, but in a future version I hope it supports GUI elements like Forms, Buttons, Textboxes...etc

It would be possible to copy the current event handling models of e.g C#, but I want to take seriously the idea of "a children's programming language". GUI programming is sometimes confusing even for college students! If there's a model that can make it simpler then I should do what I can to seek and use that model.

Again, computer science comes to help! There is a model for parallel programming called CSP, or Communicating Sequential Processes. It started from work by Tony Hoare (the same guy who invented quicksort) and it lead to many implementations and languages. It is also related to the actor model used in languages like Erlang.

So, a couple of days ago I read a paper about how to use CSP to greatly simplify GUI programming. To understand how this works I need to explain a little about the CSP model. Also my explanation is not 100% correspondent to the content of the paper (the idea was further developed in future papers, the paper itself is not current. Also my explanation is simplified).

Imagine that a program is composed of several processes that run independently. To communicate with each other they use a special type of object called a channel. There are two operations associated with a channel:

1- x = receive(ch) ; Which waits until data is available on the channel then returns it in x.

2- send(x, ch); Which waits until some process is ready to receive from the channel and then sends the data in x.

There is also a special command, spawn(p1, p2,...) that launches several processes in parallel.

Now we can talk about GUIs. Suppose we have a graphics application that can be used to draw lines and triangles. If we can assign a channel to each event then we can do this:

Finally we will launch both processes in the main function:


To implement something like this in a traditional GUI library you would need a lot of code in several places. If you studied design patterns you could use the state pattern, for example, to organize your code. But with CSP you write GUI code the same way you think about it. To draw a line you receive two points and join them together. Simple as that.

Now imagine if all this was part of Kalimat.. it would be an Arabic children's programming language that has an easier GUI library than the default library of most modern professional languages!

We need a lot of computer science to implement such a feature. How will we run the processes? Do we use multi-threading and rely on the operating system to schedule the work; or do we modify SmallVM to make it run several processes concurrently and write our own scheduler? Does that mean we will need to revisit what we learned in the operating systems course? :D

Finally

What I want to say in this article is...I'm grateful for all what I've learned in FCIS, without which I wouldn't have been the programmer I am today, that's one thing.

The other thing, and this is important, is that it took me a lot of years learning computer science topics to know all of this. It doesn't have to be about programming languages: Any CS topic; be it operating systems, computer vision, AI, or anything else can open the doors to great products. Products you can use to make money, or improve society, or move science further. But it will take years of hard work and learning.

Why not start now?

الثلاثاء، 21 ديسمبر 2010

Can your C++ do this?





The command وكل إلى is used to invoke tail calls. In the current language implementation it means "remove the current function's activation record from the call stack before calling the new function".

I'm still deciding if I'm going to keep this feature in the final version of Kalimat or not :)

الاثنين، 6 ديسمبر 2010

ابتسامات الكترونية جديدة :)

الابتسامة
المعنى

"مقموص"

مندهش

متأمل

متأمل ولديه نمش

ديناصور سعيد

ديناصور سعيد ولديه شامة في وجهه

الأحد، 14 نوفمبر 2010

خطط وأهداف: جهاز أوراق

This is an article about a tablet computer model for the future: Awraq.

We all know the importance of paper. We also know the importance of computers.

Paper records our thoughts and designs and ideas and dreams. I forget a lot; so I surround my work environment with pens and copybooks everywhere. Designs, sketches, sample code in imagined programming languages, stories...

How about computers? They are a magnifying glass for our thoughts. They give us a way to make the conceptual become real. To make our designs seen and heard.

Sometimes a computer can be better paper than paper itself: in addition to recording your idea the computer can let you search it and categorize it and share it and email it. In other areas paper is clearly the better choice:
  • It's available everywhere; you can take it to bed or in a small bag or wherever.
  • It's more durable, with no hard disk crashes or data corruption.
  • You can easily combine sketching with writing; you can layout the information in anyway with ultimate freedom.
  • It's easier to use :)
Apple's iPad tries to solve some of those problems: it's much more portable and easier to use. It's name even is related to "a pad of paper". It is certainly a sign of progress. However, one crucial thing is missing: A pen.

The iPad uses an on-screen keyboard for text entry. This is good for casual writing or typing up an email message, but it makes the iPad mainly an information consumption device and not an information production device. I think it would be better for all of society if there was an easy way for anyone to write and sketch and think. Something that changes the way we make information the way the iPad changed how people consume it.

Also, I want this device to be intrinsically Arabic-based, to recognize Arabic handwriting (which lends itself more to being written with a pen), to have an Arabic GUI, and to be usable by Arabic children and mothers and families. To be the next stage of the development started by the old Sakhr home computers.

I imagine a future where أوراق is the school textbook and copybook and blackboard. I imagine a sketch-based programming language so you can sit and code anywhere (I'm currently designing such a language). I imagine simulations where students use multitouch to run science experiments and geometry constructions. Don't you want to live in that future?


How realistic is this idea? Surprisingly the hardware manufacturing isn't the hardest part of it; given enough funding and availability of good partners, it might be a solvable problem. The real problem that worries me however is software:
  • Arabic handwriting recognition
  • The touch-based and gesture-based user interface
  • An operating system that works well given the hardware and battery limitations
  • Good OS security to avoid the problems of viruses and spyware in current PCs
  • Sketch-based programming, sketch-based design, sketch-based everything :)
  • Data indexing and organization, a new electronic book experience, a natural language user interface, or many other future research points...
So in summary, we need many geniuses in many fields like compilers, pattern recognition, operating systems, graphics, embedded systems...

If only we had faculties that were created for such topics! Hmm....

And if only we can push the students of this faculty to reach much higher levels of knowledge...

If we would create new tools to make this job easier.

These are my goals, إن شاء الله.

الأربعاء، 10 نوفمبر 2010

خطط وأهداف: مركز التفكير الحوسبي

ما هي أهدافي؟

الموضوع هو أنه هناك دافعان يحركانني.

1) كثيرا ما أتتني أفكارٌ تكنولوجية مثيرة للإعجاب. أريد أن اصنع لنفسي ولغيري بيئة لتنفيذ هذه الأفكار والاستفادة منها ماديا وعلميا.
2) مللت الفجوة بيننا وبين الغرب، علميا واقتصاديا و...و...--هذه الفجوة سلاح دائما يوجّه ضدنا. كم مرة ستدفع الأمة ثمن تخلفها العلمي؟ كم مرة سيحتلونا وينهبوا ثرواتنا؟ ألم يأت وقت سد هذه الفجوة؟ ألم يأت وقت النهضة؟

هل تسمح الظروف الحالية بالتخطيط لهذين الهدفين؟ هل يمكن حاليا السعي لتنفيذ الهدف الأول، ناهيك عن الثاني؟

أجل إن شاء الله. أعتقد أن لديّ خططاً.

لا أريد أن أسمّيها احلاماً. كلمة "أحلام" توحي بأنها صعبة أو أننا مسموح لنا فقط أن نتخيلها. هذه ليست احلاماً: هذه خطط. خطط كبيرة، نعم، لكنها ليست بالخيالية.

تعال نتكلم عن الأطفال (كما افعل كثيرا!)...

الخطوة الأولى هي مركز لبحث تعليم البرمجة. نعم هناك مركزان في مصر حاليا لتعليم الأطفال البرمجة، لكنهما ليسا ما أريد: هذان المركزان يستخدمان التكنولوجيا الحالية للتعليم، بينما أريد أنا صنع تكنولوجيا مستقبلية كما يلي:

في ظاهره يكون المركز هو مركز تدريب عادي، لكن في داخله هو مركز أبحاث أبوابه مفتوحة لطلبة الماجستير والدكتوراه في مجالات علوم الحاسب والعلوم التربوية معا. هؤلاء الباحثون يجرون تجارب ذات منهج علمي ويطورون طرق جديدة لتأليف الكتب ولغات برمجة جديدة وبيئات لاكتشاف الcomputer science.

أفكر في لغات كثيرة نصية ورسومية. افكر في برنامج يرسم اوتوماتيكيا قصصا متحركة تعبّر عن تنفيذ الcode التي تكتبها. افكر في compiler شفاف يجعلك ترى مراحل الcompilation مرحلة وراء أخرى (بالمناسبة، حلمت ذات مرّة بحائط من زجاج عليه code، ثم تسير خلال هذا الحائط للحائط الذي وراؤه فترى الparse tree، ثم الحائط الذي وراء ذلك عليه الassembly code...وهكذا).

ماذا لو طوّر هؤلاء الباحثون طريقة عامة لتعليم الأطفال البرمجة؟ طريقة عامة معناها تعليم البرمجة لكل الناس-- مثلما يتعلمون الآن الجبر او حساب المثلثات-- ليس للأذكيار فقط ولا العباقرة، بل للجميع (وإن تفاوَت استيعابهم بالطبع). ماذا قد يحدث وقتها؟

حينها يمكن الكلام عن اضافة البرمجة كمنهج للتعليم الأساسي. ويمكن تدريب كادر جديد من المعلّمين-المبرمجين ليقوموا بالتدريس. يمكن تدريب هذه الكوادر في العالم العربي كله وليس مصر وحدها. يمكن أن يكون العالم الإسلامي من أوائل من يمحون "أميّة البرمجة" لا فقط "أميّة الكمبيوتر".

وإذا تعلّم الطلبة البرمجة في المدارس فقد يخرج منهم ...

- عالِم الحديث الذي يستخدم الgraph theory كأداة في دراسة هذا العلم.
- المهندس الذي يصمم سيارة تكاد تكون حاسوب اكثر منها مركبة-- وكلما حدّثت الsoftware صار لها امكانات اكثر.
- استيعاب لموضوع الefficiency كما يصفه علم الalgorithm analysis، ولغة يمكن الحديث بها عن كفاءة الأنشطة الصناعية والبشرية حيثما يمكن تطبيق هذا العلم.

وكيف نفكر في العالم من حولنا؟ إنّك لتنظر للأشياء من حولك فتجدها يمثلها tree أو graph أو list أو stack أو queue. ويجب أن يكون الكل عالما بأنه هناك ادوات جاهزة ومدروسة لتحليل هذه التركيبات والتعامل معها.

هل سيفعل هذا المركز شيئا غير اكتشاف طريقة عامة لتعليم البرمجة؟ من يعلم؟

نحن لا نعرف إلى أين سيأخذنا هذا الطريق. ربما يحتاج الأمر الى تطوير فكرة التعلم بشكل عام. ربما نفهم أشياءا جديدة عن البرمجة، أو التعليم، أو الأطفال، أو حتى --ربما-- طريقة عمل العقل البشري.

هذه هي أحد الخطوات الأولى في الخطة. وإنّي أتمنى أن أراها بإذن الله تحدث.

الأحد، 31 أكتوبر 2010

Two new open source projects: QPeg and LogoArabic

I've been coding for a while!

During and after the previous Eid, I created two new projects:

LogoArabic

The first is LogoArabic: An interpreter for an Arabized version of the well-known LOGO programming language, as a part of my project for teaching children programming. I was reading an old childhood book called "تعلم مع صخر لوغو", and wished there was a way to run the book's examples for new-generation kids. Now there's a way! (almost...my syntax is similar but not identical to the Sakhr Logo syntax. But the differences are small).

The code is available now on Google code: http://code.google.com/p/logoarabic/

QPeg

The second project is QPeg: a parser generator for PEG grammars...I'll explain:

You give it a grammar (a way to describe language syntax) and it will produce C++ or Java code, this produced code in turn will try to parse (or recognize) its input according to the grammar.

To learn more about PEG grammars you can visit here.

Again, the source for this project is on Google code: http://code.google.com/p/qpeg/

Want to participate?

Both projects are still in their starting phases, so there might be a chance for external contributors to join early before the projects get more complex!

Both are written in C++ and use the QT library (and are worked on with QT Creator instead of Visual C++). If people are interested I could post documentation and design documents on the project's web site. Perhaps I could also meet interested participants or have a "dissect-a-project" session (remember "dissect-a-project" from my post about the new ACM?).

If you don't want to participate, I hope you still enjoy the projects :)