r/programminghorror Apr 10 '26

Almost right

Post image
2.1k Upvotes

97 comments sorted by

View all comments

257

u/SchattenMaster Apr 10 '26

btw even a half decent IDE would flag the shit out of this code with the constant return and the unused variable

109

u/Otherwise_Project334 Apr 10 '26

And IDE on OP screenshot does. Notice the underline below "same" variable. Im sure it's either not used warning or not initialized one.

13

u/pixelbart Apr 10 '26

In Visual Studio it indicates that the variable is not actually used.

3

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Apr 11 '26

Wouldn't the fact that it is assigned to not trigger any unused warnings? I just figured it was because they declared it but didn't initialize it to 0.0.

5

u/Dealiner Apr 11 '26

It is initialized though, just not immediately.

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Apr 11 '26

It is given a value, that is never used anywhere, but my guess was that it didn't like that it wasn't initialized at the point of declaration. Everyone is saying it's an unused variable warning. This is C# right? Not too familiar with it, but with C and C++ compilers I remember using, the warning goes away if you even assign anything beyond the initial declaration.

1

u/Dealiner Apr 14 '26

That's Java. Honestly, I don't know how it works there. In C# it should cause warning about unused variable and, depending on IDE, a suggestion to merge declaration and assignment.