Skip to content

Commit 9cd5abd

Browse files
Merge pull request #39 from pro1code1hack/writing__comments
Writing comments
2 parents ab7b355 + 033ea46 commit 9cd5abd

14 files changed

+230
-0
lines changed

Base/11.Writing comments.py

Whitespace-only changes.

Base/11.Writing_comments.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Writing comments
2+
3+
## Introduction
4+
5+
When you write code in python it is important for it to be understandable by other people, and in order to reach this
6+
effect you can give variables and functions appropriate names, you can also help person who reads your code understand
7+
it by writing comments.
8+
9+
In this guide you will learn:
10+
11+
- Importance of commenting
12+
- How to write comments
13+
- How not to write comments
14+
15+
## Importance of commenting
16+
17+
An essential component of any program is comments. They might take the form of inline explanations that clarify
18+
complicated functions, module-level docstrings, or both. Let's examine the significance of code comments before delving
19+
into the various forms of comments. Think about the next two situations where a programmer choose not to comment their
20+
code:
21+
22+
### When you're writing code for yourself
23+
24+
Developers often forget what their code looks like when they're under a lot of pressure. Writing comments as you go is a
25+
great way to prevent this from happening.
26+
27+
### When you're writing code for someone else
28+
29+
Using comments throughout your code can help other developers. Comments help other devs skim through your code and gain
30+
an understanding of how it all works very quickly. You can help ensure a smooth transition by choosing to comment your
31+
code from the outset of a project.
32+
33+
## How to write comments
34+
35+
To write comment in python you simply have to put `#` before the text that you want to be commented, this part will be
36+
completely ignored by python:
37+
38+
```python
39+
print("hi") # print("bye")
40+
```
41+
42+
#### Output:
43+
44+
```
45+
hi
46+
```
47+
48+
how you can see `#print("bye")` part is ignored and doesn't influence output.
49+
<br/>
50+
Comments must be short and to the point. Maximum 72 characters for inline comment is appropriate, if you surpass this
51+
value you should translate your comment to the next line.
52+
53+
### Multiline comments
54+
55+
Unfortunately, in python, you can't make multiline comments like in other languages, instead you can add more `#`s:
56+
57+
```python
58+
# This is example
59+
# of multiline
60+
# commenting in python
61+
```
62+
63+
there is another way of creating comment:
64+
65+
```python
66+
"""
67+
this is another example
68+
of multiline comment
69+
which is not really a comment
70+
"""
71+
```
72+
73+
this is string that is not assigned by any of the variables so it is ignored by pythin,
74+
but you have to be careful with these things, because sometimes, when you comment function or methods this way, it
75+
might confuse people who read your code.
76+
77+
## How not to write comments
78+
79+
1. Avoid D.R.Y. comments(D.R.Y. stands for "don't repeat yourself"), your comments mustn't be redundant. There is no
80+
need
81+
to comment pieces of code tht speak for themselves:
82+
83+
```python
84+
def foo():
85+
a = 0
86+
return a # returns a
87+
```
88+
89+
2. Avoid comments that are trying to hide problems of your code.
90+
3. Avoid rude comments:
91+
92+
```python
93+
# This fucking code Sasha has written is yebala, needs to be fixed
94+
```

Base/12.PyCharm Guide.py

Whitespace-only changes.

Base/12.PyCharm_Features.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
### Contents
2+
3+
1. Rename file and it's references
4+
2. Rename a variable(and not only) across the project
5+
3. Navigate to symbol
6+
4. Navigate to file
7+
5. Select the whole code
8+
6. Make your code beautiful
9+
7. Optimize import
10+
8. Find action
11+
9. Local file history
12+
10. Quick fixes
13+
11. Multiple cursors
14+
15+
### 1.Rename file
16+
17+
To rename a file and all it's references you simply have to right-click on the file and then refactor-->rename
18+
<br/>
19+
**Shortcut** - *shift f6*
20+
21+
### 2.Rename symbol
22+
23+
In order to change the name of a variable object or anything else, select the symbol right-click on it and then
24+
refactor-->rename.
25+
<br/>
26+
**Shortcut** - *shift f6*
27+
28+
### 3.Navigate to symbol
29+
30+
In order to navigate to any variable in your code use ***Shift-Ctrl-Alt-N***(windows) or ***Alt-Cmd-O***(mac). Then type
31+
the
32+
name you are looking for.
33+
34+
### 4.Navigate to file
35+
36+
In order to navigate to any file in your project use ***Shift-Ctrl-N***(windows) or ***Shift-Cmd-O***(mac). Then type
37+
the
38+
name you are looking for.
39+
40+
### 5.Select the whole code
41+
42+
To select the whole code in a file press ***Ctrl-A***(windows) or ***Cmd-A***(mac)
43+
44+
### 6.Make your code beautiful
45+
46+
select the code you want to reformat and press ***Ctrl-Alt-L***(windows) or ***Cmd-Alt-L***
47+
48+
### 7.Optimize import
49+
50+
To optimize imports in a file simply press ***Ctrl+Alt+Shift+L***(windows) or ***Cmd+Alt+Shift+L***(mac)
51+
52+
### 8.Find action
53+
54+
If you can't remember how to call action, for example, navigate by symbol, you can just use one, find action by pressing
55+
***Ctrl+Shift+A***(windows) or ***Cmd+Shift+A***(mac) and typing the action you need.
56+
57+
### 9.Local file history
58+
59+
If you made something stupid in past and now want to return to that point there is a way of doing it through local
60+
history of the file. To open the history right-click on the file then Local History-->Show History
61+
62+
### 10.Quick fixes
63+
64+
Sometimes when pycharm shows you that something is wrong with a part of code by underlining it with the red line, if you
65+
select the problem part and press ***Alt-Enter***, pycharm will show you the list of fixes that might help.
66+
67+
### 11.Multiple cursors
68+
69+
If you will writing multiple identical or similar lines of code you can use multiple cursor be holding *Alt* and
70+
clicking
71+
on the places where you need additional cursor.

Base/13.Debugging.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Debugging in pycharm
2+
3+
To prepare PyCharm for debugging, you need to specify a so-called breakpoint. This is the line after which the debugger
4+
will start and the code will step through. Since our program is small, we will tell the debugger to start from the
5+
beginning. To put a breakpoint, you need to click the mouse to the left of the needed line and to the right of its
6+
number. A red circle will appear at this point, indicating that a pause will occur at this point. To remove the
7+
breakpoint, you need to click on the red circle again.
8+
9+
![](images/debugging_break_point.png)
10+
11+
Then you have to launch the debugger, in order to launch it you can either click on the debugger icon in up right corner
12+
or press *shift + f9* if you use windows or linux and *option + D* on mac.
13+
14+
![](images/debugging_console.png)
15+
16+
We now see two tabs: *Debugger* and *Console*. In the console, we see everything that the program has displayed so far.
17+
Since we stopped execution at the very beginning, the console will be empty for now. It is the debugger window that is
18+
of interest to us, since here we can track the change of all variables. As you can see, we already have a list of
19+
Special Variables, in which you can see the values of such utility variables as `__name__`.
20+
21+
![](images/debugging_special_variables.png)
22+
23+
To start tracking a new variable, enter the name of the variable to the input field and click on a plus icon. First, we
24+
will see the inscription name 'i' is not defined, which means that our variable has not even been created yet.
25+
26+
![](images/dubugging_add_variable.png)
27+
![](images/debugging_name_not_defined.png)
28+
29+
Let's then tell the debugger to process the next line of code. It is important to note here that there are 2 main
30+
ways of stepping: *step into* and *step over*.
31+
32+
### step into
33+
34+
When stepping into, the debugger will "enter" inside all functions and other constructs if it encounters them. So, if
35+
the debugger comes to calling some function func(), then it will go to the part of the code where its contents are
36+
described. To make one step into, press F7.
37+
38+
### step over
39+
40+
With the step over, the debugger will not “enter” all functions and other constructs, but will simply execute the
41+
entire code of the function without stopping and continue execution further. To make one step over, press F8.
42+
43+
### Process itself
44+
45+
In our example, it doesn't matter what to use, since we don't have any functions. So let's use the over step.
46+
When stepping through each line, we will go through the loop 9 times and see how the variable i changes 9
47+
times:
48+
<br/>
49+
50+
*press F8*
51+
![](images/debugging_step_0.png)
52+
53+
*press F8*, twice(because we go to the loop line itself firstly)
54+
![](images/debugging_step_1.png)
55+
56+
*press F8*, twice(because we go to the loop line itself firstly)
57+
![](images/debugging_step_2.png)
58+
59+
You can either stop debugging manually or wait until the debugger has processed all the lines in the program, which is
60+
almost never found in practice. You can also create multiple breakpoints.
61+
62+
### Conclusion
63+
64+
All in all, debugging is an indispensable thing in the development of real projects, because it is the most effective
65+
tool for finding errors.

Base/13.Debugging.py

Whitespace-only changes.
26.2 KB
Loading

Base/images/debugging_console.png

87.8 KB
Loading
95.9 KB
Loading
159 KB
Loading

0 commit comments

Comments
 (0)