You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/03-comments/article.md
+12-15Lines changed: 12 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,9 @@ code;
22
22
23
23
এ ব্যাপারে একটি সুন্দর নিয়ম আছেঃ "কোডটি যদি এতটাই অস্পষ্ট হয় যে এর জন্য একটি মন্তব্য প্রয়োজন, তবে সম্ভবত মন্তব্যের পরিবর্তে এটি পুনরায় লেখা উচিত"
24
24
25
+
### কৌশল: ফাংশন পুনর্গঠন
25
26
26
-
27
-
### Recipe: factor out functions
28
-
29
-
Sometimes it's beneficial to replace a code piece with a function, like here:
27
+
অনেক ক্ষেত্রে কোডের অংশবিশেষ এর বদলে ফাংশন ব্যবহার করাটা সুবিধাজনক। যেমনঃ
30
28
31
29
```js
32
30
functionshowPrimes(n) {
@@ -45,8 +43,7 @@ function showPrimes(n) {
45
43
}
46
44
```
47
45
48
-
The better variant, with a factored out function `isPrime`:
49
-
46
+
`isPrime` ফাংশন দিয়ে এর এর শ্রেয়তর বিকল্পঃ
50
47
51
48
```js
52
49
functionshowPrimes(n) {
@@ -67,11 +64,11 @@ function isPrime(n) {
67
64
}
68
65
```
69
66
70
-
Now we can understand the code easily. The function itself becomes the comment. Such code is called *self-descriptive*.
67
+
এখন আমরা খুব সহজেই কোডটি বুঝতে পারছি। ফাংশনটি নিজেই মন্তব্য হিসবে কাজ করছে। এ ধরনের কোড কে বলা হয় "স্ব-বর্ণনামূলক"
71
68
72
-
### Recipe: create functions
69
+
### কৌশলঃ ফাংশন তৈরি
73
70
74
-
And if we have a long "code sheet" like this:
71
+
এবং যদি আমাদের নিচের মত এরকম দীর্ঘ কোড শিট থাকেঃ
75
72
76
73
```js
77
74
// here we add whiskey
@@ -92,7 +89,7 @@ for(let t = 0; t < 3; t++) {
92
89
// ...
93
90
```
94
91
95
-
Then it might be a better variant to refactor it into functions like:
92
+
সেক্ষেত্রে শ্রেয়তর বিকল্পের জন্য কোডটি কে নিচের মত ফাংশনে পুনর্ঘঠন করা যেতে পারেঃ
96
93
97
94
```js
98
95
addWhiskey(glass);
@@ -113,15 +110,15 @@ function addJuice(container) {
113
110
}
114
111
```
115
112
116
-
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.
113
+
ফাংশন নিজেরাই কি ঘটছে ব্যাখ্যা করে। এখানে মন্তব্য লেখার কিছু নেই। এছাড়াও আলাদা আলাদা থাকলে কোডের গঠন ভালো হয়। এটা সুপষ্ট যে প্রতিটি ফাংশন কি করে, কি গ্রহণ করে এবং কি রিটার্ন করে।
117
114
118
-
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.
115
+
বাস্তবে,আমরা সম্পুর্ণরূপে ব্যখ্যা সম্বলিত মন্তব্য পরিহার করতে পারি না। এখানে উৎকর্ষতা সাধনের জন্য অনেক জটিল অ্যালগরিদম এবং অনেক সুক্ষ্ম সমন্বয় করা হয়। কিন্ত সাধারণভাবে আমাদের উচিৎ কোড কে সহজ-সরল এবং স্ব-বর্ণ্নামূলক রাখার জন্য চেষ্টা করা ।
119
116
120
-
## Good comments
117
+
## ভালো মন্তব্য
121
118
122
-
So, explanatory comments are usually bad. Which comments are good?
119
+
সুতরাং, ব্যাখ্যামূলক মন্তব্য সাধারণত খারাপ। সেক্ষেত্রে কোন ধরণের মন্তব্য ভাল?
123
120
124
-
Describe the architecture
121
+
গঠনপ্রণালী বর্ণনা করুন
125
122
: 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.
0 commit comments