Programming Advice Episode 2

programming advice


This is the second episode of the “Programming Advice” series. If you did not read that, it is highly recommended to check out the “pilot” episode.

Programming Advice: Naming Conventions

Naming conventions are important in programming for numerous reasons. There are a lot of conventions. It highly depends on the programming language that you are using. Examples of naming conventions are CamelCase, snake_case, PascalCase, StudlyCaps, etc. This is a lesson learned a hard way. So it is a good idea to consider this programming advice as a treasure. Some of you may find this simple and stupid. However, this could save hours of debugging. Imagine a case where there are a lot of functions, and your task is to do a code refactor. And probably, you would also touch the architecture. The task is to improve whatever you see is possible, as much as possible. A quite trustworthy person you are. Not everyone is given this kind of opportunity.

So, without further ado, let us get to the point. Besides the conventions mentioned above, there are also some rules that are just a part of common sense. This is where this programming advice is coming from. For example, in the code below you can see the potential fixes, right?

export function getPersonsName(ids: string[]): string[] {
  //do some function related work!

export function getPersonName(id: string): string {
  //do some function related work!

They are okay, right? They seem to follow the convention “CamelCase”. However, the problem is naming. You see, you can easily think that they are the same whenever they are used in the same line, like in the below example.

const ids = ['id1', 'id2'];
const newArray = => getPersonName(userId));
const names = getPersonsName(ids);

Right? You can easily mix things up. Especially when it is the first time you see this code. Imagine seeing something like this. Here the functionality of “getPersonsName” is a little changed. It separates the “id”s out of the complex data structure

const ids = [{id: '', ...otherData}, {id: '', ...otherData}];
const newNames = getPersonsName(ids).map(id => getPersonName(id));

Here, have a peek. In case you did not know anything about the functions, you would think that those are the same functions. This complicates the developer’s life. The life of developers is already not easy, so there is no need to make it artificially harder. 

Basically, this is a piece of general programming advice to help developers be more productive.

Programming Advice Episode 2

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top