Lesson 1 / الدرس 1

What a program is / ما هو البرنامج

Before any syntax: a program is a list of instructions, followed exactly, in order, by something that understands nothing. Most beginner difficulty comes from forgetting the last part.

قبل أي صيغة: البرنامج قائمة تعليمات تُتَّبع بالضبط بالترتيب من شيء لا يفهم شيئًا. ومعظم صعوبة المبتدئ تأتي من نسيان الجزء الأخير.

You already write programs. A recipe is one, and so are directions to your house. Both are a sequence of steps that produce a result if followed in order. The only thing that makes programming harder than writing directions is that the follower is a machine, and a machine will not fill in anything you left out.

Directions for a person:
  1. Go to the second street and turn right.

The same, for a machine:
  1. Walk forward.
  2. Count every street you cross.
  3. If the count is 2, stop.
  4. Otherwise, go back to step 1.
  5. Turn 90 degrees clockwise.
The second version is longer and it is not more complicated — it is the first version with the assumptions written down. That is the entire skill this course teaches, and lesson 21 is where you will need it most. Run the demonstration.

Three things every program does

It canWhich meansLessons
RememberPut a value somewhere and get it back3 to 8
DecideDo one thing or another, based on a test9 to 11
RepeatDo something many times without writing it many times12 to 14

That is the whole of programming, at this level. Everything else — functions, arrays, objects, the entire JavaScript language — is a way of organising those three so that a large program stays understandable.

Why this course uses JavaScript

The logic in this course is the same in every language — Python, PHP, Java and JavaScript all have variables, conditions and loops, and they differ mostly in punctuation. JavaScript is used here for one practical reason: it is already in the browser you have open, so there is nothing to install, and the next course builds directly on it.

One habit is worth starting today. Before writing any code, write the steps in ordinary language — Arabic or English, whichever you think in — one line per step, as if instructing a very literal person. Most programs that will not work were never clear as a list of steps either, and finding that out on paper costs a minute instead of an hour.

Try it live / جرّب بنفسك

Preview / المعاينة

Check yourself / اختبر نفسك

1. What are the three things every program can do?

2. A program does something strange. What is almost always true?

3. Why does this course use JavaScript rather than another language?

Your task / مهمتك

Pick something you do without thinking — making tea, getting to work, logging in to a site — and write it twice on a page: once as you would tell a person, and once as you would have to tell a machine, with every assumption spelled out and every decision made explicit. Then mark the places where the second version had to make a decision the first one hid.

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

  • Both versions of the same everyday task صيغتان للمهمة اليومية نفسها
  • The machine version numbered, one action per line صيغة الآلة مرقّمة، فعل واحد لكل سطر
  • At least three hidden assumptions made explicit ثلاثة افتراضات خفية على الأقل صريحة
  • At least one decision, and one repetition قرار واحد على الأقل وتكرار واحد
How do you want to submit? / كيف تريد التسليم؟