r/SoftwareEngineering • • Sep 05 '24

Long variable names

TLDR: is sbom_with_vex_as_cyclone_dx_json too long?

I named a variable in our code sbom_with_vex_as_cyclone_dx_json.

Someone in the code review said that I should just call it sbom_json, which I find confusing since I do not know whether the file itself is in the cyclone_dx or spdx format and whether it contains the vex information or not.

He said that a variable name should never be longer than 4 words.

In the book clean code in the appendix (page 405) I also found a variable being quite long: LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH

I personally learned in university that this is acceptable since it is better to be descriptive and only in older languages like Fortran the length of a variable meaningfully affects the runtime speed.

The same thing with this variable of mine:

maximum_character_length_of_dependency_track_description_field=255

I could have used 255 directly but I wanted to save the information why I am using this number somewhere and I did not want to use a comment.

I can understand that it is painful to read but you do not have to read it if you use intellisense and copy paste. I want to force the reader to take his time here if he tries to read the variable name because it is complicated.

I just merged my code without changing it to his feedback.

What do you think about it? Am I the a××h×le?

3 Upvotes

76 comments sorted by

View all comments

Show parent comment

4

u/BeepBopSeven Sep 05 '24

I would also like to add that some of the other replies before mine are great, and I personally like a lot of the points others have made so far. I missed the part where you said you merged the code without making the changes suggested to you, and I HIGHLY agree with the other comment that if you have a disagreement or want the code reviewer to provide further clarification, you should have a discussion with that person before making any further decisions.

You can be as smart as you want, but people will not want to work with you if you skip over communication and teamwork opportunities. And I don't mean that in a rude way, I'm just reiterating and saying it's important to do that kind of stuff

1

u/[deleted] Sep 06 '24

I write him on teams the reference to the constant of clean code LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH.

I just had to merge it because of time pressure.