Avoiding feature creep as a developer
Tags: productivity, programming
Published: 2023-03-22 07:55:46

_TLDR: Make sure your code is extendable and do the bare minimum._

> Feature creep is the excessive ongoing expansion or addition of new features in a product, especially in computer software, video games and consumer and business electronics. These extra features go beyond the basic function of the product and can result in software bloat and over-complication, rather than simple design.
> [Wikipedia: Feature Creep](https://en.wikipedia.org/wiki/Feature_creep)

## We've all been there

We've all estimated an issue to be completed in a couple of hours, and days later, we're not sure when it'll be finished, but it's "almost there, just needs this one thing done". Just like yesterday and the day before that. One of the reasons why this might happen is feature creep: "I'm gonna do this one other thing too while I'm at it".

## Simple example
Let's assume the requirement is "Set a value inside a multi-dimensional array using a simple [JSONPath](https://goessner.net/articles/JsonPath/index.html#e2) as path to data". We'd want to use something like `$.path.to.data` to set value of a 5 to our array. So, we'd do:

```
$array['path']['to']['data'] = 5;
```

The problem here is that we don't know the path in advance, so we need to be more creative. It's not a complex problem, and you can solve it with a simple solution like:

```
function setArrayValue(array $array, string $path, $value): array {
    $path    = preg_replace('/^\$\./', '', $path);
    $keys    = explode('.', $path);
    $current = &$array;

    foreach ($keys as $key) {
        $current = &$current[$key];
    }

    $current = $value;

    return $current;
}

```
Writing this code won't take days (especially as I pretty much copy-pasted it from [StackOverflow](https://stackoverflow.com/questions/13359681/how-to-set-a-deep-array-in-php)). But couldn't we make it a bit better?

What if the path was something more complex? JSONPath allows paths like `$.actions[action_type==video_view].foo`. What if someone wants to do that instead? It's not included in the original requirement, but it might become handy. So, let's go ahead and implement it, right? 

## Stop!
…and this is where you should stop. Was the more complex path  a requirement? No. It's not a "simple JSONPath". If you're unsure, ask the Product Manager for clarification. As it's not a requirement (and the PM confirmed that), you don't implement it. 

Instead, you ensure that such a feature could be implemented in the future if needed. Basically, you're making sure that your code is extendable. And yes, looking at the [function signature](https://developer.mozilla.org/en-US/docs/Glossary/Signature/Function), nothing prevents you from doing this. Your code is extendable. You're good.

## Why did you stop?
If you chose to continue and add the more complex path, you'd be guessing future needs. If you guessed wrong and we never needed the feature, implementing it would only have wasted time and effort, and delayed the features we actually needed. Implementing the more complex logic takes more work, as does testing it.

---

Explore engineering careers at Supermetrics at [supermetrics.com/careers/engineering](https://supermetrics.com/careers/engineering).