22-09-2006, 21:31
|
|
|
|
חבר מתאריך: 09.12.01
הודעות: 2,337
|
|
תגובה לשניכם
לא אמרתי לכנות את כל המשתנים בצורה של a,b,c,i,j,k,x,z,
כמובן שיש צורך לכנות אותם בשמות שיסברו פחות או יותר מה התפקיד שלהם.
אמרתי שמתכנת שאינו יודע מה המשתנים בהם הוא משתמש כאשר זה הקוד שלו אז יש פה בעיה.
לגבי ה-underscore (קו תחתון _ ), בוודאי שיש צורך להשתמש בזה, ואני אפילו מעדיף להשתמש ב קו תחתון כאשר יש צורך בכך (לחלק את שם המשתנה למספר מילים: $user_info).
דיברתי ספציפית על caps, וקטע מתוך מאמר נחמד שמדבר בדיוק על זה:
Yes, I know you can mix upper and lower case - but do you
really want to? It's so easy to use upper case for one
variable, lower case for another, then to forget which you
used later on.
Suggestion - keep all your "simple" variables to lower case
throughout. Depending on the language you're using, you may
wish to capitalise object or class names, or package names.
And you may wish to write constants all in capitals.
Should you use underscores in variable names? It's up to
you - if your variable name is several words joined
together, you may wish (consistently) to place an underscore
between words and / or to capitalise the first letter of
each embedded word - sometimes known as "camel case".
In Python, you're recommended to start a private variable
name with a single underscore, and an intensely private name
with a double underscore. System names start AND end with
double underscore.
עריכה: המאמר לקוח מפה: http://www.wellho.net/solutions/gen...iable-name.html
ודוקמנטציה זה הדבר הכי חשוב, גם אם אתה כותב שם ארוך למשתנה, זה לא מחליף את הצורך בלהסביר למה המשתנה קיים וכיצד להשתמש בו.
P.S. בקשר לעבודה,
כרגע אני עדיין ממשיך לעבוד בעבודתי, ומאוד אוהבים את דרך כתיבת הקוד שלי, ואני הוא זה שסובל ממשתנים כמו MyUserForm['input'] או my_user_formשעדיף היה להשתמש ב form['input']...
וכשאותכם יפתרו על זה שאתם עובדים על קוד של שעה ארבע שעות, תבינו שאתם עושים משהו שהוא לא נכון.
עד אז, תמשיכו ללמוד דרכים שגויות לתכנת, ולהסתמך על IntelliSense שיש במקומות בודדים, וצריך לדעת לעבוד גם בלי AutoComplete...
בהצלחה
_____________________________________
“The man of wisdom is never in two minds about right and wrong;
the man of benevolence never worries about the future;
the man of courage is never afraid.”
~ Confucius
נערך לאחרונה ע"י The AcE בתאריך 22-09-2006 בשעה 21:32.
סיבה: הוספת קישור למאמר המדובר
|