Importance of Code Refactoring

By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you’ll find that it is easier to extend and maintain code.
—- Joshua Kerievsky, Refactoring to Patterns

I had recently seen the above quote while sifting through some periodicals that I read and it reminded of the importance of Code Refactoring. Refacotring is a mindset that you must put yourself into. You have to decide that you do not write perfect code the first time and that there may be some room for improvement. An hour or two a day may be all you need to review your own code.

I recently spent two hours reviewing code from one of my modules that I had written. It had the same or similar code written in 5 sections in the code and had the same purpose to these sections. Each section had 11 or more lines of code in it. I took one of those sections of code and converted it to a function and then replaced the 5 sections with this new function. Ultimately I had eliminated 51 lines of code out of one module.

Reasons for Refactoring Code
1. Consolidating and eliminating “Like” or “Similar” Code
2. Breaking out a extraordinary long function into more manageable bites
3. Make error trapping easier to handle
4. Make code more readable and maintainable
5. Removing nested IF or logic Loops
6. Make it easier to document
7. Create Reusable code
8. Better class and function cohesion.

The benefits now are the following:
1. Similar code is now the same which is the way it was meant to be ( coded over three days, the code morphed a bit ).
2. Since the code had the same purpose, it looks the same now and behaves the same.
3. Code is in one spot instead of 5 – makes it easier for a base change
4. Error trapping is much more controlled.

If you cannot review your own code ( some people cannot and should not be ashamed for it ), you should get yourself someone you can trust to review the code for you. The do not have to modify the code, they can either insert comments to you, print out and scribble on the pages or meet with you. Never take it as bad thing if someone wants to change your code; take it as a learning experience. If you are using someone else, challenge them back. Make sure they know what they are talking about. A face to face meeting is always a good idea. A mentor, or team lead should be taking on the role of code reviewer. Code reviewer should be recommending ways to refactor your code. This should be done prior to release, deployment and ending a project. The review should always be done with the developer(s) responsible for writing the code. Should never be done without as that undermines the developer(s) and no one learns anything from it.

New Project or Team Manager – First Two Weeks

There are plenty of tasks a person could do in their first two weeks as a new Project or Team Manager.  I have isolated some of the more important tasks that need to be addressed in the first two weeks of starting the new position.  Mind you these can vary depending on the size of team and the discussions with your new superior.

  1. Discuss your role and management styles with new superior.  Ensure you are both on the same page.
  2. Become intimate with company policies
  3. Get to know everyone on the team including their name, responsibilities
    and what they have done in the past
  4. Review all project descriptions and time lines
  5. Find out what each team member is currently working on and where they are in the time lines
  6. Compare where each team member is at on the time lines with the actual time line
  7. Discuss progress with My Boss
  8. Team Meeting
    • discuss priorities
    • discuss what everyone’s expectation is.
    • discuss what I expect of them
    •  ideas to get the projects back on track
    • look for team suggestions
  9. Discuss progress with my superior
  10. Meet with each member
    •  – discuss where they are in the project
    •  – together figure out how to advance in a more efficient way
    •  – set some realistic goals
  11. Discuss progress with my superior

The Art of Task Delegation

Delegation is a tough skill to master.  Many mangers have trouble delegating tasks to employees because they have trouble giving up control.   A good manager knows their strengths and the amount of work load they can handle without stressing.   A good manager also knows their employees strengths.  Use those strengths to your advantage.  Through the art of delegation, you can harness the skills you don’t have and reduce your stress by reducing your work load.  Delegation of tasks does not mean you are no longer responsible for the task, it only means that you are now managing.  You are still responsible for quality of the work done by the person you delegated the task to.  You still deserve credit for getting the work done, the only difference is you should be sharing the credit with the people who helped you.

Tips for Delegating Work

  • Know everyone’s strengths
  • Follow up with everyone who you delegated work to.   Ensure they are on task and the quality it to your desire.
  • Delegate tasks only to the people you trust.
  • Use a calendar.   Make sure you are following a schedule and that everyone knows the schedule.
  • Make sure everyone has the resources to get the job done. 
  • Provide your knowledge and share your experience.
  • Manage, manage, manage – this doesn’t mean you do the work. 
  • Share the glory, if you get praise, share the praise with those who helped.