Skip to content

Commit 724386a

Browse files
authored
Merge pull request #64 from Salah856/master
comments
2 parents 4aa00c2 + ee078ad commit 724386a

2 files changed

Lines changed: 114 additions & 110 deletions

File tree

1-js/03-code-quality/03-comments/article.md

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Comments
1+
# التعليقات
22

3-
As we know from the chapter <info:structure>, comments can be single-line: starting with `//` and multiline: `/* ... */`.
3+
كما نعلم من الفصل <info: structure> ، يمكن أن تكون التعليقات سطر واحد: بدءًا من `//` و multiline: `/ * ... * /`.
44

5-
We normally use them to describe how and why the code works.
5+
نستخدمها عادةً لوصف كيف ولماذا يعمل الرمز.
66

7-
At first sight, commenting might be obvious, but novices in programming often use them wrongly.
7+
للوهلة الأولى ، قد يكون التعليق واضحًا ، لكن المبتدئين في البرمجة غالبًا ما يستخدمونها بشكل خاطئ.
88

9-
## Bad comments
9+
## التعليقات السيئة
1010

11-
Novices tend to use comments to explain "what is going on in the code". Like this:
11+
يميل المبتدئون إلى استخدام التعليقات لشرح "ما يجري في الكود". مثله:
1212

1313
```js
1414
// This code will do this thing (...) and that thing (...)
@@ -18,13 +18,13 @@ complex;
1818
code;
1919
```
2020

21-
But in good code, the amount of such "explanatory" comments should be minimal. Seriously, the code should be easy to understand without them.
21+
ولكن في مدونة جيدة ، يجب أن تكون كمية هذه التعليقات "التفسيرية" ضئيلة. على محمل الجد ، يجب أن يكون الرمز سهل الفهم بدونها.
2222

23-
There's a great rule about that: "if the code is so unclear that it requires a comment, then maybe it should be rewritten instead".
23+
هناك قاعدة رائعة حول ذلك: "إذا كان الرمز غير واضح إلى حد أنه يتطلب تعليقًا ، فربما يجب إعادة كتابته بدلاً من ذلك".
2424

25-
### Recipe: factor out functions
25+
### الوصفة: قم بعمل إعادة اعتبار للدوال
2626

27-
Sometimes it's beneficial to replace a code piece with a function, like here:
27+
في بعض الأحيان يكون من المفيد استبدال قطعة التعليمات البرمجية بدالة ، كما يلي:
2828

2929
```js
3030
function showPrimes(n) {
@@ -43,7 +43,8 @@ function showPrimes(n) {
4343
}
4444
```
4545

46-
The better variant, with a factored out function `isPrime`:
46+
البديل الأفضل ، مع دالة محسوبة
47+
`isPrime`:
4748

4849

4950
```js
@@ -65,11 +66,11 @@ function isPrime(n) {
6566
}
6667
```
6768

68-
Now we can understand the code easily. The function itself becomes the comment. Such code is called *self-descriptive*.
69+
الآن يمكننا فهم الرمز بسهولة. تصبح الوظيفة نفسها التعليق. يسمى هذا الرمز * وصفي ذاتي *.
6970

70-
### Recipe: create functions
71+
### الوصفة: إنشاء وظائف
7172

72-
And if we have a long "code sheet" like this:
73+
وإذا كان لدينا "صفحة تعليمات برمجية" طويلة مثل هذا:
7374

7475
```js
7576
// here we add whiskey
@@ -90,7 +91,7 @@ for(let t = 0; t < 3; t++) {
9091
// ...
9192
```
9293

93-
Then it might be a better variant to refactor it into functions like:
94+
بعد ذلك ، قد يكون من الأفضل تغييرها إلى دوال مثل:
9495

9596
```js
9697
addWhiskey(glass);
@@ -111,21 +112,22 @@ function addJuice(container) {
111112
}
112113
```
113114

114-
Once again, functions themselves tell what's going on. There's nothing to comment. And also the code structure is better when split. It's clear what every function does, what it takes and what it returns.
115+
مرة أخرى ، تخبر الوظائف نفسها عما يحدث. لا يوجد أي تعليق. وكذلك بنية الكود أفضل عند التقسيم. من الواضح ما تقوم به كل وظيفة ، وما تحتاجه وما تعيده.
115116

116-
In reality, we can't totally avoid "explanatory" comments. There are complex algorithms. And there are smart "tweaks" for purposes of optimization. But generally we should try to keep the code simple and self-descriptive.
117+
في الواقع ، لا يمكننا تجنب التعليقات "التفسيرية" تمامًا. هناك خوارزميات معقدة. وهناك "تعديلات" ذكية لأغراض التحسين. ولكن بشكل عام يجب أن نحاول الحفاظ على الكود بسيطًا وصفيًا ذاتيًا.
117118

118-
## Good comments
119+
## تعليقات جيدة
119120

120-
So, explanatory comments are usually bad. Which comments are good?
121+
لذا ، التعليقات التوضيحية عادة ما تكون سيئة. ما هي التعليقات الجيدة؟
121122

122-
Describe the architecture
123-
: Provide a high-level overview of components, how they interact, what's the control flow in various situations... In short -- the bird's eye view of the code. There's a special language [UML](http://wikipedia.org/wiki/Unified_Modeling_Language) to build high-level architecture diagrams explaining the code. Definitely worth studying.
123+
وصف العمارة
124+
: تقديم نظرة عامة عالية المستوى على المكونات ، وكيفية تفاعلها ، وما هو تدفق التحكم في المواقف المختلفة ... باختصار - رؤية عين الطائر للرمز. هناك لغة خاصة [UML] (http://wikipedia.org/wiki/Unified_Modeling_Language) لإنشاء مخططات معمارية عالية المستوى تشرح الكود. بالتأكيد تستحق الدراسة.
124125

125-
Document function parameters and usage
126-
: There's a special syntax [JSDoc](http://en.wikipedia.org/wiki/JSDoc) to document a function: usage, parameters, returned value.
126+
معلمات وظيفة الوثيقة واستخدامها
127+
: هناك بنية خاصة [JSDoc] (http://en.wikipedia.org/wiki/JSDoc) لتوثيق دالة: الاستخدام ، المعلمات ، القيمة المرتجعة.
128+
129+
على سبيل المثال:
127130

128-
For instance:
129131
```js
130132
/**
131133
* Returns x raised to the n-th power.
@@ -139,42 +141,42 @@ function pow(x, n) {
139141
}
140142
```
141143

142-
Such comments allow us to understand the purpose of the function and use it the right way without looking in its code.
144+
تسمح لنا هذه التعليقات بفهم الغرض من الوظيفة واستخدامها بالطريقة الصحيحة دون النظر في التعليمات البرمجية الخاصة بها.
143145

144-
By the way, many editors like [WebStorm](https://www.jetbrains.com/webstorm/) can understand them as well and use them to provide autocomplete and some automatic code-checking.
146+
بالمناسبة ، يمكن للعديد من المحررين مثل [WebStorm] (https://www.jetbrains.com/webstorm/) فهمهم أيضًا واستخدامهم لتوفير الإكمال التلقائي وبعض التحقق التلقائي من التعليمات البرمجية.
145147

146-
Also, there are tools like [JSDoc 3](https://github.com/jsdoc3/jsdoc) that can generate HTML-documentation from the comments. You can read more information about JSDoc at <http://usejsdoc.org/>.
148+
أيضًا ، هناك أدوات مثل [JSDoc 3] (https://github.com/jsdoc3/jsdoc) يمكنها إنشاء وثائق HTML من التعليقات. يمكنك قراءة المزيد من المعلومات حول JSDoc على <http://usejsdoc.org/>.
147149

148-
Why is the task solved this way?
149-
: What's written is important. But what's *not* written may be even more important to understand what's going on. Why is the task solved exactly this way? The code gives no answer.
150+
لماذا تحل المهمة بهذه الطريقة؟
151+
: ما هو مكتوب مهم. لكن ما هو * غير * مكتوب قد يكون أكثر أهمية لفهم ما يحدث. لماذا يتم حل المهمة بهذه الطريقة بالضبط؟ الكود لا يعطي إجابة.
150152

151-
If there are many ways to solve the task, why this one? Especially when it's not the most obvious one.
153+
إذا كانت هناك طرق عديدة لحل المهمة ، فلماذا هذه المهمة؟ خاصة عندما لا يكون الأمر الأكثر وضوحًا.
152154

153-
Without such comments the following situation is possible:
154-
1. You (or your colleague) open the code written some time ago, and see that it's "suboptimal".
155-
2. You think: "How stupid I was then, and how much smarter I'm now", and rewrite using the "more obvious and correct" variant.
156-
3. ...The urge to rewrite was good. But in the process you see that the "more obvious" solution is actually lacking. You even dimly remember why, because you already tried it long ago. You revert to the correct variant, but the time was wasted.
155+
بدون هذه التعليقات يكون الوضع التالي ممكناً:
156+
1. أنت (أو زميلك) تفتح الشفرة المكتوبة منذ بعض الوقت ، وترى أنها "دون المستوى الأمثل".
157+
2. أنت تفكر: "كم كنت غبيًا في ذلك الوقت ، وكم أنا أذكى الآن" ، وأعد الكتابة باستخدام متغير "أكثر وضوحًا وصحة".
158+
3. ... كانت الرغبة في إعادة الكتابة جيدة. ولكن في هذه العملية ، ترى أن الحل "الأكثر وضوحًا" غير موجود بالفعل. حتى أنك تتذكر لماذا ، لأنك جربته بالفعل منذ فترة طويلة. أنت تعود إلى البديل الصحيح ، لكن الوقت ضاع.
157159

158-
Comments that explain the solution are very important. They help to continue development the right way.
160+
التعليقات التي تشرح الحل مهمة جدا. أنها تساعد على مواصلة التنمية بالطريقة الصحيحة.
159161

160-
Any subtle features of the code? Where they are used?
161-
: If the code has anything subtle and counter-intuitive, it's definitely worth commenting.
162+
أي ميزات خفية للكود؟ أين يتم استخدامها؟
163+
: إذا كان الرمز يحتوي على أي شيء خفي وغير بديهي ، فمن المؤكد أنه يستحق التعليق.
162164

163-
## Summary
165+
## ملخص
164166

165-
An important sign of a good developer is comments: their presence and even their absence.
167+
من التعليقات الهامة لمطور جيد التعليقات: حضورهم وحتى غيابهم.
166168

167-
Good comments allow us to maintain the code well, come back to it after a delay and use it more effectively.
169+
تسمح لنا التعليقات الجيدة بالحفاظ على الشفرة جيدًا ، والعودة إليها بعد فترة تأخير واستخدامها بشكل أكثر فعالية.
168170

169-
**Comment this:**
171+
** تعليق هذا: **
170172

171-
- Overall architecture, high-level view.
172-
- Function usage.
173-
- Important solutions, especially when not immediately obvious.
173+
- العمارة الشاملة ، منظر عالى المستوى.
174+
- استخدام الوظيفة.
175+
- حلول مهمة خاصة عندما لا تكون واضحة على الفور.
174176

175-
**Avoid comments:**
177+
** تجنب التعليقات: **
176178

177-
- That tell "how code works" and "what it does".
178-
- Put them in only if it's impossible to make the code so simple and self-descriptive that it doesn't require them.
179+
- يخبر "كيف يعمل الرمز" و "ماذا يفعل".
180+
- ضعهم فقط إذا كان من المستحيل جعل الكود بسيطًا وصفيًا ذاتيًا بحيث لا يتطلبهم.
179181

180-
Comments are also used for auto-documenting tools like JSDoc3: they read them and generate HTML-docs (or docs in another format).
182+
تُستخدم التعليقات أيضًا في أدوات التوثيق التلقائي مثل JSDoc3: فهم يقرؤونها وينشئون مستندات HTML (أو مستندات بتنسيق آخر).

0 commit comments

Comments
 (0)