News for hackers. Stuff that matters.
Re:Thoughts Around Naming Variables by quelsolaar on Tuesday March 02, 2021 @03:52AM (#26313269)
As a C programmer i have two ways I go about selecting names. For anything uniqe, I use long post fix names. I think of them as a directory path to the functionality. So instead of:

create_object(); delete_object();

I do:

project_module_object_create(); project_module_object_delete();

I then do the same with files, so the above would probably reside in a file called:

project_module_object.c

This makes everything easy to find, you know where things belong and you can search for partial names to find instances of interfaces.

For local variables, I have a small set of variable names that all have specific meninges like i, j, k, f, sum, found, best, length, count, that I always use in the same way. They therefore become very easy to read since I know their use. If something doesn't fit the limited set of common variables, I revert to long post fix names.

A much longer explanation of how is use C that goes in to more depth about naming can be found here: https://www.youtube.com/watch?v=443UNeGrFoM

There are no comments on this comment yet.