Showing posts with label Software Development. Show all posts
Showing posts with label Software Development. Show all posts

16 October 2018

Master, Expert and Machine

To build something new, you need a master. To improvise something that is built, you need an expert. To run something that is already built/improved, you need a machine

The points are:
  1. To build a software you need a master, to sustain it you need an expert and to operate it, you need a machine.
  2. To build quality you need a master, to improve it you need an expert and to just regress the past, you need a machine
These are phases and need not be necessary done by different people. The skills required diminishes as we traverse the phases (so are complexity)

Build -> Sustain -> Run requires Master -> Expert -> Machine

09 January 2018

Unit Tests - Are they important?

While I was going through some of the projects in GitHub, I found that almost all the projects have automated unit tests (I hope you will also see many of your projects have that. These days it is quite common to start off by writing tests first). These tests are run most of the times - before every commit, after every commit, nightly tests and at various stages. These tests are a critical and important piece in CI/CD. Tests, in general, are the cornerstone to software development. The tests are proof that the specific part of the software is working correctly and consistently.  In this post, I am going to talk about unit testing and in subsequent posts show some examples (in Python but you can find similar tools in other modern languages)

What is testing?
It is the systematic exploration of the subject and verifying all the aspects of the subject is intact. It is the philosophy that a faulty brick is responsible for bringing down a massive building. The main purpose of testing is building quality (correctness and consistency) and the side effect is "defects". 
What is a test case?
A test case is a scenario which ensures that a certain aspect of the subject works as intended (or does not work which becomes a defect). When you change the condition, it is altogether a different scenario. A test case with the correct result is the proof that the system works fine in a specific scenario. A test case is narrow (in the sense that it verifies only a specific part/function), to the point and repeatable. It is concrete, it improves confidence and it builds quality.

Top-down approach
When you test a bigger piece, it is often challenging to find out the boundary of the piece. As you explore, you tend to get a feeling that the bigger piece is expanding as you explore (and often never-ending as you come to know more about the system). It quickly gets out of control. The top-down approach (knowing the bigger system first and then decomposing it further, keep working on it until you come to a unit) is time-consuming and tedious to do in all situations (someone fixing a small bug needs to communicate why she has fixed that brick), and delaying the validation of a unit until bigger piece is built is ineffective.  The top-down approach should focus on the problem domain and wider aspects/functions much at a higher level.

Bottom-up Approach
This is not to say that top-down approach is wrong. Rather the top down is not sufficient or it is sufficient but fixing it when the system is developed fully is going to hurt the product in many ways (very likely). It needs to be complemented by the bottom-up approach. Write your "unit of code" and while you are writing your "unit of code", write your own tests. It is even better if someone writes unit test code for your unit of code. The top-down and bottom-up are two different perspectives of the same system (the first perspective is system has components and the second perspective is the components make the system)

What is a unit of code and unit testing?
This is a very vague term, often confusing and means different things to different people. We can consider a unit of code as "smallest possible amount of code that can be tested". You can call a function as the unit (like the ones that we are going to see tomorrow) but then the entire main() function where your application runs is too big to be called the unit of code. So, apply your mind when deciding how smaller or bigger is the unit of code.

A unit test is a scenario (setup, input, output, validation, cleanup, and reporting). Each unit test will have certain environment or conditions that are assumed to be present, input values, output returned, the validation that proves that the test is passed or failed, cleanup and finally last but not least reporting the success or failure.

When the unit test suites/cases can be run?
It is an absolute must that a developer writes unit tests before she writes production code. It is the test code that is to be written first and runs or at least while you are writing your code (writing test code after you commit your code is the biggest sin that you can do to your code). The idea is to break the software and keep fixing it. With that philosophy, it is a critical piece in software development. The unit tests have to be run successfully during the development stage (numerous stages and numerous times), before the code is committed, after the commit and nightly builds.

Why automated unit tests?
If you look at the above point, it stresses the importance of running them all the times. So, it becomes easier (and productive too) to write/automate once and run millions of times throughout the life of the product. So prefer automated unit tests over manual.

In the above analogy, unit tests are certainly examining each and every brick that they are good. The other forms are testing ensures that the joints between bricks are correct, the walls are correct, all the room comply with the requirements and overall the building is a masterpiece.

In the next post, we will start off with a simple example, learn the trades of unit testing and learn Python's built-in "unittest" module.


28 December 2017

Blogger, Feedburner Email Subscription Popup Widget


After a very long time, I got a chance to write some Javascript, jQuery, and some HTML stuff. I thought of updating my blog with a new subscription pop-up. The goal is to show a pop-up enabling the user to subscribe to my blog through email. While I have them already in a couple of places, I felt a pop-up at the center of the screen would help - to get some attention and action. Let us see how it goes.

I am sharing the code here. Feel free to use it if you are searching for something like this (but give the credits by not removing Widget by Lakshmi N).

Now coming to the widget. The following are the functionalities
  1. Display a pop-up with an option to subscribe or close the widget
  2. Integrate the pop-up with my feed provider (which is Google's Feedburner) so that I do not need to manage the subscriptions. It comes with a lot of security and  I can move to a different provider if there is a need.
  3. Make it less annoying. Use cookies and do not display the pop-up for another N days (by setting the expiry for cookie).
While I foresee some changes on the look and feel - but the core features are almost there. I have also committed the changes to GitHub.  There are few customizations that you might need depending on your requirements and taste. Here is how I have implemented
  1. HTML/CSS: If you turn on developer tools in your browser, you should see that the entire pop-up is written using HTML, CSS, and Javascript. I have used absolute positioning of the widget so that it shows up in the middle of the browser window. 
  2. Images: There are two images that I have used - one for the background for the pop-up and the close button. You can customize these too for your requirements in case if you need better images
  3. Display Timeout: Configure timeout duration after which you want the pop-up to be displayed. The display of the pop-up will be delayed for such duration after document.ready(). This should be lesser duration.
  4. Cookie Expiry Timeout: This is the duration after which the popup will again appear. This can be any precision (it can be from milliseconds to year). In order for this logic to kick-in, the user should have clicked "close". Ideally, this should be longer duration.
  5. JQuery: I have used JQuery, so ensure that you load jQuery in section and add/update document.ready(). I have used one already on my blog from Google CDN.
  6. Other Platforms: I have tested this on my blog (blogger) and not tested on other blogging platforms. But I believe it should work. Give it a try :-)
  7. Questions: If you have any questions or the stuff is not working, use the comments section to reach out to me. I try my best to support.
Here is my gist (If you remove the credits, it is mere copying and if you give credits it will be termed as normal usage. Be happy that I do not ask for money or bitcoins :-)).


27 December 2017

Want to GIT?

The entire programming world is moving towards using GIT as it is becoming a de-facto. If you have few hours during the holidays and want to learn how to work with GIT (or how GIT works), do not miss this course from Udacity. The course instructor has done a good job of putting together a nice course with a lot of materials and exercises (you can complete the course in two days budgeting some breaks for reflection)

Udacity Course Link - Version Control with Git

Points to be noted:
Note 1: You will learn only git (not GIT Hub or something that uses git to host your code). Nevertheless, this should be the first step before embarking further. GIT Hub (or something similar) should be logical next step
Note 2: Highly recommend for students who are still in college (writing code is good thing, writing tests for the code is better thing, managing your code is the best thing)
Note 3: Very highly recommend for professionals who have not explored GIT yet (learn now or will be made to learn it in 2018).
Note 4: Many text editors (like Atom) and IDEs (like PyCharm) support GIT/GIT Hub (super easy)
Note 5 (good that you have read thus far): Refer https://git-scm.com and learn why you should be learning GIT if you are a developer