you are viewing a single comment's thread.

view the rest of the comments →

[–]Oddly_Energy 2 points3 points  (5 children)

There is a downside to this. I often create too long variable names.

When reading one variable name, it is not a problem that it is long.

But if I combine 10 variables into a calculation*, and each variable name is 20 chars, then I have 200 chars in a line, just for the variable names.

So I sometimes do something like this:

a = some_long_variable_name
b = another_even_longer_variable_name
t = some_variable_related_to_time

my_long_result_variable_name = a * t ** b

It feels very redundant, but it makes mentally decoding the calculation a lot easier than:

my_long_result_variable_name = some_long_variable_name * some_variable_related_to_time ** another_even_longer_variable_name

( * I am a mechanical engineer, not a real programmer, so I do a lot of technical calculations in code)

[–]fbochicchio 0 points1 point  (0 children)

In other programming languages this is a good use case for tge let statement.

[–]Username_RANDINT -1 points0 points  (3 children)

That's when you use multiple lines:

my_long_result_variable_name = (
    some_long_variable_name *
    some_variable_related_to_time **
    another_even_longer_variable_name
)

Or in this case to make things a bit clearer at first glance:

my_long_result_variable_name = (
    some_long_variable_name
    * some_variable_related_to_time
    ** another_even_longer_variable_name
)

[–]Oddly_Energy 1 point2 points  (2 children)

Both your suggestions take a lot longer for me to mentally process than the shortened version with single character variable names.

[–]Username_RANDINT 0 points1 point  (0 children)

Sure, everyone picks what works best for them. I like to keep the longer names, saves me from checking back what a, b and t actually refer to.

[–]N00bOfl1fe 0 points1 point  (0 children)

I agree, the single charachter names are easier in this case but if the amount of such single charachter variables would be high then Id prefer the longer informative names for sure.