@@ -36,6 +36,7 @@ Targets Python3.7+
3636### Use meaningful and pronounceable variable names
3737
3838** Bad:**
39+
3940``` python
4041import datetime
4142
@@ -44,6 +45,7 @@ ymdstr = datetime.date.today().strftime("%y-%m-%d")
4445```
4546
4647** Good** :
48+
4749``` python
4850import datetime
4951
@@ -56,6 +58,7 @@ current_date: str = datetime.date.today().strftime("%y-%m-%d")
5658
5759** Bad:**
5860Here we use three different names for the same underlying entity:
61+
5962``` python
6063def get_user_info (): pass
6164def get_client_data (): pass
@@ -64,6 +67,7 @@ def get_customer_record(): pass
6467
6568** Good** :
6669If the entity is the same, you should be consistent in referring to it in your functions:
70+
6771``` python
6872def get_user_info (): pass
6973def get_user_data (): pass
@@ -102,6 +106,7 @@ understanding our program, we hurt our readers.
102106Make your names searchable.
103107
104108** Bad:**
109+
105110``` python
106111import time
107112
@@ -111,6 +116,7 @@ time.sleep(86400)
111116```
112117
113118** Good** :
119+
114120``` python
115121import time
116122
@@ -123,6 +129,7 @@ time.sleep(SECONDS_IN_A_DAY)
123129
124130### Use explanatory variables
125131** Bad:**
132+
126133``` python
127134import re
128135
@@ -155,6 +162,7 @@ if matches:
155162** Good** :
156163
157164Decrease dependence on regex by naming subpatterns.
165+
158166``` python
159167import re
160168
@@ -173,6 +181,7 @@ Don’t force the reader of your code to translate what the variable means.
173181Explicit is better than implicit.
174182
175183** Bad:**
184+
176185``` python
177186seq = (" Austin" , " New York" , " San Francisco" )
178187
@@ -185,6 +194,7 @@ for item in seq:
185194```
186195
187196** Good** :
197+
188198``` python
189199locations = (" Austin" , " New York" , " San Francisco" )
190200
@@ -266,12 +276,14 @@ arguments then your function is trying to do too much. In cases where it's not,
266276of the time a higher-level object will suffice as an argument.
267277
268278** Bad:**
279+
269280``` python
270281def create_menu (title , body , button_text , cancellable ):
271282 pass
272283```
273284
274285** Java-esque** :
286+
275287``` python
276288class Menu :
277289 def __init__ (self , config : dict ):
@@ -290,6 +302,7 @@ menu = Menu(
290302```
291303
292304** Also good**
305+
293306``` python
294307from typing import Text
295308
@@ -326,6 +339,7 @@ create_menu(config)
326339```
327340
328341** Fancy**
342+
329343``` python
330344from typing import NamedTuple
331345
@@ -360,6 +374,7 @@ create_menu(
360374```
361375
362376** Even fancier**
377+
363378``` python
364379from typing import Text
365380from dataclasses import astuple, dataclass
@@ -395,6 +410,7 @@ create_menu(
395410```
396411
397412** Even fancier, Python3.8+ only**
413+
398414``` python
399415from typing import TypedDict, Text
400416
@@ -439,6 +455,7 @@ cleaner. If you take nothing else away from this guide other than this, you'll b
439455of many developers.
440456
441457** Bad:**
458+
442459``` python
443460from typing import List
444461
@@ -460,6 +477,7 @@ def email_clients(clients: List[Client]) -> None:
460477```
461478
462479** Good** :
480+
463481``` python
464482from typing import List
465483
@@ -488,6 +506,7 @@ def email_clients(clients: List[Client]) -> None:
488506Do you see an opportunity for using generators now?
489507
490508** Even better**
509+
491510``` python
492511from typing import Generator, Iterator
493512
@@ -695,6 +714,7 @@ print(fullname) # ["Ryan", "McDermott"]
695714```
696715
697716** Good:**
717+
698718``` python
699719from typing import List, AnyStr
700720
@@ -709,6 +729,7 @@ print(name, surname) # => Ryan McDermott
709729```
710730
711731** Also good**
732+
712733``` python
713734from typing import Text
714735from dataclasses import dataclass
@@ -891,9 +912,9 @@ company_managers_list = get_employee_list(employees=company_managers)
891912
892913** [ ⬆ back to top] ( #table-of-contents ) **
893914
894- ## ** Translation **
915+ ## ** Translations **
895916
896- This is also available in other languages:
917+ This document is also available in other languages:
897918
898919- ![ br] ( https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png ) ** Brazilian Portuguese** : [ fredsonchaves07/clean-code-python] ( https://github.com/fredsonchaves07/clean-code-python )
899920
0 commit comments