Buy @ Amazon

Search This Blog

September 17, 2017

Rob Pike's 5 Rules of Programming

Rule 1: You can't tell where a program is going to spend its time. Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you've proven that's where the bottleneck is.

Rule 2: Measure. Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest.

Rule 3: Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don't get fancy. (Even if n does get big, use Rule 2 first.)

Rule 4: Fancy algorithms are buggier than simple ones, and they're much harder to implement. Use simple algorithms as well as simple data structures.

Rule 5: Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.

August 27, 2017

Android Activity's onDestroy() Ain't Your Reliable Friend

Look at the Android Activity life-cycle events in the picture beside.

The lifecycle isn't something new. You're familiar with it right? You're also that good Android developer that writes clean code, wherein you consciously override onDestroy() method to include resources clean-up code and save some state, right?

Per Android doc, it is okay and usually the practice to write cleanup code in this method but not anything beyond that.

So if you are to write code to persist state in this method, or anything else beyond resource clean-up (like threads associated with an activity), you're better off to push it up the life-cycle, either in onStop() or onPause() method.

That is how I settled in the first iteration of new learning but wasn't happy. Why? To quote Android Doc:

August 26, 2017

Android - Don't Keep Activities - Developer Options

"Don't Keep Activities" - are you aware of this must turn-on developer setting in your Android device?

Not sure about you. The first time I saw this in the developer setting, I laughed out wondering why on earth a developer would want to do this, assuming that this would hide the app performance issues.

I was so damn wrong. Contrary to my assumption, turning on this developer setting actually helps you identify performance issues. It helps you identify memory leaks of an activity.

Where do I find this? See picture attached.

How it works? When the developer option - Don't Keep Activities - is checked-on, in the device, all activities that are stopped will be destroyed almost immediately. It simulates the Android Operating System behaviour when your app is in the background and the system is short on memory; because of which it will destroy your background activities.

How is it useful? It is intended to help developers debug their apps for testing saved instance states and detecting memory leaks.

When to use it? Turn it on - always. If you find any unexpected behaviour of your app like freezes and force closures, it is a sign of bad code that requires fix.

1. Knowledge boost for junior Android developers — Part I
2. Don't keep activities - What is it for?

August 25, 2017

Notes On Android Notification

This post is my notes drawn from Official Android Docs and Android O: How to Use Notification Channels.

A notification is a message you display to the user outside of your apps UI.

When you tell the system to issue a notification, it first appears as an icon in the notification area like below:

To see the details of the notification, the user opens the notification drawer like below:

Both the notification area and the notification drawer are system-controlled areas that the user can view at any time.

August 21, 2017

Book Review - The Checklist Manifesto

It's a well written book shedding light on the importance of Checklists at work even if it is very critical with regards to time, cost, size of team/project etc. The author shares stories and anecdotes on how right kind of checklists can avert serious damages/mistakes.

I particularly like the way the author catches the attention of the reader in the beginning of the book. As the book gets to the later chapters, it gets dense in the domain that may or may not interest the reader.

I would recommend you get your copy from Amazon for cheaper price. Have fun reading it..