DEV Community

How to name software things, be a good programmer & work solo

Arpit Mohan on October 07, 2019

My TL;DR style notes from articles I read today. Effectively Naming Software Thingies “Programs are meant to be read by humans and onl...
Collapse
 
zeslova profile image
Simon Newby • Edited

I'm feeling bad about the database I tossed up last week where all the ID columns are called ID rather than <tablenameID now... 😳

Collapse
 
mohanarpit profile image
Arpit Mohan

I actually prefer that instead of tablenameID. I typically don't like alliteration in my SQL queries or code function calls. I'd much rather invoke select * from users where id = ? instead of select * from users where userid=?

I find the first one more readable and understandable as well.

Collapse
 
buinauskas profile image
Evaldas Buinauskas • Edited

This isn't generally bad. I worked with both and having TableNameID makes a lot of sense when you write more SQL code. It makes join conditions way easier to read.

Collapse
 
zeslova profile image
Simon Newby

Yeah definitely, and since I'm using the ids to correspond to other numeric columns in one base table then using a view to display strings instead of underlying integers, I think it's passable for the time being.

Collapse
 
danyalasif profile image
Daniyal

It seems pretty okay for a database since the context gives it meaning and using 'id' is pretty common in database lands. i.e. don't feel bad!

Collapse
 
buinauskas profile image
Evaldas Buinauskas

I've recently made a change in our api where we had three data properties where each meant totally different thing. 🤔

Collapse
 
mohanarpit profile image
Arpit Mohan

Are they now named data1 , data2 and data3 ? 😛

Collapse
 
buinauskas profile image
Evaldas Buinauskas

No! : ) It is paginated research data and JSON previously looked like this:

{
    "page": 1,
    "size": 3,
    "total": 3,
    "data": [
        {
            "countryId": 1,
            "categoryId": 2,
            "data": [
                { "year": 2012, "data": 123.45 },
                { "year": 2013, "data": 123.45 },
                { "year": 2014, "data": 123.45 },
                { "year": 2015, "data": 123.45 },
                { "year": 2016, "data": 123.45 },
                { "year": 2017, "data": 123.45 }
            ]
        }
    ]
}

Now it's been renamed to be as follows, which is 1000 times better!

{
    "page": 1,
    "size": 3,
    "total": 3,
    "results": [
        {
            "countryId": 1,
            "categoryId": 2,
            "timeSeries": [
                { "year": 2012, "value": 123.45 },
                { "year": 2013, "value": 123.45 },
                { "year": 2014, "value": 123.45 },
                { "year": 2015, "value": 123.45 },
                { "year": 2016, "value": 123.45 },
                { "year": 2017, "value": 123.45 }
            ]
        }
    ]
}