Skip to main content

How to deal with difficult code

I have recently been working on a piece of very complex and very poorly designed code. It has been very difficult staying focused on the task at hand because I just can't keep everything going in my mind. I lose track of what path I was working on or how I got to a specific spot in the logic tree.

What can I do in this situation?

Unfortunately, I can't completely rewrite the entire section of code, even though it desperately needs it. Even if I was free to rewrite the entire piece of the system, I don't have a good enough understanding of it to be able to completely rewrite it without breaking it. I can, however, make changes to the code to make it easier to understand. I can accomplish this without changing any of the logic in the code. This will shrink down the amount of code I need to work with.

I can start by taking a piece of code and break it out into its own method. This new method will do nothing different than what it was previously doing. It will receive a name that will be descriptive of what it is doing. It will separate this code from the larger more complex whole. I can then better understand what this new method is doing while also making the larger method easier to understand and smaller.

I continue doing this, piece by piece until the original large function is broken down into many smaller functions. Every step along the way reduces the complexity of the original block of code and leaves me with a new method that I can understand more easily. I haven't changed anything about how the code works, but I have made it easier to understand.

When I find myself feeling frustrated trying to understand some new code, this is what I do. I stop trying to understand it. I break it apart and I turn it into smaller pieces that I can understand.

Comments

  1. Casinos Near Harris, PA - Mapyro
    Find 김포 출장샵 Casinos 양산 출장샵 Near Harris, PA in Pennsylvania near Harris, United States 경기도 출장마사지 and get 동해 출장안마 real reviews and 춘천 출장안마 ratings near Harrah's. Directions near me, PA.

    ReplyDelete

Post a Comment

Popular posts from this blog

Converting a Large AngularJS Application to TypeScript Part 1

I work on a project that uses AngularJS heavily. Recently we wondered if using a preprocesser like CoffeeScript or TypeScript for our JavaScript would be beneficial. If our team is going to switch languages, we would need to be able to convert existing code over without much pain and we would have to find enough value in switching that it would be worth the conversion. I had read an article that stated that because TypeScript is a SuperSet of JavaScript, you could convert a plain JavaScript file to TypeScript by changing the extension to .ts and not much else would need to change. I wanted to test out this claim, so I took a file that I was familiar with, an Angular Controller, and tried to convert it to TypeScript to see how much effort it would take and then try to figure out where we would benefit from using TypeScript. This is what the controller JavaScript file looked like to start out with: ( function () { 'use strict' ; angular .module( 'app'

Interns: Taking off the training wheels

My intern team has been working for several weeks now on our new website. We have already completed one deployment to production and are finalizing our second one. We started with a plan to release often adding small bits of functionality as we go and so far that plan has been working really well. We already feel like we have accomplished a lot because we have completed many of our project's requirements and should easily be able to complete the rest giving us time to do even more than just the original requirements. One of the things I have had some difficulty balancing has been how much to lead the interns and how much to let them figure out on their own. In deciding what our team process should be and how we should allocate our time, I think it was important for me to do more leading. I saw some deficiencies in how we were currently working and brought up some ideas for how we could address them. We had moved into spending all our time just working through stories and did not

My idea for Hearthstone to add more deck slots

Recently someone asked the Blizzard developers for more slots for decks in the game Hearthstone. The response was that they are talking about it and looking into it, but no decision has been made yet. One of the concerns over adding deck slots is that it could complicate the UI for Hearthstone and make it more difficult for new players to understand. I have what I think would be a good solution to add more deck slots without increasing the learning curve for the game much if at all. First I would take a look at the current selection screen for starting to play a game. It defaults to showing the decks that are custom built by the player if they have any custom decks, and there is an option to page over to the basic decks. This basic deck screen is perfect for how I would change this process. Instead of having 2 pages of decks, 1 for basic and 1 for custom, you would just see the select a Hero screen. Then once you selected the Hero you wanted, you would see all of the decks that