What do software engineers do all day long? Write code? Of course! But what about reading code, about understanding what’s happening? Aren’t we doing that even more? I believe we do. Because of that code should be as readable as possible! But what does that even mean? How do we achieve readable code? This talk will introduce you to coding principles and techniques that will help you write more readable code, be more productive and have more fun!
24. def paint_control(event)
# some painting code
rescue => e
# Really important to rescue here.
Failures that escape this method
# cause odd-ball hangs with no
backtraces. See #559 for an example.
#
puts "SWALLOWED PAINT EXCEPTION ON
#{@obj} - go take care of it: " + e.to_s
puts 'Unfortunately we have to swallow
it because it causes odd failures :('
end
25. Also known as the smell that
tries to make other smells
seem ok
26. # do one thing
...
...
...
...
...
# do another thing
...
...
...
...
# do something more
...
...
27. # do one thing
...
...
...
...
...
# do another thing
...
...
...
...
# do something more
...
...
28. # do one thing
...
...
...
...
...
# do another thing
...
...
...
...
# do something more
...
...
Cocepts
44. # allowed to drink?
if customer.age >= 18
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{['cola', 'mate'].sample}?"
end
45. # allowed to drink?
if customer.age >= 18
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{['cola', 'mate'].sample}?"
end
48. # allowed to drink?
if customer.age >= MIN_DRINKING_AGE
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{NON_ALCOHOLIC_DRINKS.sample}?"
end
49. # allowed to drink?
if customer.age >= MIN_DRINKING_AGE
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{NON_ALCOHOLIC_DRINKS.sample}?"
end
50. # allowed to drink?
if customer.age >= MIN_DRINKING_AGE
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{NON_ALCOHOLIC_DRINKS.sample}?"
end
60. # allowed to drink?
if customer.age >= MIN_DRINKING_AGE
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{NON_ALCOHOLIC_DRINKS.sample}?"
end
61. # allowed to drink?
if customer.age >= MIN_DRINKING_AGE
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{NON_ALCOHOLIC_DRINKS.sample}?"
end
62. # allowed to drink?
if customer.age >= MIN_DRINKING_AGE
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{NON_ALCOHOLIC_DRINKS.sample}?"
end
63. # allowed to drink?
if customer.age >= MIN_DRINKING_AGE
say 'Okay'
drink = prepare_drink requested_drink
say 'here you go'
hand_drink_over drink, customer
else
say 'I am sorry you are not legally
allowed rather to drink here'
say "Would you rather have a
#{NON_ALCOHOLIC_DRINKS.sample}?"
end