Thursday, June 17, 2021

REFACTORING

 What is Refactoring?

A software is built initially to serve a purpose, or address a need. But there is always a need for enhancement, fixing problems, add a new feature, or enhancing/ modify an existing one.

Periodic changes to the code are made by a plethora of developers of varied experience and coding styles. Hence, over a period of time, the code becomes increasingly complex, adding to its performance and overall maintainability.

To combat this, it's essential to refactor the code periodically to avoid the above-mentioned problems.

Refactoring ensures the quality of the code by restructuring the code without changing the overall behavior.

When to Refactor?

Ideally, refactoring should be a part of the project plan on a periodic basis. It should also be a part of regular programming.
When you have a task of making some fix/ enhancement to the code base, look at the existing code and analyze its readability. If the developer thinks the code is not readable enough to make a straightforward change, take some time to refactor it first. Many times you would already find some code to re-use which is hidden inside some bigger method. Once you refactor them, the job looks simpler.

Then make the required change. 
 
You would notice that it would be a lot faster and less prone to errors/ bugs. 
After a couple of weeks, return to the method and see if it is still readable or needs refactoring again. Chances are, you will find scope for improvement. 
If you visit the same code again after a few weeks, there will still be scope for improvement. 
It's just how the coding works.

Benefits of Refactoring:

1. Improves Understanding and Readability

Translating someones else can be time-consuming and overwhelming. Periodic refactoring improves the design of the software and makes the bigger picture clear. It makes the code easier to understand, and eventually, the software gets cleaned up, for yourself and for other developers who would work on it in the future.

2. Improves development time

Sometimes, it takes several hours just to understand and get the gist of the functionality of a code written by someone else. A well-refactored code is easier to understand and cuts down a lot of development time and reduces regression bugs.

It's easier to write unit test cases for a well-refactored code.

3. Maintainability

Refactoring helps in finding bugs and program faster. It keeps the code clean and organized. A well-refactored code is easier to maintain in the long run.

Automated tools for refactoring

Most IDEs like eclipse/ IntelliJ already have inbuilt plugins that automate the refactoring process. However, it is not mandatory to use them. It is perfectly possible and okay to refactor manually. Just make smaller changes and test frequently to avoid errors. Unit test cases can come in handy too while refactoring. So consider writing as many unit tests to validate your changes.

Conclusion

I have often noticed teams struggling to write unit test cases just to get a good coverage percentage on various quality tools (Sonar, Jacoco, etc.). More often than not, these are mandated by stakeholders to quantify the quality of the source code. But these numbers can be highly misleading, meant only to showcase to the upper management and make pretty ppts.
Periodic refactoring is actually what will get you there. Making enhancements will take a lot less time and it will improve the code quality over a period of time. So it is important, we allocate time to this as part of your regular programming tasks.

Sunday, January 31, 2021

COVID AND FEMINISM

Over the new year, we had some of my husband's (Db) college friends visit us over. So we were 5 couples with 7 kids between us.

While I was done preparing tea, Db came to the kitchen to collect the teacups and help me set up the snacks on the table. 

"Oh Wow! Db is so amazing! He helps you in the kitchen!!!"

"Not as much as I would like, he doesn't cook," I said.

All of them exchanged glances and laughed. "Do you expect him to cook or what???"

Another said, "I would be glad if mine did a fraction of what Db does".


And all of these are educated women. 4 out of 5 of them are either currently working or were professionals at some point in their life. And I am appalled at how easily they believed that I was lucky and Db is being so nice by helping me in the kitchen. 

Now it's the covid lockdown, and we have two sets of jobs, one young toddler, and all household chores without any domestic help. And to my deep chagrin, the household work is very unfairly divided between us at 1:3 ratio. While Db openly accepts that this is an unfair distribution of labor, he also believes that he is a lot better than other men because the bar is already so low for men that doing 25% of household work automatically brings him to the "very nice guy" category.

I call Bullshit!!!

While women are seeking equal opportunities at work, men are still considered "nice" if they get their own cup of tea. And, the saddest part is, women believe so too...then how do we expect men to believe that household work is not just a women's territory. 

At work, many times we come up and volunteer to take tasks because maybe it's a good opportunity to learn something new, to get into limelight, and sometimes because we feel that the rest of the team is already loaded. Why doesn't it apply at home, for domestic chores? Why can't men just come up and say "I wanna help!", the same way you would do at work.


The answer to that is simple.

In my opinion, its nothing to do with gender inequality and everything to do with what you can get away with. 

It also often happens with in-laws, where the mother-in-law would expect the daughter-in-law to take up most of the heavy lifting. Happens at work, where some members of the team always try to push work to the hard-working ones until someone up on the ladder notices and questions him.

If there is something that is accepted or not questioned, it would never change.


And to make matters worse, we as women think so little of ourselves and so highly of our male counterparts. Patriarchy is deeprooted into our bones.

At the risk of having an unpopular view, the most educated and feminist women would go hungry on Karwa Chauth for the long life of our husbands. We celebrate Raksha Bandhan to ask our brothers to protect us or do a Teej to find a perfect husband in the future. All of these and more are done only by women for the benefit of their male counterparts. Have we ever had male equivalents of these beliefs? Aren't these blazing examples of patriarchy in the Indian culture we are so proud of.

I know quite some men who are feminists themselves. Db is also one of them. But believing in feminism as an onlooker and actually practicing it in real life are two different things. It's easier when the domestic work is outsourced to helps, but when it means that you actually have to pick up that broom and get your ass moving...then we are not feeling as feminist, are we now!!! 

Men don't want to change because it clearly works for them and women don't because they accept it as 'That's how it's always been'.



REFACTORING

 What is Refactoring? A software is built initially to serve a purpose, or address a need. But there is always a need for enhancement, fixin...