-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnaming.py
73 lines (49 loc) · 1.93 KB
/
naming.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
###################### Bad naming examples ##################
from datetime import datetime
class Entity:
def __init__(self, title, description, ymdhm):
self.title = title
self.description = description
self.ymdhm = ymdhm
def output(item):
print('Title: ' + item.title)
print('Description: ' + item.description)
print('Published: ' + item.ymdhm)
summary = 'Clean Code Is Great!'
desc = 'Actually, writing Clean Code can be pretty fun. You\'ll see!'
new_date = datetime.now()
publish = new_date.strftime('%Y-%m-%d %H:%M')
item = Entity(summary, desc, publish)
output(item)
##################### Better naming examples ########################
class BlogPost:
def __init__(self, title, description, dete_published):
self.title = title
self.description = description
self.date_published = dete_published
def print_blog_post(blog_post):
print('Title: ' + blog_post.title)
print('Description: ' + blog_post.description)
print('Published: ' + blog_post.date_published)
title = 'Clean Code Is Great!'
description = 'Actually, writing Clean Code can be pretty fun. You\'ll see!'
now = datetime.now()
formatted_date = now.strftime('%Y-%m-%d %H:%M')
post = BlogPost(title, description, formatted_date)
print_blog_post(post)
##################### Best naming examples ######################
class BlogPost:
def __init__(self, title, description, date_published):
self.title = title
self.description = description
self.date_published = date_published
def print(self):
print('Title: ' + self.title)
print('Description: ' + self.description)
print('Published: ' + self.date_published)
title = 'Clean Code Is Great!'
description = 'Actually, writing Clean Code can be pretty fun. You\'ll see!'
now = datetime.now()
formatted_date = now.strftime('%Y-%m-%d %H:%M')
post = BlogPost(title, description, formatted_date)
post.print()