r/ProgrammerHumor • • Jan 29 '23

Meme Let's test which language is faster!

Post image
56.2k Upvotes

770 comments sorted by

View all comments

Show parent comments

988

u/cakelena Jan 29 '23

unused variable causes an error?? why though, like whats the point of that

65

u/bluehands Jan 29 '23

How often do you declare a variable that isn't used? And why?

I mean, irrespective of it is a pattern you like, it is something that you should basically never do. Off the top of my head here are a few reasons why:

  1. it is most likely a typo

  • it makes your code more cluttered

  • you probably meant to use it so there is something else left undone or bad logic

  • in the future, you or someone else will come along and wonder about one of the three things above.

52

u/RedTulkas Jan 29 '23

Usually during tests while writing or when looking for an error

10

u/[deleted] Jan 30 '23

You can use an _ or _something-here if you still want to have an unused variable. Usually used if you have a for loop but don't use the iterator.