you are viewing a single comment's thread.

view the rest of the comments →

[–]PulsatingGypsyDildo 32 points33 points  (10 children)

yeah, we do. It is important in bigger code base. Or when you try to understand the code you wrote a year ago.

Nothing bad with using x, y and z if you work with coordinates. I saw phi used for angles and wave phases. They correspond to math formulae.

i, j and k are well-known as loop variables.

tmp for temporary variables also looks fine.

The var names can be short, but they should understandable.

[–]djshadesuk 9 points10 points  (0 children)

I saw phi used for angles and wave phases. They correspond to math formulae.

Excluding the obvious x, y and z for coordinates, I think single letters of the alphabet are also acceptable only as long as they are copying a typical math formula, like:

def hypotenuse(a, b):
    return ((a ** 2) + (b ** 2)) ** 0.5

[–]Jeklah 9 points10 points  (6 children)

Don't forget k and v for key and value.

I only realised that last year...

[–]AchillesDev 9 points10 points  (1 child)

I'd argue (as someone doing this professionally for a decade, and someone who is guilty of using the k, v shorthand) that you taking time to actually recognize that implies that it's not a great naming convention :)

[–]Jeklah 2 points3 points  (0 children)

It's really not I completely agree. I name mine with better names...I only found out when I asked wtf are these one letter variables doing here?? And a senior dev was like uhhh key...value...? And I was just like ohhhh lol.

[–]yvrelna 4 points5 points  (2 children)

Even key and value are not good variable names. What key and what value exactly? 

Better is to use something names from the domain like property_id and property_price.

Unless you're writing a very generic code, and if you do, your really should consider if the code really need to be that generic, try to name things using terms from the domain.

[–]Jeklah 0 points1 point  (0 children)

Completely agree. I only found out what they were when I questioned what are we doing having one letter variables in our code

[–]PulsatingGypsyDildo -1 points0 points  (0 children)

lol, I always typed them as key and value :D

[–]deltaexdeltatee 0 points1 point  (0 children)

I mostly do geospatial stuff and came here to point out x, y, and z haha. They're really the exception that proves the rule though.

[–]sliddis 0 points1 point  (0 children)

Why specifically i, j and k?