A while back I had blogged about my Morning Routine. The routine helps set the pace for the day and in getting things done that matters to me most. During mid of December 2016, I started running once a week to get some exercise into my routine. I got interested in running and soon was running thrice a week along with some free body exercises another three days. Since this was new and exciting naturally my concentration was more on getting these done. I struggled to keep up with my blogging schedule, failed to get a video out in the month of February and lost track of everything else (FSharp, Reading, etc.). Though I continued to wake up early in the morning, I could not get much done. I badly wanted to fix things up and here is what I have come up with

    TLDR;

    • One-week sprints and setting weekly goals
    • Break the Big Rocks (or MIT’s) into smaller tasks
    • Improve Focus using Pomodoro Technique
    • Daily Review and Weekly Review

    One Week Sprints

    The PSM course I attended in January made me realize the importance is sticking to a process. I decided to do weekly sprints for managing my personal work. I have a better estimate of how much I can get done with a shorter interval. I have blocked time on Sunday morning for my weekly planning and processing the ‘In-Basket.’ The In-Basket is where anything that comes up during the week goes. Todoist has an Inbox Project to which any uncategorized items go by default. I process the inbox and move them to various categories that I have setup in Todoist. Depending on the priority things make their way into the coming week or get set to ‘tentative’ dates and appropriate categories.

    Todoist Inbox

    Big Rocks are tasks that matter to you the most. Identifying them is important so that you do not miss out on them. The idea is to fill your time available over the week with the Big Rocks. The rest will find its way through, just like if you were to fill a bottle with stones first and then fill it with water, sand as opposed to the other way round. Big Rocks are the same as the Most Important Tasks (MIT’s) that we saw earlier.

    For me the biggest rock is family, and I have all of my evenings and weekends (rather any time they are awake, and I am home) blocked out for them. Over the past year, since I have written about my Morning Routine one of the MIT’s has changed. Blogging and FSharp still stay on, but I swapped in producing videos for Github contribution. Exercise is something I have set as a goal for 2017. To keep up with my exercise goal, I run three times a week and body weight exercises for another three days.

    Every day I have roughly three hours of ‘me time’ from morning 4 am - 7 am. Waking up was difficult for a while but then I realized it’s all about waking up to an alarm. The ‘me time’ acts as the bottle into which I have to fit the Big Rocks into (if you watched the video above). I need to optimize the things in the best way possible to fit it all in there.

    Pomodoro Sized Tasks

    The Pomodoro Technique is a time management technique that uses a timer to break down work into intervals, traditionally 25 minutes in length, separated by short breaks. These intervals are named Pomodoro.

    Many times in the past I have tried Pomodoro Technique on and off but was never able to stick with it. From my previous Morning Routine you can easily tell that I had a high-level plan on what my MIT’s are, but did not have any specific plans or goals on what to do about them. I also left room for flexibility to choose each day to pick up things randomly. Often it happened that I took more time to blog and got a bit of time for the other MIT’s. Though I have automated a lot of blogging activities, writing a post often took more time. And since I was not tracking this I was always happy that I achieved some of my MIT’s daily.

    Once I started running things changed drastically. I struggled to keep up the with everything and concentrated on just blogging. It was because I started losing focus and started getting the feeling that it’s too hard to fit in everything. I let this happen for over a month but was not very happy with it. Mid of February I sat down and dumped all my available time onto a paper and broke them up into Pomodoro sized intervals. So now I know how much time I have in a week for getting stuff done. I then broke down my big rocks s into smaller measurable pieces. For, e.g., with blogging, I have 4 Pomodoro of work - Creating a draft (high level), Refining the post body, Writing the introduction and conclusion and finally Adding in images, proofreading, and publishing. Similarly, I broke down publishing videos (happens throughout a month) and learning F#.

    Plans are nothing; Planning is everything

    I blocked out the time for running and exercise first, then I filled in with blogging tasks, followed by videos and then with FSharp learning. I also have a reading goal for 2017 and found that I can best do that during my commute to work. Though this is not a full sized pomodoro interval, I have this tracked. Weekly Planning and Daily Review are two other activities that I have started following religiously. I do my daily planning right after my Daily Scrum at work so that I get to capture anything work related as well.

    Pomodoro Plan

    I was surprised how easily I could fit all of these into the time I have. Since the task breakdown above is guesstimates, I have some buffer time in my plan so that I can accommodate tasks that take more time or urgent tasks that come up during the week or the laziness that kicks in at times.

    Increasing Focus and Removing Distractions

    Social Media and emails were one of the biggest distractions for me. Even though I try to reduce the amount of time I spent for these, I often ended up taking a glance at those sites now and then. It often ended distracting and taking me completely off course from the task. I decided to stick to checking personal email only once a day and work emails twice a day. As for social networks (especially Facebook), I decided to keep that to one as well. I wanted to track this as well and see how well I was with it. I use Loop Habit Tracker app on my phone for tracking these habits.

    Loop Habit Tracker

    For tracking pomodoro I use Tomighty, a simple Pomodoro tool. It just tracks the interval and does that thing well. The Pomodoro Technique lists down different techniques to manage interruptions and distractions. Managing interruptions is particularly useful when working out of an office and using pomodoro. During the short intervals, I usually take a walk around, fill water, stretch, etc.

    I have only been following this for three weeks. But I find this effective and hope to stick on with it for a longer time. I no longer have to spend time deciding what to do as that’s already decided. The only thing is to do it. Having taken the reasoning part of what to do out, I find doing things is easy and I procrastinate less. The important thing is sticking with the process and believing in it. I am sure this is going to pass as well, but for now I happy and it works for me. How do you keep yourself productive? Sound off in the comments

    Refactoring to Composite Pattern

    Composite Pattern is a useful technique to keep code maintainable and readable.

    I often come across functions that do multiple things. Many times such functions have a common pattern where multiple sections within the function use the same parameters for calculations. The results from these different code sections within the function are either separated by conditionals (if, switch, etc.) or combined using various arithmetic operators. The most obvious refactoring in such scenarios is to move the code sections into different functions within the same class. Having it in separate functions keeps the code readable. But on closer observation, such functions can be moved into different classes, keeping each of these code sections as the only responsibility.

    Identifying the Refactoring

    Within a function when a similar pattern of code repeats, it could be refactored into multiple classes and composed to give the same functionality. Let us take a simple example of a function where we are validating an Account object based on different criteria. The various criteria end up as conditionals within the function. This function can soon get big and difficult to manage. It also makes it harder to test. If you are adding more validations to this class over a period you are violating the Open-Closed Principle (OCP), the O in SOLID. Depending on the level of abstraction that we are looking at, the class also violates the Single Responsibility Principle(SRP), the S in SOLID. The function handles validations based on different criteria.

    public List<string> Validate(Account account)
    {
        var result = new List<string>();
    
        if (string.IsNullOrEmpty(account.Email))
            result.Add("No email");
        else if (!IsValidEmailFormat(account.Email))
            result.Add("Email not valid");
    
        if (account.BillingDetails == null)
            result.Add("Billing Details does not exists");
        
        ...
    
        return result;
    }

    The Composite Pattern

    Composite pattern is appropriate when the client ignores the difference between the composition of objects and individual objects. The pattern helps developers to maintain the complexity of the code and also separate out class responsibilities.

    Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly

    Composite Pattern

    Refactoring

    In the Account validation above, the function checks for an email and validates the format, checks for valid billing details, etc. The validations could also extend on to users attached to the account and check if there is at least one user, the user has email, phone number, etc. Each of these validations can be moved into separate classes and composed together in one class so that they are all executed when an account needs to be validated. You can see a tree like hierarchy forming here, and the actual validation is composed of all these validations

    Account Validation hierarchy

    The actual C# code looks like this after the refactoring.

    public interface IValidateAccount
    {
        IEnumerable<string> Validate(Account account);
    }
    
    public class AccountValidators : IValidateAccount
    {
        public readonly IEnumerable<IValidateAccount> Validators;
        public AccountValidators()
        {
            Validators = new List<IValidateAccount>()
            {
              new AccountHasEmailValidator(),
              new AccountEmailIsValidValidator(),
              new AccountHasBillingDetailsValidator()
              ... // Add more validators
            };
        }
        public IEnumerable<string> Validate(Account account)
        {
            return Validators.SelectMany(validator => validator.Validate(account));
        }
    }
    
    public class AccountHasEmailValidator : IValidateAccount
    {
        public IEnumerable<string> Validate(Account account)
        {
            if (account != null && string.IsNullOrEmpty(account.Email))
                yield return "No email";
        }
    }
    
    public class AccountEmailIsValidValidator : IValidateAccount
    {
        public IEnumerable<string> Validate(Account account)
        {
            if (account != null && account.Email != null && !IsValidEmail(account.Email))
                yield return "Email not valid";
        }
    }

    After the refactoring, we have separate classes for each of the validation rules. The AccountValidators class composes all the other validators and provides the same uniform interface for the consumers to validate an account. It calls on to all the Validators iteratively and invokes the Validate method on them. You can use Dependency Injection to inject in all validators to this class if you are not comfortable hard-wiring them. The IoC container can be setup using registration by convention, which prevents the needs for explicit registration for any new validators.

    One other worry that I have seen common when moving to such a pattern is that - We now have a lot more classes. Does that not affect the performance?. If you are following SOLID principles to the core and want to maintain loose coupling in your code then creating more classes is something you cannot avoid. We do not want any God Classes in our code and the first step towards it is to split them into different classes.

    If an Object Oriented language cannot handle the creation of many classes and objects then why should we be using it in the first place?

    -Big Object Graphs Up Front, Mark Seemann

    The composition can be complex conditions as in the case below. For, e.g., let’s say we need to execute a different kind of algorithm to calculate based on a property.

    public class AccountCalculator : ICalculate
    {
        public AccountCalculator(ICalculate calculate1, ICalculate calculate2, ICalculate calculate3)
        {
            ...
        }
    
        public int Calculate(Account account)
        {
            if(account.PropertyExists)
                return calculate1.Calculate();
            else
                  return calculate2.Calculate() + calculate3.Calculate();
        }
    }

    The above composition makes it easy to test the composed parts and the composition separately. It also helps keep the tests simple and easy to understand. The code is separated into maintainable classes and each criteria can be modified independently.

    Composite Pattern is a useful technique to keep code maintainable and readable. Identifying the pattern is a bit of a challenge, but the more you see it the more familiar you will be. Hope this helps!

    Posts on this blog are published automatically on preset dates. I have created a custom workflow for this in Octopress, my blogging framework. If you are interested in the end to end workflow check out my video on it. Publishing to different social media was also one of the things that I wanted to automate in the whole workflow. So whenever a post is published to my blog, it also posts to the different social media (Twitter, Facebook, and LinkedIn).

    Buffer is a tool to manage all your social media networks and publish content to it at one. It is a ‘Write Once, Publish Everywhere’ kind of service and works best for me. From the Buffer website or using browser extensions posts can be manually buffered. A buffered post can be published immediately, scheduled to be shared next or scheduled for a particular date and time. You can have custom messages for each of the social network that you are sharing.

    Buffer Share

    For automatic updates from my blog, I use Buffer via Email. With every buffer account, there is an associated email address. A post can be buffered by sending an email to this address in a specific format. So every time a new blog is published I send an email to my buffer account to publish immediately (@postnow). Automatic sharing posts also helps me reduce the time I spend on social networks; learning to disconnect

    I am on their Free plan at present. I have only less than ten posts scheduled at any point in time, and the plan provides all the features I need.

    Hope this helps you manage your social media content.

    Tip of the Week: AutoFixture - Make Your Unit Tests Robust

    AutoFixture is an open source library for .NET designed to minimize the 'Arrange' phase of your unit tests in order to maximize maintainability

    AutoFixture is an open source library for .NET designed to minimize the ‘Arrange’ phase of your unit tests in order to maximize maintainability. Its primary goal is to allow developers to focus on what is being tested rather than how to setup the test scenario, by making it easier to create object graphs containing test data.

    AutoFixture

    If you are on .NET platform and write tests (there is no reason you wouldn’t) you should check out AutoFixture. AutoFixture makes test data setup easy. It is a generalization of the Test Data Builder pattern and helps make your tests more robust and maintainable. Below is a sample (as taken from the GitHub page) shows how minimal setup is required for testing. Check out the post, Refactoring Test Code: Removing Constructor Dependency to see in detail how AutoFixture can be used to make the tests more stable against changes.

    [Theory, AutoData]
    public void IntroductoryTest(
        int expectedNumber, MyClass sut)
    {
        int result = sut.Echo(expectedNumber);
        Assert.Equal(expectedNumber, result);
    }

    If you are new to AutoFixture, I highly recommend checking out the Cheat Sheet to get started. Check out my post on Populating Data for Tests for some common patterns of using AutoFixture and how it can reduce setup code. Understanding the Internal Architecture of AutoFixture helps if you want to extend it for customization. AutoFixture integrates well with the different testing frameworks and support libraries that are popular. I mostly use it with xUnit and Moq.

    Hope this helps with your testing!

    I am happy to have contributed (minor) to such a great library.

    I came across the Google Indic Keyboard recently and now enjoy writing in my native language. If you want to write in an Indian language on your Android device, then this post is for you

    Google Indic Keyboard allows you to type messages, update on social networks or compose emails in your native language on your Android phone. At the time of writing the keyboard supports the following languages:

    • English keyboard
    • Assamese keyboard (অসমীয়া)
    • Bengali keyboard (বাংলা)
    • Gujarati keyboard (ગુજરાતી)
    • Hindi keyboard (हिंदी)
    • Kannada keyboard (ಕನ್ನಡ)
    • Malayalam keyboard (മലയാളം)
    • Marathi keyboard (मराठी)
    • Odia keyboard (ଓଡ଼ିଆ)
    • Punjabi keyboard (ਪੰਜਾਬੀ)
    • Tamil keyboard (தமிழ்)
    • Telugu keyboard (తెలుగు)

    Setting up the keyboard could be a bit confusing as changing keyboards is not something that we often do. I ended up spending some time walking through the setup for some of friends and family.

    Setting Up

    1. In Google Play Store search for [Google Indic Keyboard]. If you have not installed/updated before, tap on Install or Update to get the latest application version.

    Play Store

    1. Once installed go to any of the apps where you can open the keyboard. On the bottom right corner tap the icon to change the keyboard.

    Change Keyboard Icon

    1. From the window that pops up select “Choose Keyboards.”

    Choose Keyboards

    1. Enable Google Indic Keyboard (English and Indic Languages) listed in the list of available keyboards.

    Enable Google Indic Keyboard

    1. Repeat step 2 and open up the Change Keyboard window. Select Google Indic Keyboard from the list.

    Select Indic Keyboard

    1. The keyboard is now set as Google Indic Keyboard with its default language. To choose a language of your choice, select the Indian Language icon on top left.

    Google Indic Keyboard Default

    1. From the window that pops up select the language of your choice. For me, it’s Malayalam.

    Indic Keyboard Choose Language

    1. Google Indic Keyboard supports different layout.

      • Native Keyboard: Type directly in your native language.
      • Transliteration Mode: Get output in your native language by spelling out the pronunciation using English letters(For, e.g., Malayalam -> മലയാളം)
      • Handwriting mode (currently available for Hindi only) - Write directly on your phone screen.
      • Hinglish mode - If you choose “Hindi” as an input language, the English keyboard will suggest both English and Hinglish terms.

    Indic Keyboard Layout

    1. Type away in your native language :)

    Indic Keyboard Native Language

    The transliteration mode is impressive and intuitive. Its fits in perfectly with how I was earlier using my messaging apps; native language spelled out using English letters. The better thing now is that it automatically converts into my mother tongue. The Indic keyboard brings back the forgotten love to my language. Thank you, Google!.