for (x=0;x<variable.length;x++) {
// blah
}
I wasn't declaring the x variable, so it was using the x part of the x/y positioning of the UI container. Woops.edit: initialise/declare brain freeze
for (x=0;x<variable.length;x++) {
// blah
}
I wasn't declaring the x variable, so it was using the x part of the x/y positioning of the UI container. Woops.edit: initialise/declare brain freeze
It also doesn't happen in languages where you must say self.x to access a property/field called x.
Only it is worse in Python because, lacking `var` keyword, you will shadow the variable in Python
Do you mean s/initialising/declaring/, or am I just really confused?
In any case, I'm not sure that I need a hint to tell me that doing things quickly and carelessly is a bad idea. But we all do it sometimes, in both our programming and our writing.
I for one would speculate, not to sound harsh, that if you haven't made silly errors like this then you haven't been around the block enough times.
on the other hand, those of us who have been around the block enough times have almost certainly encountered co-workers who were bright, talented, cute, whatever - but at the end of the day were just ... sloppy ... lazy ... careless ... in their approach. It's a personality thing - they had nice childhoods, they never learned to by hyper-vigilant and paranoid, and as a consequence... they write buggy code that can't be trusted.
My eyebrow just raised so far my forehead cramped.
As for the rest... well, I don't understand where you're going with it. Pop psychology aside, are you really suggesting that you write utterly seamless code every single time? You've never done a build and then realised that you made an error somewhere along the way, gone back and fixed it? You act as if my mistake had the potential to ruin a business. Of course it didn't- I picked up on it before the code had even been pushed to the remote repository.
You can live in a world where everyone does everything perfectly, every time (and pay the price when you inevitably don't) or you can set up systems with unit testing, user testing, and- yes- developer testing that results in bugs being dealt with in a timely manner before a single end-user sees anything.
But hey, each to their own. Whatever works for you. If you get it right first time, every time, then you are a better programmer than I, and I congratulate you on it.
Not to beat on you, but didn't you discover the error after users started using it in a big news day?
Between that, and using -Werror to ensure that warnings never get ignored, I find C99-style declare-anywhere quite useful. It helps me keep the scope of variables limited to the places that need them.
That said, I rarely use C99's ability to declare a variable in the middle of a block. I primarily use the C99 feature of declaring variables as part of a loop.
Greatgrandparent's error was lack of such inner declaration. -Wshadow wouldn't help with that.
Also, I imagine enforcing old-style declaration restrictions helps you to avoid introducing those errors in first place, but it's just as hard to debug them once they're in.
My choice would be to get in the habit of declaring a variable in the narrowest scope that makes sense. I can't see much of a problem with this (esp. in the context of C!) barring old habit. I don't think Scheme programmers, for example, have this stuff any easier and I don't think scoping is perceived as a problem there.
I also agree about declaring a variable in the narrowest scope that makes sense. I often see code that attempts to reuse the same variable for several different purposes, rather than declaring separate variables in narrower scopes.