There are only two hard things in Computer Science: cache invalidation and naming things.
Phil Karlton
There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors
Leon Bambrick
There are only two hard problems in distributed systems:
2. Exactly-once delivery
1. Guaranteed order of messages
2. Exactly-once delivery
Mathias Verraes
Paweł Lewtak
Senior Developer at Xstream
@pawel_lewtak
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
Code for readability.
John F. Woods
def a(b):
c = sorted(b)
d = len(b)
if d % 2 == 1:
return c[(d - 1) / 2]
else:
return (c[d/2 - 1] + c[d/2]) / 2
def median(pool):
copy = sorted(pool)
size = len(copy)
if size % 2 == 1:
return copy[(size - 1) / 2]
else:
return (copy[size/2 - 1] + copy[size/2]) / 2
total = price * qty
total2 = total - discount
total2 += total * taxrate
total3 = purchase_order_value + available_credit
if total2 < total3:
print ("You can't afford this order.")
order_total = price * qty
payable_total = order_total - discount
payable_total += payable_total * taxrate
available_funds = purchase_order_value + availble_credit
if payable_total < available_funds:
print ("You can't afford this order.")
No-one sets out to write legacy code
Rachel Willmer
Misapplied Java design patterns
are the root of all AbstractWordFactoryFactory("evil")
HN comment
with extra operations inside
def is_active():
if cond:
return 'false'
return 'true'
def is_valid():
if input_is_valid:
return True
def get_person():
return ['John Doe', 'Jane Doe']
def get_employers():
return 'John Doe'
def get_lowest_price(user):
pass
def get_lowest_price(user):
"""Actually it returns the highest price."""
pass
def median(pool):
'''Statistical median to demonstrate doctest.
>>> median([2, 9, 9, 7, 9, 2, 4, 5, 8])
7
'''
copy = sorted(pool)
size = len(copy)
if size % 2 == 1:
return copy[(size - 1) / 2]
else:
return (copy[size/2 - 1] + copy[size/2]) / 2
if __name__ == '__main__':
import doctest
doctest.testmod()
pos
mod
abs
auth
import requests
response = requests.get('https://cz.pycon.org/2017/')
if response.status_code == 200:
print ("It works!")
elif response.status_code == 418:
print ("Unexpected teapot!")
import requests
response = requests.get('https://cz.pycon.org/2017/')
if response.status_code == requests.codes.ok:
print ("It works!")
elif response.status_code == requests.codes.teapot:
print ("Unexpected teapot!")
def get_data():
""" Returns the data. """
pass
def get_max_id_from_db():
""" Return maximum ID value from the database."""
pass
Short (50 chars or less) summary of changes
More detailed explanatory text, if necessary. Wrap it to
about 72 characters or so. In some contexts, the first
line is treated as the subject of an email and the rest of
the text as the body. The blank line separating the
summary from the body is critical (unless you omit the body
entirely); tools like rebase can get confused if you run
the two together.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet,
preceded by a single space, with blank lines in
between, but conventions vary here
host_list, host_set => hosts, valid_hosts
value_string => first_name, lowercased_SKU
int_number => account_number
Short, bite size, single logical change
@pawel_lewtak