SmartQA Community

COVID19 and Clean Code Part 1: Techniques

T Ashok (ash_thiru on Twitter)

Summary

Corona virus aka COVID19 is a global talking point now. What is being done to contain the COVID19? Well, there are THREE actions in terms of Prevention, Detection, Containment being aggressively pursued. Three targets of young children, old people and sick persons are the most vulnerable as of now. In this article we take a look at the actions being taken to contain the pandemic and relate to what to do deliver clean code.


Corona virus aka COVID19 is a global talking point now. A pandemic now, it has shaken the entire population of the world, busted the business and the world economy. The major stock markets are taking a massive beating driven by the sentiment that there is no medicine for this as of now.

Interestingly the suggestions posed by experts are pretty basic stuff related to good hygiene and this seems to be the only way to go given that there is no medicine as of now.  What can we learn from COVID19 to deliver clean code?

So what is being done to contain the COVID19? Well, there are THREE actions in terms of Prevention, Detection, Containment being aggressively pursued. Three targets of young children, old people and sick persons are the most vulnerable as of now.

What is being done in terms of PREVENTION that we can relate to code?

  1. Cover when you sneeze/cough => USE ASSERTS, HANDLE EXCEPTIONS
  2. Wash hands frequently => SIMPLIFY, REFACTOR
  3. Don’t touch surfaces => STRIVE FOR LOW COUPLING

What is being done in terms of DETECTION that we can relate to code?

  1. Check for fever => DO BASIC TESTS
  2. Check for other symptoms =>  USE SMART CHECKLISTS, DO DETAILED TESTS
  3. Check if contact with affected => DO STATIC CODE ANALYSIS
  4. Check origin on arrival (for travellers) => WRITE DEFENSIVE CODE
  5. Check travel history => ANALYSE CODE COVERAGE

What is being done in terms of CONTAINMENT that we can relate to code?

  1. Quarantine affected/suspected persons => REWRITE POOR CODE, DON’T FIX
  2. Use masks use asserts/ EMBED TESTABILITY
  3.  Publish routes travelled by affected people => PUBLISH CHANGE LOGS SO THAT OTHERS MAY ASCERTAIN IMPACT, CREATE INTERACTION MAPS, REGRESS CODE

Now who are the TARGETS that could be most impacted in COVID19  that we can relate to code?

  1. Young children => NEW CODE
  2. Old people => OLD CODE WITH MINIMAL DOCUMENTATION/CK COMMENTS
  3. Sick people => CODE FRAGMENTS THAT HAVE BEEN BUGGY

Here is the entire learnings summarised in the full mind-map.

Check out the current article COVID19 and Clean Code Part 2 : Process & Criteria,
that outlines techniques to deliver Process & Criteria, inspired by Covid19.


on Coverage

(In this SmartBits, Girish Elchuri outlines ” on Coverage “. The video is at the end of this blog)

During development,100% unit testing is needed, anything less is useless. Look at it this way; when you are crossing the chasm, if you jump even 99%, you still die. So it has to be 100%. The way I approach this is, every single line of code that I execute, I execute it as part of the code itself or execute it separately to make sure that the function is behaving the way that it is expected to behave for the parameters being passed.Most of the times the help text provided by the man-pages for the functions may not be 100% complete.From that perspective firstly you have to test the code by yourself. Secondly, certain functions even after being tested have to be again tested as a  part of the product and for that I do write a lot of scaffolding code. It is a must. This is not something that I preach, but I practise as well. At this stage, a lot of development of my product is done by myself and I do practise 100% of unit testing and in my opinion, there is no shortcut.