חלקPart 3: קוד נקי ו-OOPClean code & OOP
כ-3 שעות (כולל הפסקה)About 3 hours (with a break)
Git ו-GitHubGit & GitHub
commit, branch, merge, push ו-README טוב.
commit, branch, merge, push and a good README.
הנקודות החשובותKey points
final_v2_REAL.pyזה לא שיטהfinal_v2_REAL.pyis not a system- היסטוריה מלאה, חזרה לכל נקודהFull history, return to any point
git initיוצר מאגרgit initcreates a repogit add→ אזור ההכנה (staging)git add→ staging areagit diff: מה השתנה ועדיין לא נשמרgit diff: what changed and isn't saved yetgit log --oneline: רשימת ה-commitsgit log --oneline: the list of commits- לא שומרים
.venv/ו-__pycache__/Don't save.venv/and__pycache__/ - לעולם לא סיסמאות ומפתחותNever passwords and keys
git switch -c featureיוצר ענף ועובר אליוgit switch -c featurecreates a branch and moves to it
מונחיםTerms
- GitGit: תוכנה ששומרת את כל ההיסטוריה של הקוד: מי שינה מה ומתי, ומאפשרת לחזור לכל גרסה.Software that keeps the whole history of your code: who changed what and when, and lets you go back to any version.
- מאגר (repository)repository: תיקיית פרויקט ש-Git עוקב אחריה (יש בה תיקייה נסתרת
.git). בקיצור: repo.A project folder Git tracks (it has a hidden.gitfolder). Short: repo. - commitcommit: תמונת מצב שמורה של הקבצים, עם הודעה שמסבירה מה השתנה ומזהה ייחודי (hash).A saved snapshot of the files, with a message explaining what changed and a unique id (hash).
- אזור ההכנה (staging)staging area: המקום שבו מכינים מה ייכנס ל-commit הבא.
git addמכניס לשם קבצים.Where you prepare what goes into the next commit.git addputs files there. - ענף (branch)branch: קו פיתוח נפרד: אפשר לנסות רעיון בענף בלי לגעת בקוד הראשי, ואחר כך למזג.A separate line of work: try an idea on a branch without touching the main code, then merge.
- מיזוג (merge)merge: איחוד השינויים מענף אחד לענף אחר.Combining the changes from one branch into another.
- GitHubGitHub: אתר שמאחסן מאגרי Git ברשת: גיבוי, שיתוף, ועבודה משותפת. ה-repo שם נקרא remote.A website that hosts Git repositories online: backup, sharing and collaboration. The repo there is called a remote.
- .gitignore.gitignore: קובץ שמפרט אילו קבצים Git לא יעקוב אחריהם, כמו
.venv/וסיסמאות.A file listing what Git should not track, like.venv/and passwords.
Cheatsheet
.gitignore.gitignore
.venv/
__pycache__/
*.pyc
.env
shelf.dbשגיאות שפגשנוErrors we met
| שגיאהError | מה זה אומרWhat it means | מה עושיםWhat to do |
|---|---|---|
AssertionError | מוסיפים לקוד מפתח סודי, וכך הוא נשמר בהיסטוריה לתמיד.Putting a secret key in the code, so it's saved in history forever. | AssertionError: a secret is written in the code: ...: שומרים סודות בקובץ .env שמופיע ב-.gitignore, וקוראים אותם עם os.environ. נראה איך במפגש 33.AssertionError: a secret is written in the code: ...: keep secrets in a .env file listed in .gitignore and read them with os.environ. We'll see how in session 33. |