Coding for the Future

I posted a note on Twitter about some code. In this case, it was the start of a for loop, but with two things in it that I didn’t like. The code is shown here:

for ($i = 2011; $i <= 2021; $i++) {

Both the starting point and the ending condition were problematic for me. This code is used in a scheduling application, to populate a dropdown that I used regularly. It’s always worked, since about 2017 or 2018, and I had no reason to even think about the algorithm. I assumed the code was something like this:

for ($i = 2011; $i <= year(); $i++) {

In fact, when I had issues on 27 Dec, I assumed that things were coded to the current year and I’d be able to schedule things on Sunday night when I got home. Instead, things still didn’t work the first few days of 2022 and I had to get someone to come in from holiday to fix the code. Now it looks back a few years (likely unnecessary) and looks forward one year, as it should.

I don’t know why a developer would bother coding anything like this. Get the need to perhaps test something expediently and limit choices, but hard-coding most anything is a poor idea. There ought to be some logic in how or why you choose values, and that logic often can be expressed in code that adapts to situations. I certainly could have lived with only the current year being available, though that still doesn’t think through the problem space well.

I’ve seen lots of simple bugs in code over the years that are similar to this one. These often occur because the developers haven’t thought through how code might need to adapt to slightly changing situations. Something like a change in the year, or maybe the addition of a time slot for scheduling or a new location added, even a new tax rate. Often I find developers think they have considered the problem given to them, but a little too tightly. They haven’t thought about how their code might change if the user requesting the feature has made a mistake.

Writing code that solves a problem and allows for adaptation to likely scenarios is a bit of an art. It can be hard to do, but great developers assume users will need some changes and plan for this in their solution. They also assume users make mistakes in their specifications and they don’t hard code anything.

Steve Jones

 

Listen to the podcast at Libsyn, Stitcher, Spotify, or iTunes.

Posted in Editorial | Tagged | 4 Comments

Daily Coping 12 Jan 2022

I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag.

Today’s tip is to write a short list of 3 things you feel grateful for and why.

My list:

  • Health
  • Finances
  • Kids

Not the top list, and certainly I am grateful for my wife and my own kids, but these are additional items.

Health

I’ve been relatively healthy for most of my life. While I have bad knees and ankles, some joint issues, most of these are minor and impede my ability to be athletic, but don’t prevent it. I’ve rarely been sick. I’ve had COVID and I had the flu one other time. I get colds every 2-3 years, but for the most part, I don’t have any chronic issues.

I got some worrisome numbers at my last checkup. Nothing too bad, but for someone that mostly gets a clean bill of health, I need to change a few things as I age. I’m “pre” a few things, so I’m working to get better, but that has helped me appreciate how blessed I am, even as I need to pay more attention.

Finances

I’ve had a good career, with jobs that paid well. Nothing amazing, but I have been well compensated for most of the last 30 years. I also built and sold a business, which didn’t let me retire, but it made life comfortable for my wife and me. My wife also had a great job and provided more support for the family than I did for a long time.

We’ve invested in real estate, had good success, saved some money from corporate 401k plans, and we are in a great position. While we aren’t able to retire in our 50s, and college for kids is a bit of a strain, we are in a better position than most people in the world, and I’m grateful for the security and peace of mind that brings.

Kids

I have three adult kids, and I enjoyed watching them grow up. I enjoyed being a part of their activities, their successes, and their struggles. I am very proud of where they are in the world.

However, I miss the time I used to get with kids, watching them learn and grow. Fortunately, I have become a decent volleyball coach and can spend my hobby time there. My wife and I have spent the last 3 years together running teams of kids during the winter and spring, competing at a fairly high level.

As tired as I can get and as stressful as some events can be, I love spending 6 months with a group of kids, watching them learn, grow, struggle, and succeed. I take a lot of pleasure in seeing them later as they continue to grow and develop.

I’m grateful that these kids are a part of my life.

Posted in Blog | Tagged , , | Comments Off on Daily Coping 12 Jan 2022

Daily Coping 11 Jan 2022

I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag.

Today’s tip is to make time to do something kind for yourself today.

I booked a massage. I don’t do this very often, but I took a break from life and booked a hot stone massage, always a relaxing treat in the winter.

I often tend to think about others before myself, so this was a good reminder to take care of myself.

Posted in Blog | Tagged , , | Comments Off on Daily Coping 11 Jan 2022

T-SQL Tuesday #146–Changing Preconceptions

tsqltuesdayIt’s the start of a new year, and the first T-SQL Tuesday is from Andy Yun. I’ve known Andy a long time and this is his third time hosting with a creative prompt for us all to consider.

I really like this one as it could be taken as a technical or a non-technical prompt. What did you think was one way and you learned it was another way. Always good to stop and double check that your view is actually representing what you think.

We all do this in our views of life as well as work, and it can be hard to change what or how we think. This is especially true for many of my customers, as I find them wanting to adopt DevOps, but not really wanting to change.

I’ll tackle this one in a couple ways, one technical and one non-technical.

Separate Accounts for Each Instance

For a long time, I always used separate domain accounts for each SQL Server service. Even in a large environment, with hundreds of instances, I did the work (or have junior DBAs do it) to ensure that each service was account separated. This was important because I’ve had change passwords and other issues break services in the past. None of the incidents seemed worth saving a bit of time to set up separate accounts.

Over time, and as SQL Server evolved, Group Managed Service Accounts came into being. I resisted using these at first, but over time I’ve realized that these are valuable and provide security as well as ease of administration. If I went back to managing servers, even single ones, I’d likely look to ensure that gMSA was the standard.

Take Feedback as An Opportunity

I’ve struggled with having someone criticize me for my work. I’ve even struggled when they suggest something else, bristling at the idea that I wasn’t doing something well. Often I was successful and doing something well, but there might be a better way.

Across time, and age, I’ve learned to appreciate other points of view and not become defensive to feedback. Instead, I’ve started to look at other views as a chance to learn or grow, or even just try something. I can still reject the advice or suggestion, but I ought to consider it.

I’ve started to adopt the “strong opinions, loosely held” philosophy at work.

Note, I’m trying to do this in my personal life, but I still very much suck at this.

Posted in Blog | Tagged , , | 2 Comments