What's the stupidest programming mistake you've made?

@vaporeon_ probably the most recent mistakes I have made were bash-related. I made some wrong assumptions regarding scope rules for variables, resulting in situations where variables in loops had values from previous iterations of the loop that I didn't expect, causing subtle bugs that took me hours to unravel

@wallhackio Got an example? I am Unaware of the scope rules for Bash, actually, but I'm guessing based on your comment that they're different from the scope rules for C?

Follow

@vaporeon_ if I declare a variable in a for loop in C, it "resets" each start of the loop

That does not happen in bash, obviously, but I wrongly assumed that it did

@wallhackio @vaporeon_ really C is block scoped and for loops are an implicit block. you can introduce new blocks arbitrarily wherever a statement is allowed

@aescling @wallhackio Yes, you can even start a block without any for or while or function definition... Should you? No. But can you? Yes:

#include <stdio.h>
int main() {
int i = 0;
{
int i = 7;
printf("i (inner): %d\n", i);
}
printf("i (outer): %d\n", i);
return 0;
}
Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.