10 January 2018

Get, Set, GOLANG

[Reading Time: 3 to 5 minutes]

[Edited] Reposting this as i have decided to change the book.

Looks like programming languages are sweeping the internet today. Ever since the programming languages were introduced, the pace of new languages was rising gradually. Today, we are seeing a higher pace of several new and promising languages. Python and Go seem to take up cloud software development quite strongly. Python has been around for a lot of time. Go seems to pick up - offering ease of development comparable to languages like Python and giving a speed of execution of that of C/C++. From now and for next few months, I have to ride two horses - learning both Python and Go. I have to admit that I cannot put off my temptation (which I kept off for last three months).

Go in Action by William Kennedy
Go in Action by William Kennedy
and Others
Similar to Python, my goal is to become fluent in Go. I am not sure of the timeline but I do see a compelling need to be good in Go in near future. I would like to take up this self-learning of Go by reading books and trying out exercises in GitHub. Having decided to learn Go, I was searching the internet for where to start. There are several good books out there. Go in Action is one among them which was highly recommended in a couple of forums. Being decent sized book (not too small or not too big) and based on my first impression after reading the table of contents, I feel that it would provide a good start in my journey.

It consists of 9 chapters (270 pages). The chapters are said to be designed in such a way that an intermediate programmer can get best out of it (the audience the folks with some programming experience but new to Go, so no boring stuff). This is a quite a promise to keep up. I am excited to ride two horses.

Let us see how it goes. I am excited to learn Go and share my reading journal with you on Go :-)

There is another language that is creating so much noise - Rust. Check it out. If you are a C guy, you have to watch out Rust (hoping that I will not jump the gun in learning Rust)

Note 1: You will see "Reading Time" in all my posts. I want to alert you how much time you are likely to invest reading my posts so that you can decide when and whether to read the post.
Note 2: My goal is to keep it short and give you links in every page to read posts relevant each post

[Update after reading first chapter and reading the second chapter after half way through]
Looks to me that Go In Action has taken the learning in a different perspective and I am certainly feeling little tired to get past each sections. Somehow, I feel this should not be my first book on Go and I am going to switch to another book - which probably offers step by step in small increments.

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.


07 January 2018

"Learning Python by Mark Lutz" - Reading Journal 6 [Chapter 10, Chapter 11 and Chapter 12]

Learning Python by Mark Lutz Fifth Edition
Learning Python by Mark Lutz
Like me, if you are new to Python and want to ramp-up to become no non-sense developer in Python, you might want to read these posts (and if you are prepared to take up the tough path of mastering the language). The post like this is my experience - the journey that is little longer but interesting, thought-provoking and rewarding. 

For next few months, I would be posting my experiences with Python more specifically the learning I am going through from the book - "Learning Python by Mark Lutz". You can find all of my reading journal of this book.

The rest of this post covers what I learned in Chapter 10, Chapter 11 and Chapter 12.

Chapter 10: Introducing Python Statements
This chapter is fairly easy to read. By now you should have written some code with statements which should make this chapter even more easier. But an important take away is "why Python is Pythonic" with to respect statements, code blocks, and indentation. Towards the end, we also see few nice and quick examples.

Chapter 11: Assignments, Expressions, and Prints
This is another great chapter that covers assignments, expressions, and prints in great detail. It details various ways of assignments, sequence unpacking, sequence assignments and augmented assignments. Variable naming rules, conventions, and expression statements are discussed too. Towards the end, there is a good section on prints and various ways of printing covering both 2.x, 3.x, and printing in version neutral way. Another great chapter.

Chapter 12: if Tests and Syntax Rules
This chapter gives an in-depth treatment of if constructs & its optional extension (elif, else) giving examples of nested and deeply nested if constructs, multiway branching. The most valuable content is the discussion on indentation and philosophy of Python with respect to code readability in the light of software maintenance. Truth values, boolean tests and if/else ternary operations are discussed. I suggest to stop here for a while and then try out examples so that the concepts are understood well.

All posts related to "Learning Python by Mark Lutz"

Friendly Note: I am posting the images and links from the publisher's website. I am not an affiliate and I do not get paid for writing this. If my journal is useful for someone to learn Python, I am more than happy :-)

05 January 2018

"Learning Python by Mark Lutz" - Reading Journal 5 [Chapter 8 and Chapter 9]

Learning Python by Mark Lutz Fifth Edition
Learning Python by Mark Lutz
Like me, if you are new to Python and want to ramp-up to become no non-sense developer in Python, you might want to read these posts (and if you are prepared to take up the tough path of mastering the language). The post like this is my experience - the journey that is little longer but interesting, thought-provoking and rewarding. 

For next few months, I would be posting my experiences with Python more specifically the learning I am going through from the book - "Learning Python by Mark Lutz". You can find all of my reading journal of this book.

The rest of this post covers what I learned in Chapter 8 and Chapter 9.

Chapter 8: List and Dictionaries
This chapter has given a lot of information in lists and directories. The key thing is that each operation is shown with examples. If you have gone through the chapter on "string", the list should be similar and you can just zip it through. The operations such as create, modify, slice, sequencing, iteration, comprehension and in place modification with loads of examples. Once you are through this chapter, you will understand (and relate to) if someone says you need not memorize things in Python. It was a very good read.

Chapter 9: Tuples, Files, and Everything Else
This chapter gives a nice exposition on tuples, named tuples, files and overview/summary of types that are discussed so far. At this point in time, I have to admit that Python is becoming easier to comprehend. Since we have seen lists/dictionary already, tuples and named tuples are similar except that they are immutable. With respect to files, I learned how to read, write, seek and flush the buffers, iterate over lines, opening them in the binary mode which turns off encoding/decoding Unicode, introduction to pickle, JSON & struct and file context manager. The chapter closes with a lengthy overview of types giving us a treat.

With this, I have completed Part 2 of the book roughly 20% of the book. Still, I have 80% to cover but it is exciting :-). Overall, my impression is - part 2 is deeper and insightful than part1 (with no offense meant to part1)

All posts related to "Learning Python by Mark Lutz"

Friendly Note: I am posting the images and links from the publisher's website. I am not an affiliate and I do not get paid for writing this. If my journal is useful for someone to learn Python, I am more than happy :-)

04 January 2018

"Learning Python by Mark Lutz" - Reading Journal 4 [Chapter 6 and Chapter 7]

Learning Python by Mark Lutz Fifth Edition
Learning Python by Mark Lutz
Like me, if you are new to Python and want to ramp-up to become no non-sense developer in Python, you might want to read these posts (and if you are prepared to take up the tough path of mastering the language). The post like this is my experience - the journey that is little longer but interesting, thought-provoking and rewarding. 

For next few months, I would be posting my experiences with Python more specifically the learning I am going through from the book - "Learning Python by Mark Lutz". You can find all of my reading journal of this book.

The rest of this post covers what I learned in Chapter 6 and Chapter 7.

Chapter 6: The Dynamic Typing Interlude
This chapter provides an excellent coverage of dynamic types, objects, variables and a picture on how the objects are created in memory. Dynamic typing - how Python detects the type (or rather where it stores the type of the object), the significance of variable names, object reference counts and where the variable names are stored are discussed. A brief walkthrough on automatic reclaim of memory (aka Garbage Collection) and GC in the context of shared references, shared references and In-place changes and shared references and equality are discussed. If you are from the language like Java, you should be knowing most of the concepts already. Overall a nice theoretical view of PVM memory and object space. Nice and neat chapter

Chapter 7: String Fundamentals
If you like strings and string manipulation - I bet you will like this chapter. What appears as simple (when we do no know) becomes quite overwhleming when we go deeper. This chapter is written in such a way that it never overwhelms with a lot of friendly advices. Do not miss this chapter if you are a fan of strings. Let us come what I learned. String, why string is a sequence, string liternals, escape sequences, raw strings, unicode representation, how to express strings (three different ways), indexing, slicing, extended slicing, conversion, changing strings, immutablity, string methods, string module (which you should be using), formatting expressions. After reading the chapter, I feel that this is one of the chapters that I should read few times. I am sure that strings will take some time to master. Overall, the chapter is nice, informative. Kudos to the author again.

All posts related to "Learning Python by Mark Lutz"

Friendly Note: I am posting the images and links from the publisher's website. I am not an affiliate and I do not get paid for writing this. If my journal is useful for someone to learn Python, I am more than happy :-)

02 January 2018

Python Tricks -

I came across a good website on Python tricks - https://dbader.org/python-tricks. I recommend you to subscribe to Dan Bader's Improve your Python skills. 

Dan is also providing videos and tutorials in Python

Relatively an easier post in Python. I am sure that this is going to be much more useful to you than what I write on my own :-)

Tomorrow, I am going to post on unit testing, a function to find prime number and test code using Python's unittest

01 January 2018

"Learning Python by Mark Lutz" - Reading Journal 3 [Chapter 4 and Chapter 5]

Learning Python by Mark Lutz Fifth Edition
Learning Python by Mark Lutz
Like me, if you are new to Python and want to ramp-up to become no non-sense developer in Python, you might want to read these posts (and if you are prepared to take up the tough path of mastering the language). The post like this is my experience - the journey that is little longer but interesting, thought-provoking and rewarding. 

For next few months, I would be posting my experiences with Python more specifically the learning I am going through from the book - "Learning Python by Mark Lutz". You can find all of my reading journal of this book

The rest of this post covers what I learned in Chapter 4 and Chapter 5.

Chapter 4: Introducing Python Object Types
As the chapter title says, this chapter introduces core data types that are built-in to Python - Numeric, String, Lists, Dictionaries. It also gives an overview of Files, Set, and user-defined classes. It talks about sequences, mappings, and sets. How to iterate over collections and access mappings/dictionaries. What are type-specific functions available. On files, a simple read/write with encoding/decoding is discussed at a higher level. At the end of this chapter, you will realize that everything is object in Python (and dynamic/strick typing system). It was very interesting to read. On the downside, I am still curious as to when I will write some code. I do not see coding exercises/puzzles at the end of the chapter yet.

Chapter 5: Numeric Types
What we think as just integers and floats are mind-boggling when we try to go little deeper. This chapter is no exception especially when you have two versions of Python (2.x and 3.x) behave little differently. I am pretty sure that numeric types and differences in two major versions of Python are going to be little tough to remember and one has to keep referring the material until it becomes second nature. Let us come to the learning.

This chapter covers numeric types - integers, floats, decimal, fraction, complex numbers, operators, building expressions, precedence, bitwise operators, comprehension, sets, booleans, evaluation of tests, chained tests, representing numbers in other bases (hex, octal and binary) and finally some introduction on number crunching with popular modules. I strongly suggest practicing while you read to get the feel of what the author says. The chapter was longer with so many details but never boring though. Truly great stuff.

All posts related to "Learning Python by Mark Lutz"

Friendly Note: I am posting the images and links from the publisher's website. I am not an affiliate and I do not get paid for writing this. If my journal is useful for someone to learn Python, I am more than happy :-)