> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Don't Write Clever Code
- URL: https://nolongerset.com/dont-write-clever-code/
- Published: 2021-07-15T02:24:34.000Z
- Updated: 2026-05-08T13:03:38.000Z
- Description: There are two problems with clever code. 1) The next person might not know what you were doing. 2) They might not know if *you* knew what you were doing.
- Author: Mike Wolfe
- Tags: Commentary, #Import 2026-05-20 02:59

Someone recently posted the following on [LinkedIn](https://www.linkedin.com/feed/update/urn:li:activity:6817227731399442432/):

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/07/image-4.png)

The poster is both technically right and practically wrong.

## He's technically right

I want to give the poster the benefit of the doubt here and assume that they would never actually declare variables this way in their own code. And I completely understand where they are coming from. If someone is throwing gotcha questions at you during a technical interview or test, it's awfully tempting to throw that back around in their face with a gotcha of your own. Hey, I'm more of a smart-ass than most, so I really do feel where they're coming from.

## He's practically wrong

With all of that throat-clearing out of the way, I have to vehemently disagree with the following line (emphasis added):

> If one were asked to define three variables, two of which are Variants and one is an Integer, then **there's absolutely nothing wrong as shown**.

Let me adjust the quote to something I can agree with:

> If one were asked to define three variables, two of which are Variants and one is an Integer, then there's absolutely nothing wrong as shown **if the compiler is the only one who will ever have to read the code.**

### Write your code for people, not computers

When you write code, you should write it **so that people can read it**. 

This is much clearer than the sample code above:

```vba
Dim i As Variant, j As Variant, k As Integer
```

The same code could also be split so that each variable is declared on its own line:

```vba
Dim i As Variant
Dim j As Variant
Dim k As Integer
```

The problem in the sample code is that `i` and `j` are *implicitly* declared as Variants. Implicit declarations are bad practice generally, but they are especially egregious in this case.

Other languages, like C++, allow you to declare multiple variables of the same type on one line with only a single type declaration.

When you write clever code that relies on intimate knowledge of the programming language (VBA in this case), you bake two dangerous assumptions into that code forevermore:

### Assumption 1: Every person who reads your code knows what you are doing

You assume that the next person to come along that sees the line... 

```vba
Dim i, j, k As Integer
```

...will understand that `i` and `j` are Variants. This is a dangerous assumption. A reasonable programmer new to VBA would likely expect that all three variables have been declared as Integers.

### Assumption 2: Every person who reads your code will know that *you knew what you were doing* when you wrote it

If I come along and see code like `Dim i, j, k As Integer`, my first thought would be that an inexperienced programmer wrote this and probably didn't understand that `i` and `j` had been implicitly declared as Variants.

I would then spend some amount of time (any amount is too much) combing through every other reference to `i` and `j` in your code to see if it's being treated as a Variant or an Integer. This is a waste of my time, and I might never know for sure what you really intended.

Both of these assumptions are completely outside of your control. So I implore you, [don't write clever code](https://nolongerset.com/overly-clever-code/).

---

### Article references

[Overly Clever CodeKeep It Simple, Stupid![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/01/lock-4894184_1920.jpg)](https://nolongerset.com/overly-clever-code/)

*Image by [Steve Buissinne](https://pixabay.com/users/stevepb-282134/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=1668167) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=1668167)*

***UPDATE \[2021-07-15\]:*** *Added sample code to show what the "not clever" version of the code would look like. H/t [@rafadomene](https://twitter.com/rafadomene/status/1415594988835119105).*