Pharmacist or a Doctor - What does your code base need?

43
Pavan Sudarshan @pavanks Anandha Krishnan @anandhak (Jake)

description

"This talk was presented by @pavanks and @anandhak at Garden Citry Ruby Conf 2014". You might know of every single code quality & metrics tool in the Ruby ecosystem and what they give you, but do you know: Which metrics do you currently need? Do you really need them? How do you make your team members own them? Wait, there was a metaphor in the title While a pharmacist knows about pretty much every medicine out there and what it cures, its really a doctor who figures out what is required given the symptoms of a patient. Just like the vitals recorded for healthy adults, infants, pregnant women or an accident patient in an ICU changes, your code base needs different metrics in different contexts to help you uncover problems. Talk take aways Through a lot of examples, the talk helps: Identify the current state of your code base Understand different metrics and what do they tell you about your code base Drive your team towards continuously fixing problems uncovered by these metrics

Transcript of Pharmacist or a Doctor - What does your code base need?

Page 1: Pharmacist or a Doctor - What does your code base need?

Pavan Sudarshan@pavanks

Anandha Krishnan@anandhak (Jake)

Page 2: Pharmacist or a Doctor - What does your code base need?

Disclaimer

This talk is mostly platform/language independent.

But, we think the Ruby community is very aligned to most of what we will be talking about

Page 3: Pharmacist or a Doctor - What does your code base need?

We have made a lot of mistakes*...

…all our life as hackers

We want to talk about one such mistake with a couple of examples

* No employers or paranoid androids were hurt in the process!

Page 4: Pharmacist or a Doctor - What does your code base need?

About 3 months back...

I saw this guy walk into a pharmacy and ask for some medicine for a toothache

Page 5: Pharmacist or a Doctor - What does your code base need?

Between us, we have seen people ask...

Page 6: Pharmacist or a Doctor - What does your code base need?

Medicines for

→ Headache→ Fever→ Dysentery→ Rashes→ Cuts from a knife (I am still scared about this

one!)

Page 7: Pharmacist or a Doctor - What does your code base need?

Do you see anything wrong with this?

Page 8: Pharmacist or a Doctor - What does your code base need?

A pharmacy...

Potentially has a cure for pretty much most ailments

Page 9: Pharmacist or a Doctor - What does your code base need?

But the important thing is…

To figure out which ailment you are actually suffering from?

Page 10: Pharmacist or a Doctor - What does your code base need?

If choosing the right medicine was that simple, the world would just have...

Page 11: Pharmacist or a Doctor - What does your code base need?

Pharmacists

and not

Doctors

Page 12: Pharmacist or a Doctor - What does your code base need?

Doctors treat attack symptoms by...

→ Coming up with a problem hypothesis

→ Using Diagnostic tests

→ Prescribing the right treatment

→ Validating that the symptoms vanish

Page 13: Pharmacist or a Doctor - What does your code base need?

Pharmacists understand...

→ The details of the medicines

→ They can reverse engineer to find the disease based on the medicines

→ Are not responsible for prescribing treatment

Page 14: Pharmacist or a Doctor - What does your code base need?

Now, with this context, lets get back to our mistake...

Page 15: Pharmacist or a Doctor - What does your code base need?

Our mistake...

The way we dealt with bad symptoms in our code bases & projects

Page 16: Pharmacist or a Doctor - What does your code base need?

Anecdote - 1

Page 17: Pharmacist or a Doctor - What does your code base need?

Pesky regression bugs

Every time we built something, a bunch of other things broke.

Page 18: Pharmacist or a Doctor - What does your code base need?

Goal

Reduce the number of these bugs which were around 10 every iteration to 5

Page 19: Pharmacist or a Doctor - What does your code base need?

Some facts

→ We took over the project from another team

→ Our knowledge of the code base was bad

→ Test Coverage was extremely low

Page 20: Pharmacist or a Doctor - What does your code base need?

What would you do if you were to fix this?

Page 21: Pharmacist or a Doctor - What does your code base need?

Low coverage was staring us straight in the eyes

Page 22: Pharmacist or a Doctor - What does your code base need?

Fix coverage first

→ Regression bugs could be caught by tests

→ We focussed on increasing coverage

→ Started monitoring and improving coverage steadily over a period of 2 months

Page 23: Pharmacist or a Doctor - What does your code base need?

Our thought process was something like this...

Page 24: Pharmacist or a Doctor - What does your code base need?

Metric/Tool

Symptom

Solution

Provokes Improves

Page 25: Pharmacist or a Doctor - What does your code base need?

And the result?

Page 26: Pharmacist or a Doctor - What does your code base need?

We ended up...

→ Improving coverage drastically

→ However, things got marginally better, but just that, marginal

Page 27: Pharmacist or a Doctor - What does your code base need?

While us devs were happy about the coverage, the project manager was

extremely frustrated

Page 28: Pharmacist or a Doctor - What does your code base need?

This and a lot of similar mistakes...

Across different projects, drove us to rethink our approach.

We ended up realising something basic...

Page 29: Pharmacist or a Doctor - What does your code base need?

Never improve a metric.

Solving a problem should automatically improve the metric.

Page 30: Pharmacist or a Doctor - What does your code base need?

Instead of this...

Page 31: Pharmacist or a Doctor - What does your code base need?

Metric/Tool

Symptom

Solution

Provokes Improves

Targets

Page 32: Pharmacist or a Doctor - What does your code base need?

Problem

Symptom

Solution

Metrics

MeasuresProblem

Solution

Metrics

Problem

Solution

Metrics

Identifies

Fixes

Page 33: Pharmacist or a Doctor - What does your code base need?

We basically stopped doing this...

→ Crawl github to find a suitable gem

→ Setup it and start monitoring

→ Spend time and effort to improve what you are monitoring

Page 34: Pharmacist or a Doctor - What does your code base need?
Page 35: Pharmacist or a Doctor - What does your code base need?

Lessons learnt about Test Coverage

Page 36: Pharmacist or a Doctor - What does your code base need?

Measuring

→ Controller specs vs Model specs coverage

→ Just line coverage is not very useful*

→ Line→ Branch→ Unique path

* The Single Metric Fallacy

Page 37: Pharmacist or a Doctor - What does your code base need?

Reporting

→ Coverage is inherently not red/green

→ Code climate does a very good job

Page 38: Pharmacist or a Doctor - What does your code base need?

Ratcheting

→ Double edged sword

→ Make sure people are not scared/hate coverage

Page 39: Pharmacist or a Doctor - What does your code base need?

Improving→ Adding unit tests to old untested code bases

is dangerous

→ Higher level tests (functional tests) are a great safety net for refactoring

Page 40: Pharmacist or a Doctor - What does your code base need?

Always keep in mind the problem you’re solving

Page 41: Pharmacist or a Doctor - What does your code base need?

Anecdote - 2

About 5 percent of requests take a very long time to return

Page 42: Pharmacist or a Doctor - What does your code base need?

Goal

Find the root cause of the unpredictable response times and fix it.

Page 43: Pharmacist or a Doctor - What does your code base need?

Questions?