Pharmacist or a Doctor - What does your code base need?
-
Upload
anandha-krishnan -
Category
Technology
-
view
66 -
download
0
description
Transcript of Pharmacist or a Doctor - What does your code base need?
![Page 1: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/1.jpg)
Pavan Sudarshan@pavanks
Anandha Krishnan@anandhak (Jake)
![Page 2: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/2.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/3.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/4.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/5.jpg)
Between us, we have seen people ask...
![Page 6: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/6.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/7.jpg)
Do you see anything wrong with this?
![Page 8: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/8.jpg)
A pharmacy...
Potentially has a cure for pretty much most ailments
![Page 9: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/9.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/10.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/11.jpg)
Pharmacists
and not
Doctors
![Page 12: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/12.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/13.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/14.jpg)
Now, with this context, lets get back to our mistake...
![Page 15: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/15.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/16.jpg)
Anecdote - 1
![Page 17: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/17.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/18.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/19.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/20.jpg)
What would you do if you were to fix this?
![Page 21: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/21.jpg)
Low coverage was staring us straight in the eyes
![Page 22: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/22.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/23.jpg)
Our thought process was something like this...
![Page 24: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/24.jpg)
Metric/Tool
Symptom
Solution
Provokes Improves
![Page 25: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/25.jpg)
And the result?
![Page 26: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/26.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/27.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/28.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/29.jpg)
Never improve a metric.
Solving a problem should automatically improve the metric.
![Page 30: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/30.jpg)
Instead of this...
![Page 31: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/31.jpg)
Metric/Tool
Symptom
Solution
Provokes Improves
Targets
![Page 32: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/32.jpg)
Problem
Symptom
Solution
Metrics
MeasuresProblem
Solution
Metrics
Problem
Solution
Metrics
Identifies
Fixes
![Page 33: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/33.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/34.jpg)
![Page 35: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/35.jpg)
Lessons learnt about Test Coverage
![Page 36: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/36.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/37.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/38.jpg)
Ratcheting
→ Double edged sword
→ Make sure people are not scared/hate coverage
![Page 39: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/39.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/40.jpg)
Always keep in mind the problem you’re solving
![Page 41: Pharmacist or a Doctor - What does your code base need?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/41.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/42.jpg)
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?](https://reader033.fdocuments.us/reader033/viewer/2022042816/55936cf31a28ab6e138b4705/html5/thumbnails/43.jpg)
Questions?