Lesson 5 / الدرس 5
Your first week in code somebody else wrote / أسبوعك الأول في كود كتبه غيرك
Nobody reads a codebase. You arrive, you are given something small, and you follow one thread through it — and the map you build that way is more useful than any tour, because it is built out of things you actually needed.
لا أحد يقرأ مستودعًا. بل تصل، ويُعطى لك شيء صغير، فتتبع خيطًا واحدًا خلاله — والخريطة التي تبنيها هكذا أنفع من أي جولة، لأنها مبنية من أشياء احتجتها فعلًا.
The instinct on day one is to read everything and understand the architecture before touching anything. It does not work, and the reason is that a codebase is not written to be read in order — it is a hundred decisions taken at different times, and without a reason to care about any particular one, none of them stick.
Follow one request all the way through
-
Get it running locally first. Before anything else, and however long it takes. Every hour spent here is repaid daily, and the notes you make while doing it are the onboarding document the next person will not have either. شغّله محليًا أولًا. قبل كل شيء، ومهما استغرق. فكل ساعة تُنفق هنا تُردّ يوميًا، والملاحظات التي تدوّنها وأنت تفعل هي وثيقة الانضمام التي لن يجدها التالي أيضًا.
-
Pick one page and find the route that serves it. Then the thing the route calls, then where the data comes from, then the template. One thread, end to end. You now know the shape of every other page. واختر صفحة واحدة وجد المسار الذي يخدمها. ثم ما يستدعيه المسار، ثم من أين تأتي البيانات، ثم القالب. خيط واحد من طرف إلى طرف. فتعرف الآن شكل كل صفحة أخرى.
-
Change something small and watch it break. Deliberately. Knowing what fails when you edit a thing tells you what depends on it faster than reading ever will. وغيّر شيئًا صغيرًا وشاهده ينكسر. عن قصد. فمعرفة ما يخفق حين تحرّر شيئًا تخبرك بما يعتمد عليه أسرع من القراءة أبدًا.
-
Read the tests for the thing you are about to touch. They are the only documentation that fails when it goes out of date, which is why they are worth more than a wiki page written two years ago. واقرأ اختبارات ما توشك مسّه. فهي التوثيق الوحيد الذي يخفق حين يتقادم، ولهذا تساوي أكثر من صفحة ويكي كُتبت قبل سنتين.
Reading git as archaeology
# Who last touched this line, and in which commit?
git blame src/Bookings.php
# Then read that commit in full. The message usually says why, and why
# is the thing the code cannot tell you.
git show a1b2c3d
# Everything that ever touched this file, newest first
git log --oneline -- src/Bookings.php
# When was this odd-looking condition added, and what came with it?
git log -S 'is_legacy_rate' --oneline
# blame is not blame. It is the fastest route to the person or the
# commit that can explain a line, and the answer is almost always
# "there was a reason" rather than "somebody was careless".
git blame مستقبلي عليه يشير إليه — مدمّرًا بعينه التاريخَ الذي كان ليفسّر الكود. اكتب القائمة، واحتفظ بها، وعُد إليها في الأسبوع السادس. فنصفها سيكون قد أجاب نفسه.Check yourself / اختبر نفسك
1. Why does reading a codebase from top to bottom not work?
Following one request end to end gives you the shape of every other page, built out of things you actually needed.
2. What is git blame most useful for?
Code that looks wrong is usually code that was right about something you do not know yet. Reading the commit before objecting saves both of you a conversation.
3. Why not reformat a messy file in your first month?
Keep the list instead and revisit it at week six. Half of it will have answered itself by then.
Score / النتيجة: 0 / 3