this post was submitted on 21 Apr 2024
886 points (97.9% liked)

Programmer Humor

19302 readers
1150 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] dylanTheDeveloper@lemmy.world 3 points 5 months ago (3 children)

I'm not a CS major but why exactly does having a variable or parameter that's not used in C, C# and C++ throw a warning

[–] Prunebutt@slrpnk.net 9 points 5 months ago

It's probably gonna be optimized out by the compiler. However, linters will mark it for you, since it suggests that you actually wanted to do something with that variable and forgot about it after declaration.

... Or it can be removed to reduce visual noise once it's not necessary anymore after refactoring.

[–] gens@programming.dev 5 points 5 months ago

Lets say you use a variable named abcd in your function. And a variable named abcb in a for loop inside the same function. But because reasons you mistakenly use abcd inside that loop and modify the wrong variable, so that your code sometimes doesnt work properly.

It's to prevent mistakes like that.

A similar thing is to use const when the variable is not modified.

[–] Shareni@programming.dev 2 points 5 months ago

Because it's code that literally doesn't do anything. Some languages won't even let you compile without special instructions.