1
iamabot
30d

I am unable to understand the naming convention. I SUCK IN IT.. CAN'T I JUST NAME MY VARIABLE AND OTHER THINGS LIKE SIMPLY, WHY I HAVE TO USE UNDERSCORE AND ACCURATE NAME FOR IT.

I mean , my variable does tell what is it for then why I need to do that?

Comments
  • 2
    i mean depending on the context you sometimes can give variables simple names. Just don't do i, tx, m_*, l_*, etc.
    just name shit short and meaningful 👌

    i personally always write out i as index for example, since let's face it your IDE of choice will auto complete and you're usually not confined to 80 chars per line. And it will keep you from doing i, j, k and stuff like that.

    i guess the only reason why a one char variable would be okay, is when the full name of it consist of one letter anyways, like x, y, z. Or common words like ui, json or html (where the meaning unambiguous).

    A good rule of thumb, if you don't know if an abbreviation is common, it's better to not abbreviate it (if you had to look it up for example)

    Everybody has their personal preferences though.
  • 1
    @thebiochemic you are right! But I work as a backend Developer and in classes let's suppose my class is deal, and in it I have to use location.. so why I choose fancy words like deal_location, when I can use location? It's common sense that location is using in deal class...

    Well anyways I get scolded by my senior and they were like , it's common sense which you don't have any. I am actually offended
  • 3
    the variable name doesn't just need to tell _you_ what it's all about.

    it needs to tell _everyone_ what it's all about.

    and that's why naming conventions exist.
  • 1
    Don't forget that your (future) team mates and future you will dislike you if you write code that isn't clear (variable names is part of that).

    And naming conventions are there for a reason, to ensure consistency and enhance readability and structure.

    If you went through a single code base where files, of the same type, have like e+ coding conventions and styles each; you'll have a harder time reading and understanding it.
  • 1
    Variable names that scream your intention are > names just following convention

    Make your code unanimous yet skimmable

    Oh and <insert rant about why people should learn code smells>
Add Comment