Posts

  • Refactoring 2nd Edition: Chapter 12: Dealing with Inheritance

    Refactoring: Improving the Design of Existing Code (2nd Edition) Cover Book cover copyright Martin Fowler

    Overview

    This chapter explains several methods that that allow you to refactor classes.

    My One Takeaway

    I love the concept of “Replace Type Code with Subclasses”. This has been an effective way to remove complexity because each subclass can handle it’s logic in it’s own set of functions.

    I hope everyone enjoyed the book!

  • What the F*ck Is With All the Artisan Commands

    Laravel Logo

    At work, we’re moving our application from Zend Framework to Laravel. I don’t have much experience with Laravel so I’ve been working my way through Laravel 5.7 From Scratch . I’ve been amazed at how easy it is to work with Laravel but I’m overwhelmed by Artisan’s list of available commands. My goal over the next several weeks is to look at each command and determine why it’s there and when the command should be used. Mostly due to my own self interested but hopefully others will find it helpful.

    Read More
  • Refactoring 2nd Edition: Chapter 11: Refactoring APIs

    Refactoring: Improving the Design of Existing Code (2nd Edition) Cover Book cover copyright Martin Fowler

    Overview

    This chapter explains several methods for refactoring functions and their parameters.

    My One Takeaway

    I felt like most of this chapter just clicked with me. I do love the “Remove Flag Argument” refactoring because I worked on a piece of software were it was used all the time and I constantly had to look up what the function was doing.

  • Finding All (or most) Commits to a Feature

    git Logo

    The other day my supervisor asked me an interesting question. He wanted to know how much time we spent developing a new feature. The feature was massive and we started working on it late last year and is just now about to come out of beta. There were a bunch of issues trying to figure this out: nobody was dedicated full time to it, it’s been worked on in fits and starts during that time, and we don’t currently track our time at this level of detail. It became an interesting thought process.

    Read More
  • Refactoring 2nd Edition: Chapter 10: Simplifying Conditional Logic

    Refactoring: Improving the Design of Existing Code (2nd Edition) Cover Book cover copyright Martin Fowler

    Overview

    This chapter explains several refactoring methods for simplifying conditional logic.

    My One Takeaway

    Another two takeaway chapter:

    1. Decompose Conditional is a huge win for me for readability
    2. “I often find I use Replace Nested Conditional with Guard Clauses when I’m working with a programmer who has been taught to have only one entry point and one exit point from a method. … Clarity is the key principal: If the method is clearer with one exit point, use one exit point; otherwise don’t.” I love “Clarity is the key principal” and it should be on every blackboard in every programming class ever.
  • Refactoring 2nd Edition: Chapter 9: Organizing Data

    Refactoring: Improving the Design of Existing Code (2nd Edition) Cover Book cover copyright Martin Fowler

    Overview

    This chapter explains several refactoring methods for moving code that accesses data around so it’s easier to work with

    My One Takeaway

    I’ve become a big fan of “Change Value to Reference” as I’ve worked with more complex integration tests. It’s made testing results a lot easier in some cases and has improved performance in others.

  • Using clearstatcache To Fix Unit Tests

    PHP Logo

    The other day I ran into an interesting problem. In one of our integration tests we did the following:

    $this->assertFalse(is_file($fullPath));
    
    $item->runProcessThatCreatesFileInADifferentProcess();
    
    $this->assertTrue(is_file($fullPath));

    The assertTrue() check always failed and everything we did showed that the file existed. In order to get around this we had to use PHP’s clearstatcache() function before the assertTrue() call.

    The reason for this can be seen in this section from https://www.php.net/manual/en/function.clearstatcache.php

    When you use stat(), lstat(), or any of the other functions listed in the affected functions list (below), PHP caches the information those functions return in order to provide faster performance. However, in certain cases, you may want to clear the cached information. For instance, if the same file is being checked multiple times within a single script, and that file is in danger of being removed or changed during that script’s operation, you may elect to clear the status cache. In these cases, you can use the clearstatcache() function to clear the information that PHP caches about a file.

    PHP was caching the result of is_file() and causing the assert to fail. To fix the tests we had to add the following call to clearstatcache().

    $this->assertFalse(is_file($fullPath));
    
    $item->runProcessThatCreatesFileInADifferentProcess();
    
    clearstatcache(false, $fullPath);
    $this->assertTrue(is_file($fullPath));
  • Link Post and Podcast Roundup: September 2019 Edition

    Link Post Logo

    September’s links.

    Read More
  • Refactoring 2nd Edition: Chapter 8: Moving Features

    Refactoring: Improving the Design of Existing Code (2nd Edition) Cover Book cover copyright Martin Fowler

    Overview

    This chapter explains several refactoring methods for moving code around and making it easier to clean them up.

    My One Takeaway

    Two this time:

    1. I love how much easier to read the “Replace Loop with Pipeline” refactoring makes the example. I think I’ll definitely be spending some time looking into how to do this with PHP.
    2. “Remove Dead Code” is my favorite refactor ever. In an earlier job, we had a functions.php that was included in every file and it had an if statement that could never resolve to true. Everyone was afraid of removing it for fear that it would break something. I wasn’t. :-)
  • Refactoring 2nd Edition: Chapter 7: Encapsulation

    Refactoring: Improving the Design of Existing Code (2nd Edition) Cover Book cover copyright Martin Fowler

    I fell off of this process really bad due to some family reasons but I’m going to start back on this process.

    Overview

    This chapter explains several refactoring methods that involve moving items into classes, out of classes, and into new classes.

    My One Takeaway

    I think these are all valuable refactorings to learn but I’m still not sure on how I’ll know to use them when I’m working. I guess I’ll just need to keep reviewing these. :-)

subscribe via RSS