الجمعة، 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

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

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

"مقموص"

مندهش

متأمل

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

ديناصور سعيد

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