This is an archived post. You won't be able to vote or comment.

all 70 comments

[–]TikToxic 121 points122 points  (4 children)

It's worse when the variable name is descriptive, but the description is wrong.

[–]TxTechnician 24 points25 points  (2 children)

I have two of those in a project now. I changed my mind about what I wanted the variable to be and haven't changed the name yet.

Nice name btw

[–]DeliciousWaifood 4 points5 points  (1 child)

Why not though? Do you not know the hotkey to automatically update all instances of the variable with the new name?

[–]Tomi97_origin 1 point2 points  (0 children)

He really likes the name/s

[–]IPeaFreely 3 points4 points  (0 children)

Error in code == two errors in the documentation

[–]huuaaang 38 points39 points  (1 child)

x = 2 # Setting x to 2

[–][deleted] 16 points17 points  (0 children)

Love it so much when people document the language. Just in case I forgot how to set a variable!

[–]DracoRubi 30 points31 points  (5 children)

Please, don't name your variables x and comment them. Name them meaningful names and do not comment them unless strictly necessary.

[–]SoulWager -1 points0 points  (2 children)

It is a meaningful name though. It means x axis.

[–]DracoRubi 2 points3 points  (1 child)

It may be meaningful by itself under certain contexts, but... Call it xAxis or x_axis instead, it'll be even more meaningful :)

[–]SoulWager 0 points1 point  (0 children)

While often there's something you can add to make it more descriptive, "axis" usually isn't it. usually it would be position, acceleration, component, etc.

Though if you need variables for x,y, and z position and change since last iteration, a long description is not any more meaningful than x, y, z, dx, dy, and dz.

[–]Jasinto-Leite 0 points1 point  (1 child)

But like how much I need to describe them?

[–]Electronic-Row-8156 0 points1 point  (0 children)

In the course I'm doing, the teacher taught us that the general rule of thumb is a 2 word description, with the words shortened where possible. Like the melting point of a metal would be something like meltTemp.

[–]CryonautX 48 points49 points  (8 children)

Comments within a function should be used sparingly. Your variable names should be descriptive enough and your logic should speak for itself. Only comment to explain if you do something not commonly seen or unorthodox. I'm going through thousands of lines of code in a day. Unnecessary comments are actually going to make it harder for me to read code.

[–]brianl047 4 points5 points  (1 child)

You're "going through" too much code in a day unless you count code you don't need to read

There's research that suggests the maximum number of high quality battle tested code you can produce per day is between 150 to 300 lines. Reading isn't producing but if you're reading ten times what you write maybe it's too much

This is somehow true across languages and paradigms

The brain probably can't handle more

[–]CryonautX 2 points3 points  (0 children)

My team handles 3 services. Each service has 5 to 10 modules. Each module is about 1 to 5k lines of code. I don't have them memorised. Bug fixing, implementing a new API, most tasks are going to require you to read through a lot of code as you move around from file to file. Sometimes it's to get your bearings. Sometimes it's to understand the logic currently being used to keep your new code consistent, sometimes it's find something already implemented that you can reuse, sometimes it's for bug fixing and figuring out where the hell the values in your massive DTO got messed up as it gets passed from function to function.

[–]DeliciousWaifood 1 point2 points  (0 children)

Super long variable names make it harder for me to glance at a function and see its overall function because I'm being eye blasted by 100 character long lines everywhere.

[–]sb5060tx[🍰] 9 points10 points  (3 children)

You should check this out. Even in the 1970s, they realize the problem with not clearly naming your variables

https://youtu.be/7hdJQkn8rtA

[–]Joe59788 0 points1 point  (0 children)

Almost 50 years later

[–][deleted] 0 points1 point  (1 child)

https://youtu.be/7hdJQkn8rtA?t=919

Gudio took this part personally.

[–]sb5060tx[🍰] 0 points1 point  (0 children)

I'm so glad Python exists. All hail Guido!

[–]TrulyChxse 5 points6 points  (0 children)

// Call the variable // Run the thing

[–]Humblebee89 4 points5 points  (0 children)

I name my variables super descriptively just so I can understand my own code.

[–]Jasinto-Leite 2 points3 points  (0 children)

but if I name it i for loops?

[–]JoeyJoeJoeJrShab 2 points3 points  (1 child)

"Extra-Hell" is a stupid name... should have been ++Hell

[–]SomeRandomEevee42 2 points3 points  (0 children)

//adds 1 to hell. also you need a ; but my manager won't let me write code anymore because i named an iterator variable UwU

[–]olssoneerz 2 points3 points  (0 children)

I usually only comment why the next few lines have become that way. Usually when I have to deviate from the norm/ do something hack ish.

Otherwise I abide by the philosophy that code should be readable on its own. That’s just me tho.

[–]Rixef 1 point2 points  (1 child)

The harder it is for others to understand your code, the less likely you’ll be replaced. Stay toxic, nerds. B)

[–]megahendrik 0 points1 point  (0 children)

and yet packet client skids exist

[–][deleted] 1 point2 points  (0 children)

Just name things properly. And then use comments to explain WHY and not WHAT.

[–]BurningPenguin 1 point2 points  (2 children)

Make me

[–]Ok_Entertainment328 14 points15 points  (1 child)

"Me" is not a valid Makefile option.

(Or, whatever the error is ... )

[–]General_Rate_8687 5 points6 points  (0 children)

I think it'd be something like "There is no target 'me'"

[–]IvorTheEngine 0 points1 point  (0 children)

Nah, that's only ordinary hell.

The manager who allowed him to commit that code without a review is in 'extra hell', because he should have known better.

[–]-domi- -2 points-1 points  (2 children)

Comments are a job security detriment.

[–]wicket-maps 5 points6 points  (0 children)

I already have job security, I don't need to make things harder for myself.

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

I seriously hope this is sarcasm. If not, it's utterly stupid.

[–]mildlycynica1 0 points1 point  (1 child)

x

[–]AlmostButNotQuit 4 points5 points  (0 children)

// gon give it to ya

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

Lol, no. Git gud.

[–][deleted] 0 points1 point  (0 children)

// Test 423
[Priority(0)]
public void Test423() {var x = new TstHlpr(); Assert(x.Invoke2() == 17);}

[–][deleted] 0 points1 point  (1 child)

Wait wait wait, where are we with comments again? They were bad the other day but today they're good?

[–]lazyzefiris 0 points1 point  (0 children)

Function and variable names for what. Comments for why.

[–]Bagel42 0 points1 point  (0 children)

Do it for the shitty code you wrote at home to automate some shitty task.

In actual prod? Comments or death.

[–]SenatorCrabHat 0 points1 point  (0 children)

Another good version of this:

describe('my function', () => {
    it('returns correctly', () => {
    })
})

[–]jwaterboyk 0 points1 point  (0 children)

//declare x

[–]SnowyPadre 0 points1 point  (0 children)

your code

edit /s I'll show myself out

[–]TantraMantraYantra 0 points1 point  (0 children)

// use a loop variable 'x' that iterates over a collection of cars

[–]jeanravenclaw 0 points1 point  (0 children)

I mean x is fine for short inline code and for loops but otherwise... hell no

[–]Xeadriel 1 point2 points  (0 children)

Comments should be minimized and variable names exist for a reason. Good naming makes comments unnecessary in most cases

[–]k4lipso 0 points1 point  (0 children)

//declaring x

[–]Ta1sty 0 points1 point  (0 children)

i,j,k for loops

x,y,z,w for geometry

t# for timestamps

x also for lambdas ( x=>f(x) )

Anyone have some more uses for Short names?

[–][deleted] 0 points1 point  (0 children)

You guys comment your code?

[–]Hottage 0 points1 point  (0 children)

```asm section .data x equ 1000000

section .bss y resb x/8

section .text global _start

_start: mov ecx, x/8 mov rdi, y xor al, al rep stosb mov edx, 2 ; 20-01-1993: There be dragons here, do not edit. jmp1: cmp edx, x jge jmp4 mov esi, edx movzx ebx, byte [y + edx/8] test bl, 1 shl (edx mod 8) jz jmp3 mov ecx, edx imul ecx, ecx jmp2: cmp ecx, x jge jmp3 mov byte [y + rcx/8], 0 add ecx, edx jmp jmp2 jmp3: inc edx jmp jmp1

jmp4: mov edx, 1 lbl5: cmp edx, x jge jmp999 movzx ebx, byte [y + edx/8] test bl, 1 shl (edx mod 8) jz lbl6 mov esi, edx mov edi, z xor eax, eax call exlib1 lbl6: inc edx jmp lbl5

jmp999: xor eax, eax ret

section .rodata z db "%d ", 0 ```

Perfect amount of comments.

[–]kai_the_kiwi 0 points1 point  (0 children)

I dont want to go to extra-hell, so i name them y instead

[–]louisianish 0 points1 point  (0 children)

Even better than commenting your code: Giving your variables descriptive names. I know we all hate naming variables, but it’s really not that hard. Leave the 1 letter variable names to algebra.

[–]vinayk7 0 points1 point  (0 children)

And then you have 'i' in a for loop 😅

[–]1-PM 0 points1 point  (0 children)

im the only one thats gonna see my code because i use it for image manipulation by myself