Why should I listen if I do security?
Take a look at:
https://www.cursivesecurity.com/blog/2017/libressl-replacement-openssl/
https://en.wikipedia.org/wiki/LibreSSL
Because it'll make you more attractive, it'll make you jump higher and be more awesome.
Use Pythonic code conventions and format using Pep8.
Try to show your intention with your code.
Care about the names that you give your classes variables.
Make functions small and easy to digest.
Bad!
Good!
kitty = 'Marshmallow'
found = False
if kitty == 'Marshmallow' or kitty == 'Gambit' or kitty == 'Ghost':
found = True
found = 'Marshmallow' in ['Marshmallow', 'Gambit', 'Ghost']
Bad!
Good!
kitten_is_cute = True
rat_is_cute = False
cuteness = [kitten_is_cute, rat_is_cute]
if kitten_cute == True:
# pet kitty
elif rat_is_cute == False:
# ignore rat
if len(cuteness) > 0:
# see if animals are cute
kitten_is_cute = True
rat_is_cute = False
cute_list = [kitten_is_cute, rat_is_cute]
if kitten_cute:
# pet kitty
elif not rat_is_cute:
# ignore rat
if cute_list:
# see if animals are cute
Bad!
Good!
def check_equal(x, y):
result = False
if x == y:
result = True
return result
def is_equal(first, other):
return first == other
Bad!
Good!
def user_info(user, cats):
return 'Name: ' + user.name + ' Age: '+ user.age + ' number of cats:' + cats
def get_user_details(user, cats):
return 'Name: {user.name} Age: {user.age} number of cats '.format(
user=user,
cats=cats
)
Bad!
Good!
ls = list()
for element in range(10):
if not(element % 2):
ls.append(element)
# We may also employ a lambda function
ls = list(filter(lambda element: not(element % 2), range(10)))
def is_even(number):
return not(number % 2)
even_numbers = [element for element in range(10) if is_even(element)]
Bad!
Good!
ls1 = [1, 2, 3, 4, 5]
ls2 = [4, 5, 6, 7, 8]
elements_in_both = []
for element in ls1:
if element in ls2:
elements_in_both.append(element)
print(elements_in_both)
number_bunch = [1, 2, 3, 4, 5]
second_number_bunch = [4, 5, 6, 7, 8]
numbers_in_both_bunches = list(set(number_bunch) & set(second_number_bunch))
print(numbers_in_both)
Bad!
Good!
all_cats = None
cat = None
if 'marshmallow' in all_cats:
auth = all_cats['marshmallow']
else:
auth = 'No Cats Found'
cat = all_cats.get('marshmallow', 'No Cats Found')
Idiomatic Python. Coding the smart way.
(https://medium.com/the-andela-way/idiomatic-python-coding-the-smart-way-cc560fa5f1d6)
Writing Idiomatic Python.
https://jeffknupp.com/writing-idiomatic-python-ebook/
Pep8
https://www.python.org/dev/peps/pep-0008/
Clean Code:A Handbook of Agile Software Craftsmanship
https://www.amazon.ca/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=pd_lpo_sbs_14_t_1?_encoding=UTF8&psc=1&refRID=N7SYPCHTQKZWNQGFSEWT
Test Driven Development with Python
https://www.obeythetestinggoat.com/
Test Driven Development by example (written for java but applies)
https://www.amazon.ca/Test-Driven-Development-Kent-Beck/dp/0321146530
If you write good code you'll be able to do the following:
If you write bad code you'll feel the following:
If you're me you like my cats
Marshmallow
Ghost
Gambit