Refactoring software

If you have done professional software development for some years then you know the value of refactoring. As time moves on, more and more
features are added to the software. The team learns a lot about the domain, problem at hand, broken assumptions and design mistakes. It is
natural that the team wants to correct the software with this new found knowledge. But most of the teams never do it. Sometimes there are valid
reasons for not doing it for eg

  • The software works and meets the user need. And the software has already matured enough. There will be no more active development.
  • The software contains lot of fixes with respect to issues from the field. If a refactoring is done then all this polishing will be lost.
  • There are no unit tests available for the software. So there is no way to check the refactoring for correctness.

But there are times when a refactoring is being avoided for the wrong set of reasons like

  • The product owner wants new feature over refactoring.
  • The team is lazy and considers the complexity as a pride.
  • There are no resources available to do refactoring.
  • Team wants to do a reengineering instead of refactoring.
  • The manager believes that refactoring is a waste of time.

From my own experience all these reasons can be avoided and refactoring can be done. Let me take one by one and see how we can get around.

Product owner wants new feature over refactoring

Refactoring will not provide anything new to the user. The user still provides the same set of inputs and the software responds back
in the same manner. So if we request the product owner to allocate time only for refactoring then we will never receive the time for it.
And the alternative is to take the entire new feature request and based on priority trade the least priority items for a refactoring. This way
product owner gets the new feature and the development team gets some part of the software cleaned up.

Team is lazy and considers the complexity as a pride

Most of the software development team starts with a clear and concise design. Over the time with the advent of new features and new team members
the design accumulates lot of incidental complexity. Instead of planning some time to identify and fix this situation, some teams tend to enjoy
this complexity. Smallest of the fix takes lot of time, new developers often find themselves lost in call stacks and no one can guarantee something
will work by design. If this situation is not properly handled then in the near future the whole software will need a reengineering. An expert
will always come up with an elegant and simple solution. So teams need to get out of their comfort zone and cleanup things then and there.

No resources available for refactoring

Most of the time finding resources to do refactoring is always hard. There are different solutions to this one and I have one solution that
always worked for me. Whenever I get a new team member as a replacement for some attrition I spend some time in training them. As a part of that
training I request them to refactor some part of the software. Yes new developers are crude, they lack the knowhow, they may complicate that
part etc., And one important fact is they have lot of energy and want to prove themselves. For me the refactoring succeeded most of the times using this technique. Give a try.

Team wants to do reengineering instead of refactoring

Most of the time if the topic of refactoring is started, some teams always want to throw the whole thing into bin and start a fresh. This may look
fascinating. But old code is not bad. It is not a rusting iron. Actually old code has accumulated lot of runtime knowledge. It contains lot of
small tweaks here and there with respect to customer feedback. So if a team is matured then it will always prefer to preserve the old code and
cleanup only those parts that are ugly.

Manager believes refactoring is a waste of time

In any industry the highest paid person’s opinion (HIPPO) has lot of value. So if you really want to do refactoring the manager has to be
convinced about the advantages and benefits. Here I have seen always show the benefit as something concrete. For eg number of saved man days,
amount of money saved, code/design metrics etc., Managers tend to believe hard facts and numbers over qualitative statements. This too has worked for me in the past.

So take that extra effort and cleanup the code.

-Ferose

Advertisements

Resurrecting my sisters Samsung galaxy captivate i897

It all started simple. My sister owns a Samsung galaxy captivate i897. It is a nice phone considering its release time line. It had good specifications, fast camera, good build and light weight. She was using it mainly as a phone and as a primary camera. Like every non tech person she never bothered to add an additional sd card and kept all her beloved photos within the built in phone memory.

Problem 1 – Broken screen

First problem started when she broke the screen by dropping it. Everything was functional but nothing on the screen. All the photos and memories are locked inside this device and after all possible tries I couldn’t get the photos out (usb debugging was turned off). So I decided to change the screen myself and ventured out to buy one from the market. Since this phone is from AT&T and we currently reside in Bangalore India, I couldn’t get the replacement screen. I finally bought it from USA through one of my friend. Thanks to youtube, I changed the screen myself. I took a backup of all the photos and as an additional step installed cyanogen mod 10.2. The phone did get a fresh air and started to look more like a modern phone. Everything was fine.

Problem 2 – Failed internal sdcard

Second problem showed up after some months. The phone refused to boot up now. I thought it was because of firmware corruption and tried to reinstall it. Again the phone always booted into recovery. Then I cleared up my mind and read the error message that the system showed patiently. I understood the internal sdcard has failed. Again I tried a lot and finally gave the mobile to service center. They mentioned it is a hardware failure and they won’t service it. I took that to the local cellphone repair service. They too mentioned that the phone cannot work without the internal sd card.
Now being an engineer one always try to solve a problem when everyone else says it’s impossible. After some thought I felt if I can switch the external sdcard and the internal sdcard at the software level then the system should be able to boot using the external sdcard. Now I am just going to list the solution and not the full story

  • The external sdcard should have the same partitions like the internal one or else the system refused to use it. So I partitioned the external sdcard into 2 partitions. 2gb & 6gb each of type vfat.
  • The custom firmware didn’t pick up this card as a replacement for the internal sdcard. But the stock firmware picked up this card for its /data partition and the phone booted up.

Problem 3 – The phone doesn’t have a sdcard

The phone was functional but if one tried to open any of the application that needs to store data, it would close with an error there is no sdcard. I checked the settings>storage and found the 2gb partition has been mounted but the 6gb partition was not. I again started a search and from my little linux background I know that the mounting can be changed by modifying the fstab file. But the fstab structure has changed a lot in the recent times and also I should have root privileges to change it. Again I am going to list down the solutions here and not the full story

  • I used to superoneclickroot from the xda forum and rooted the phone.
  • I used adb and downloaded the /etc/vold.fstab file.
  • I modified the mount point of the sdcard to the external sdcard partition.

Voila the phone works and also the sdcard was scanned during the bootup. I gave the phone back to my sister. The moral of the story is “If you build a system from open technologies then there are people with time and effort to fix the problem on their own”.

Pages that helped me
Get SuperOneClick from here
How the Mount SD Card Android Process works