Blog Post

Putting counters in names

,

It’s not all that unusual, or unreasonable to put a counter in a name. For example let’s say you need multiple test instances for your Sales production instance. It’s not unreasonable to do something like this:

  • TestServerSales_Test1
  • TestServerSales_Test2

You do want to be somewhat careful though as it is possible you can get some very confusing names. For example let’s say that your production environment requires three different instances so you do something like this:

  • Sales_Prod1
  • Sales_Prod2
  • Sales_Prod3

But you also have two nodes for a cluster for an availability group. Now you have:

  • ProdServer_Node1Sales1
  • ProdServer_Node1Sales2
  • ProdServer_Node1Sales3
  • ProdServer_Node2Sales1
  • ProdServer_Node2Sales2
  • ProdServer_Node2Sales3

Your test environment doesn’t have a cluster, but you do have 2 copies of each of the instances, and since this server was upgraded recently your server team decided to create the new server with a counter (the original was something like TestServer01 and the new server is TestServer02).

  • TestServer02Sales1_Test1
  • TestServer02Sales2_Test1
  • TestServer02Sales3_Test1
  • TestServer02Sales1_Test2
  • TestServer02Sales2_Test2
  • TestServer02Sales3_Test2

If you think that’s starting to look a bit confusing you’re absolutely right. Now add in a case where they need a third set of test instances but TestServer02 is getting a bit overwhelmed so now you have TestServer03 with yet more instances on it.

The same thing can happen with variables. I’ve seen @Counter1, @Counter2, @Counter3, etc. in the same piece of code before.

In the end, while I don’t think it’s a problem to use a counter in a name, multiple counters can get bit confusing. So to keep the number of counters down I try to avoid them whenever I can come up with something else to use. This would have been a bit easier to follow in my ever so humble opinion.

  • TestServerWin2016SalesWeb_Test1
  • TestServerWin2016SalesDesign_Test1
  • TestServerWin2016SalesApp_Test1
  • TestServerWin2016SalesWeb_Test2
  • TestServerWin2016SalesDesign_Test2
  • TestServerWin2016SalesApp_Test2

Do I like having the windows version name in the server name? Not overly but I think it’s better than just a counter. And how do I feel about having more specific instance names? This is a 💯 for me. There’s not only no need to put a counter there now but the instance names are far more specific. It’s actually easy to tell what exactly this is intended for. And last but not least we have an actual counter. First test environment, second test environment. Perfect place for a counter and I can’t think of anything you could put there instead that would work better.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating