Lower your WTFs/min

Who am I?
- Alex Muscalu
- 5 years experience with Java
- fan of "Uncle Bob"
- written a lot of ugly and bad code
Why I am actually here for


Looooooooo.....oooong functions
You start with
something like this...

And then...

But you get attached...

Anyway, you know everything there by heart!

WRONG!
What to do? Simple:
- Write unit tests
- Split into smaller functions
- Find abstractions
- ...in one word: REFACTOR
Boolean Parameters
What does this
little fella do?

How about this one?

Let's make this harder.
How many implementations does this function have?

Why is this BAD?
Clear violation of SRP
What to do? Simple:
- Write tests for the big function
- Split into multiple functions
- ...in one word: REFACTOR
Cryptic code

What does that piece of code do?
Context
Implement a method that receive the configuration of bagel packs sold by a bakery and the amount of items that will be bought and returns the bundle configuration.
Example:
Packs configuration: {2, 5, 8}
Amount: 14
Answer: 1 x 8 + 3 x 2
What's wrong?
- method name
- variables names
- magic numbers
- ...pretty much everything

What's better?
- no more magic numbers
- variables relate to the problem that is being solved
- redability...at least a little bit

What to do? Simple:
- "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- write unit tests
- use descriptive names for everything
- use local variables to increase readability
Return fast
Subtitle

An else follows...
Two tabs
How to simplify?

Less tabs => easier to read
So...
What was this all about?
Refactoring
and
Unit testing
Thank you!*
*for bearing with me at this early hour
Lower you WTF/min
By Alexandru Muscalu
Lower you WTF/min
- 52