Your Worst "Gotchas" ever in programming

Started by
68 comments, last by Icebone1000 11 years, 2 months ago

I did say language and tools. ;)

That the language still allows you to make that exact same mistake in exactly the same way doesn't make it look like an upgrade =P

True, the tools for the language are what's better.

Advertisement

Oh gee.

  • Anything threading
    • Implementing a reusable, thread-safe, intrusive copy-on-write base for classes (2 levels of thread safety required!!)
    • Any undocumented or hard to find caveat to a windows api call. Ex: WatiForMultipleObjects in some threading situations
  • Different STL optimization flags set in a single project. This caused random crashes in random places I spent a looong time "debugging" in code which was actually correct.
  • MSVC producing the same .obj filename out of two separate source codes in separate directories which themselves have the same filename. UGH. Major linking problems.
  • C++ implicit casting has nailed me hard more than once.

Oh, don't worry on that account, we already upgraded our language. wink.png
Which, incidentally, also solves ApochPiQ's bug in the post above this.

Actually, the implicit NULL conversion to literal 0 in my code is a total red herring. The actual evil is squarely with default parameters, and can be trivially reconstructed even with all the parameters being of primitive non-pointer types.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

It looks like C#.


I did say language and tools. ;)


Oh, don't worry on that account, we already upgraded our language. wink.png
Which, incidentally, also solves ApochPiQ's bug in the post above this.
You know, I'm sure with a higher than default warning level and 'warnings as errors' I've seen the compiler catch this error before now (reports as a warning, warning as error fails the compile).

Now, it won't catch you when you make this mistake...

auto it = std::begin(someContainer);
auto end = std::end(someContainer);
bool found = false;
while(it != end && !found)
{
    found = *it == searchItem;
}
Opps... biggrin.png

@ApochPiQ: Then I fail, cause I can't spot it at all. laugh.png

(Ignoring the lack of actual inheritance in the structs, which I presume isn't the bug)

I'll rephrase it slightly:
struct Base
{
    Base(int oldValue, int newValueWeJustAdded, int oldValueWithDefault = 42);
};

struct EverythingMustBeOne : Base
{
    EverythingMustBeOne()
        : Base(1, 1, 1)
    {  }
};

struct EverythingMustBeTwo : Base
{
    EverythingMustBeTwo()
        : Base(2, 2)
    {  }
};
Assume that Extremely Bad Things™ happen if the value of oldValueWithDefault in EverythingMustBeTwo is not 2.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

You know, I'm sure with a higher than default warning level and 'warnings as errors' I've seen the compiler catch this error before now (reports as a warning, warning as error fails the compile).

Gcc requires -Wall and -extra to catch it. Clang catches it by default.

(incidentally, this discussion is occurring over here as well).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


Now, it won't catch you when you make this mistake...




auto it = std::begin(someContainer);
auto end = std::end(someContainer);
bool found = false;
while(it != end && !found)
{
    found = *it == searchItem;
}
Opps... biggrin.png

Lesson: stick to for loops when doing that kind of iterations.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

Lesson: stick to for loops when doing that kind of iterations.

I prefer the 'while' construct; imo it better expresses the intent of the loop.
'for' tends to imply you'll hit a whole range where 'while' is more a 'while these conditions are true' and, in my mind, is better for a search.

Would have prefered to have used an std algorithm however, would have been clearer and without the mistake...

http://www.gamedev.net/topic/617629-works-with-x64-debug-x64-release-and-x32-debug-but-not-with-x32-release/

If werent by gamedev...Ive had gave up on programming many times..(learned new stuff in that one)

This topic is closed to new replies.

Advertisement