0Pricing
Mojo Academy · درس

عادات Mojo الاصطلاحية

اكتب تعليمات برمجية سريعة افتراضيًا

عادات Mojo الاصطلاحية درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Fast by Default

The best speed comes from habits, not last-minute tricks. Idiomatic Mojo is written so it is fast from the very first draft. 🚀

Prefer fn in Hot Paths

Reach for fn in code that runs often. Its required types let the compiler optimize the parts of your program that matter most.

fn dot(a: Int, b: Int) -> Int:
    return a * b

Annotate Your Types

Spell out types on values and arguments. Each annotation removes a runtime guess and helps Mojo emit faster machine code.

var total: Int = 0
var ratio: Float64 = 0.5

Declare with var

Use var for clear, explicit variables inside fn code. Predictable scope helps both the compiler and the next reader.

fn run():
    var n = 10
    print(n)

Lean on Value Semantics

Mojo's value semantics avoid surprise sharing. Let values own their data so your code stays correct without defensive copying.

Borrow When Reading

Pass big values as borrowed when you only read them. You avoid a copy while keeping the original safe and unchanged.

fn show(borrowed data: Int):
    print(data)

Vectorize Number Crunching

For element-wise math, reach for SIMD so the CPU handles many values per instruction instead of one slow scalar at a time.

var v = SIMD[DType.float32, 4](1, 2, 3, 4)

Reuse Python Where It Fits

Keep mature libraries via interop, but cross the bridge rarely. Do heavy loops in Mojo and call Python for the parts it already nails.

from python import Python

Measure Before Tuning

Profile first so you optimize the real hot path. Guessing wastes effort on code that was never slowing you down.

Keep Loops Tight

Move setup and allocations outside the loop. A tight inner loop with no extra work is what the compiler optimizes best.

var buf = List[Int]()
for i in range(100):
    buf.append(i)

Readable Stays Fast

Idiomatic Mojo is clear and fast at once. You rarely sacrifice readability for speed, because good habits give you both.

Quick Check

Pick the habit that keeps Mojo fast by default.

Recap

Idiomatic Mojo uses typed fn in hot paths, borrows to read, vectorizes math, and profiles first. Good habits make code fast and clear. 🎯

الأسئلة الشائعة

هل درس «عادات Mojo الاصطلاحية» مجاني؟

نعم — نص درس «عادات Mojo الاصطلاحية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.

ماذا ستتعلم في «عادات Mojo الاصطلاحية»؟

اكتب تعليمات برمجية سريعة افتراضيًا تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟

لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «عادات Mojo الاصطلاحية»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟

نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. كتابة اختبار أداء منصف
  2. لماذا تسرّع fn والأنواع التنفيذ
  3. قراءة الأرقام بموضوعية
  4. عادات Mojo الاصطلاحية
← العودة إلى Mojo Academy