Author: Rob Broadhead

  • Reasons To Avoid Code Generators

    Reasons To Avoid Code Generators

    When one goes looking for reasons to use code generators, the articles tend to skew positive. I guess most people need to be convinced that these are good tools. However, there is a dark side to code generators. Well, that may be a bit over-dramatic. However, there are reasons that a code generator should be avoided and definite drawbacks to using one. Allow me to make the case against these productivity tools.

    Ignorance By Abstraction

    The first problem we can look at is what I call ignorance by abstraction. This effect happens when we shield people from the underlying process for any task. For example, you look at your watch and read the time. You have no idea how it “knows” what time it is. You are ignorant of that functionality or process. Code generators often provide that abstraction. Yes, a developer can always review the source code. However, how often do you see that happening? There may be an initial deep dive into the generated code when the tool is evaluated. That is where it ends in most cases. You assess the tool and then trust it. Future developers may blindly use it and never even see the source code.

    Confusing Custom With Standard

    Frameworks also suffer from this weakness, but code generators hide it better. This situation occurs when a developer gets so used to how a tool helps, they think it is part of the environment. There are many developer tools that fall into this category. The result can be great for productivity but can also end with tool lock-in or limit career moves. I have come across developers that end up stuck in a job because they are so reliant on the tools that the company provides. That may seem like a win for the company, but it can scare away better talent. These environments also deter those that want to focus on learning a language or environment. Instead, your team is just learning tool usage.

    Performance And Maintenance Woes

    An often overlooked weakness in code generators (and frameworks) is how they provide a general solution. In some cases, this just leads to unused code. On the other hand, it can lead to slow code that is difficult to maintain. It can be frustrating and time-consuming to sort through excess code while debugging. There also are performance issues that often arise. The best way to build a code generator that allows for extensible code is through abstraction. However, those abstraction layers take time to process during runtime. That can cause performance issues that cannot be overcome. The generated code provides a baseline that cannot be moved without removing the tool. When you hit those sorts of walls, you will hear a lot of wailing and gnashing of teeth.

    Regeneration Nightmares

    I worked on code generators early in my career for a tool called Power Builder. We ended up often having more layers on top of the primary tool than it supported. We ended up spending hours each week in generation and regeneration and compiling cycles. I lost track of how many hours were spent in non-productive waiting for a system process to complete. This was not uncommon in those days of application compiles that often took dozens of minutes or more. Nevertheless, we had to be aware of what might be over-written in our code during a regeneration process. Likewise, there are side effects we might have on the same. I am not sure the resulting time savings were worth it.

    Scalability and Extension

    That leads to another weakness code generators can run into. They do not always scale. I have run into this often with RDBMS object mapping generators. The tools have an approach that makes assumptions that make sense until you get to large or complex solutions. The problems may occur as name collisions, objects with too many properties, tables with too many columns, or overhead that buries the system. Consider what audit information adds when you scale it to large and complex systems. Do you really need audit information for every data lookup item?

    While some solutions and generators provide configuration or customization, that can also be expensive in both time and performance. There is a chance that an update of the tool or even a new code generation will break custom code. Those changes may also fall outside of the patterns the code generator uses and have a negative impact on application performance. Think of it as the tool plotting a specific course through the generated code. Then, the customization tries to change the course. There is a form of working against yourself that occurs in those situations that can cause maintenance and performance degradation.

  • The Shortest Path To Solve A Problem

    The Shortest Path To Solve A Problem

    Velocity and speed come in two ways. You can increase power, or you can reduce drag. We can find ways to address both of these aspects to solve a problem faster. Some of these may be obvious. However, I often find many to be overlooked regularly. That may come from rushing through the process or even institutional and cultural limits.

    More Than One Way To Solve A Problem

    Most problems have multiple solutions. Likewise, some are going to be better than others. Therefore, do not let perfect be the enemy of good. The first solution is at least a solution. That is more than you started with. That may be all that is needed. A better solution may be the goal—however, version 1.0 of a solution is better than nothing at all. There is also the option to build on that first solution. When you keep going back to the drawing board, you limit what you start with. Sometimes getting close to a solution provides a foundation or watershed moment. When that happens, you can start the next effort closer to the end. It is like climbing a mountain in stages instead of one herculean effort.

    Remove Drag

    We can start by removing drag on our problem-solving approach. However, let’s first think about what drag is. It is anything that causes friction or otherwise slows down an object or process. That includes things that may take the progress off course. For example, a river may re-route itself if something causes enough drag. Likewise, your GPS may re-route you if there is too much friction in the form of a traffic jam or accident. Now indirect progress may not exactly be a drag, but it works for our purposes.

    The biggest drag I have found in all my years of work to solve a problem (big or small) is misdirection. That may come in the form of going down the wrong path or even solving the wrong problem. The simplest example of this is trial-and-error. Every error (wrong path) slows your speed to a solution. The sooner you get on the right path, the quicker the problem is solved. That brings us to our first key point.

    Ensure You Have The Correct Problem

    That may appear to be an obvious starting point. Nevertheless, it is a common mistake. Humans are known for confusing cause and effect. Likewise, we all have moments of focusing on the wrong aspect of a situation missing the root cause. We sometimes even solve a problem that does not exist. We assume trends where there are none. Start your process by stepping back and examining how the problem arose or manifested. It is easy to get off track and lose a lot of time chasing after requirements that are not needed. When possible, ensure you can reproduce the problem/error. Then, verify the solution actually addresses it.

    A tangent struggle to this is assigning blame. There are many times blae is chased down first. However, that does not solve the problem in most cases. Therefore, work on the problem first, then worry about heads rolling. Reviewing why a problem occurs or occurred can have limited use. Rather than focus on what happened, keep the focus on how to avoid it in the future.

    Fail Fast Fallacy

    The idea of failing fast is popular among some circles. That often is used as a way to remove analysis and push to try things out. Yes, trial-and-error can be useful. However, random is not as good as a focused approach. We have to find a balance between quickly verifying potential options and overthinking their value. We are not going to increase velocity to solve a problem by quickly removing options unless they were valid in the first place. Each successive failure should be methodically moving us toward the solution. Thus, we can think of it as a mortar fire walking in the charges to the target. There will be attempts that take us away from a solution, but that means we go back and try another direction.

    The Single Step

    The is an old saying that a journey of a thousand miles starts with a single step. That is true every step of the way. We can think about a problem and discuss it, and even rehash it. However, we are not going to make progress on a solution until we start work on that. There is a time to think and time to act. Make sure you understand what time it is and you will get to that solution faster. You might even reach it faster than you thought.

  • Building a Code Review Culture

    Building a Code Review Culture

    I was recently in a conversation about software development and asked about my thoughts on doing a code review. The assumption was that a code review is a good thing. However, there was a question as to how they can be done properly. It may sound like a cliche, but that is an excellent question. There are billions of lines of code written each year, from scripts to full-featured languages. We need to be aware of how to write and produce better code. The review process helps us do that.

    What Is A Code Review?

    We should start with the goals of this practice. Of course, companies vary in their official objectives. Nevertheless, code reviews almost always have the same list of goals.

    • Reduce bugs
    • Improve Quality
    • Verify Adherence to Standards
    • Cross-training/Leverage Expertise

    There are nuances and details to each of these items. However, a process that addresses these is off to an excellent start. We should not do anything simply to be busy or conform to a norm. We want to have concrete value in our work, and the above items give us that.

    Developer peers typically do a code review. There can be any number of participants, and it may be direct and in-person or performed off-line. There are tools to assist in a review, or “paper and pencil” approaches might be used. The highest level description of a code review is a person (or persons) walking through source code with an eye for improvement or errors. We can look to the above objectives to help us flesh out this process to make it more effective.

    Reduce Bugs

    It is frustrating to developers, but many bugs are easy to detect. There are typos and simple logic flaws we miss while cranking out code. The second set of eyes can often help us quickly spot these issues and address them. A code review that aims to assess logic and scan for inconstancies can help us squash bugs sooner and faster. This is not a process without cost. It takes an investment of time to review code and provide feedback. However, it is worth the effort. We gain in quality but also productivity as we work together to implement solutions that are peer-reviewed. The things I am most attuned to are not the same as your experience. That means a few minutes of your time may easily determine bugs that take me hours to track down. Minutes for hours is always a worthwhile trade.

    Improve Quality

    Quality and bugs are related but not the same. You can write low-quality code that is bug-free. Yes, I mean that. There is a lot that goes into quality. It has to be correct, maintainable, scalable, stable, and more. A code review helps bring the team to the same page. The programming standards can be reviewed and feedback given on specific code rather than just functionality. That leads to better developers, tighter code, and a consistent style throughout the application that makes it much easier to maintain. You get a reward today and in the future for going through this process.

    Adherence To Standards

    Every organization needs a standards cop. There is value in everyone on the team rowing in the same direction. This objective is partially addressed by standards. While there are automation tools that enforce these rules, not everything can be reduced to a rule. The code review process allows the team to go over processes and standards with an eye towards to enforcing and improving them. It is easy to take a short cut in a rush to solve a problem or forget to “clean up” a quick code snippet. That is where this process comes in. The author has someone to follow behind and provide accountability for the work before it is committed up the chain.

    Cross Training

    Another benefit of going through this effort is cross-training. Team members are at least exposed to areas they may otherwise never see. There is always a cost to cross-training in terms of time. However, a code review adds value immediately while still moving forward the breadth of experience in the team. Members that are completely ignorant of a section of the solution can gain insight and even familiarity through this process. They not only see code, they are brought into the discussion as features are created, bugs found, and decisions made. They also have a context to work with in terms of code that has been reviewed in the past.

    A Worthy Investment

    My goal through all of this is to show that there is value in doing code reviews. However, it is not something you can magically start and immediately do fully. There is an art to being able to walk through code and provide insight. That takes time and experience. Therefore, the best time to start this process was last year, but the second best time is now. Get out there and bring the team into your coding.