Jump to content

  • Log In with Google      Sign In   
  • Create Account

Your Worst "Gotchas" ever in programming

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
69 replies to this topic

#1 Lil_Lloyd   Members   -  Reputation: 287

Posted 28 January 2013 - 05:37 AM

Ever had an issue you just couldn't debug? You tried stepping through the program and the relevant parts line by line and the values in your watch window look ok, but the magic just isn't happening when you hit 'run'. You spend hours these problems, and then when you relax and take a bath or a walk the Archimedes moment happens and you realise the small mistake you made.


As for me I was trying to implement interleaved array buffer objects in Open GL today, and the meshes were rendering but the texturing just wasn't happening. After some careful deliberation and many attempts over a few hours, I gave up. When I was walking to my local restaurant I realised I didn't call glEnableVertexAttribute(). I get home, try it and it runs! 


So, time wasted or a lesson well learned? 


What are your most frustrating problems that were solved with something simple you forgot?



#2 Waterlimon   Crossbones+   -  Reputation: 4236

Posted 28 January 2013 - 05:54 AM

Cant recall anything very interesting, but the latest ones were forgetting to make a function return a reference instead of a value (and assuming assigning an object to a reference would change where the reference points) and trying to figure out why my game always renders the cells in the middle of the screen as "loaded" (with chunked terrain) instead of the ones at the origin, because i forgot that of course the chunks will be loaded around where you are looking and not around the origin xP


#3 Xanather   Members   -  Reputation: 761

Posted 28 January 2013 - 07:33 AM

lol yes, I remember a few times actually where I wanted something to happen, and it didn't. Spent a while trying to debug it, and it was as simple as calling the method.

#4 swiftcoder   Senior Moderators   -  Reputation: 17436

Posted 28 January 2013 - 07:41 AM

Pass-by-reference can be a killer:

  • Neglecting to pass an argument by reference, and then staring at a profile trace where 75% of the time was spent in a copy constructor.
  • Passing by reference the nodes in a recursive-descent parser, which caused the same instance to be modified over and over again, and the parse to get stuck in loops.

Tristam MacDonald - Software Engineer @ Amazon - [swiftcoding] [GitHub]

#5 Milcho   Crossbones+   -  Reputation: 1177

Posted 28 January 2013 - 08:14 AM

This took me back about 4 years, when I was working on my capstone uni project. Me and a friend were getting linker errors - something along the lines of " somevariable already defined in somefile.obj". No compilation errors - all our headers were #ifndef guarded, so we were scratching our heads for near four days.


The obvious thing, in retrospect, is that #ifndef guards only stop code declaration from happening twice. If you (as we did) put actual data in a header file (say, something like int someCount; that is not static), it doesn't matter if the .h file is guarded, when its included multiple times the linker will try allocate the variable again, and will fail, giving an error like above.


Bottom line is don't put anything except declarations in your header.

#6 Nyssa   Members   -  Reputation: 426

Posted 28 January 2013 - 08:17 AM

Best one I've seen is a program missing the '()' when calling glEnd. Caused BSOD! Took a while to figure out till we realized we overlooked something as simple as some brackets haha.

#7 Ravyne   GDNet+   -  Reputation: 13181

Posted 28 January 2013 - 08:55 AM

  1. Template meta-programming. 'nuff said.
  2. Deciding to do a small project in C, and forgetting all locals must be declared *before* any code statements in a scope.
  3. I once was doing some pointer arithmetic in Quickbasic, and my program, a 16bit DOS app, would crash windows entirely. I narrowed the problem down to one of four identical lines. It turns out that in one of those lines, in one place, I multiplied the pointer by some value, rather than adding. I have no idea what that caused it to overwrite, but I take crashing windows from a supposedly-isolated DOS app to be a point of pride.

throw table_exception("(ノ ゜Д゜)ノ ︵ ┻━┻");

#8 PurpleAmethyst   Members   -  Reputation: 334

Posted 28 January 2013 - 08:58 AM

Colleagues who think that writing their own custom C++ string classes rather than using a well tested library is wise.

Missing or misplaced commas and brackets - I have spent half days utterly confused by these stupid mistakes that I made, every coder no matter how experienced has done this at some point.

#9 smr   Members   -  Reputation: 2234

Posted 28 January 2013 - 11:01 AM



>>>import time
>>> def report(when=time.time()):
...     print when
>>> report()
>>> time.sleep(5)
>>> report()


Python default arguments are defined when the function is defined, not when it's called. Calling report will always return the same value with no arguments. (I took this specific example from stackoverflow, but it's bitten me a few times).


Or you can get caught by it this way:


>>> class Thing:
...     def __init__(self, v):
...             self.v = v
>>> def foo(thing=Thing(0)):
...     thing.v += 1
...     return thing.v
>>> foo()
>>> foo()




A contrived in Oracle SQL:


SELECT * FROM table WHERE null != null


Will always return zero results because null is never equal or inequal to anything. In Oracle, varchar fields are never empty. They either have something in them, or they are null. Zero-length strings are considered null.


This means that the query:



Will not return any rows where COLUMN1 is empty. The natural expectation would be that when COLUMN1 has no value, then it would not be equal to 'THIS' and thus would be included in the resultset. At least that seems natural to me.


The workaround:


Edited by smr, 28 January 2013 - 02:10 PM.

#10 Barbossa   Members   -  Reputation: 967

Posted 28 January 2013 - 11:21 AM

Last month I needed to access single characters from Delphi Strings. But whatever I did my program just put out trash and crashed.

After six hours (and almost implementing a replacement system) I got it:

While arrays start by zero, Strings in Delphi start at 1. So i kept interpreting the first byte, which does totally mess up Unicode....


Additionally in another project (GCC/Linux => C++) there was a function, log(), which compiled properly, but the linker never found it, whatever I try. (Multiple Headers, directly in the source file etc). Hours later I finally found an answer: The function was declared as

inline void Log( Ogre::String MSG );

In VC++ this works fine, but under GCC/Linux the "inline" caused the linker to search the function without finding it. Wasted way too much hours searching mistakes like that...

#11 HelloSkitty   Members   -  Reputation: 152

Posted 28 January 2013 - 11:48 AM

I once had a school project in java dealing with Strings. Well, what better name for a class dealing with a project centered on Strings than String.java? Then when I tried to use methods of java's String class, the methods weren't there (because the compiler was trying to find the methods in my String class). Took two days to figure it out and it was only because I tried to rewrite the thing with more descriptive class and variable names after being inspired by a daily WTF article.
A penny for my thoughts? Do you think I have only half a brain?

Not-so-proud owner of blog: http://agathokakologicalartolater.wordpress.com/

#12 swiftcoder   Senior Moderators   -  Reputation: 17436

Posted 28 January 2013 - 12:07 PM

Implementing a compiler front-end in Python. Write the prosaically-named 'SyntaxError' exception class. Realise that none of the methods on my SyntaxError class are accessible.


A little later, run 'pydoc SyntaxError' and realise the problem...

Tristam MacDonald - Software Engineer @ Amazon - [swiftcoding] [GitHub]

#13 MaxDZ8   Crossbones+   -  Reputation: 4857

Posted 28 January 2013 - 12:07 PM

I don't recall the best.

But I'll tell you what I just fixed.


Updated an old project to new interface.

It failed on a custom string comparison.

Figured out the new project had optimizations all ON while dependencies didn't.

Previously "Krohm"

#14 XXChester   Members   -  Reputation: 1363

Posted 28 January 2013 - 01:09 PM

First time I used a treeset with a custom comparator and I couldn't figure out why it was loosing elements after calling sort().

Remember to mark someones post as helpful if you found it so.










#15 Oberon_Command   Crossbones+   -  Reputation: 4386

Posted 28 January 2013 - 01:43 PM

Another vote for pass by reference issues. I once fixed a bug by adding a single '&' character to a function signature.

#16 TheChubu   Crossbones+   -  Reputation: 8221

Posted 28 January 2013 - 01:53 PM

Probably everything when I'm kinda sleepy.


When I'm doing something and I'm not pretty focused, sometimes I go into "auto mode" and I eventually just lose track of what I'm trying to do and how.


So I code, code, code then something doesn't works and I spend 40min trying to figure out what I was doing (like literally, just trying to understand what I was doing the last 20 seconds), why, how I tried to do it and only then why it isn't working.



My journals: dustArtemis ECS framework and Making a Terrain Generator

#17 szecs   Members   -  Reputation: 2662

Posted 28 January 2013 - 01:54 PM

Not calling the function I was debugging (and that was good for the first time and all along).

EDIT: I'm into some of those moments with Labview too. It's inherently parallel, so I'm sucking with queues and notifiers to avoid race conditions, sucking with messages getting lost and making workarounds to solve that.

Ah, yup, here's a gotcha: in Labview you draw wires (data flow) between icons (kinda like functions). I was debugging a bug for three hours, foaming at the mouth, breaking the keyboard in rage, when I accidentally noticed that the wire was hiding under the debugged construct (a case structure), and the wires from inside the case construct weren't actually connected with the outside. No wonder why values never changed. It was impossible to tell by eye, the wires where collinear, the little output "ports" were there on the structure, but not connected with the wire outside.

Edited by szecs, 28 January 2013 - 02:05 PM.

#18 mikeman   Members   -  Reputation: 2586

Posted 28 January 2013 - 03:07 PM

Yeah, I actually had one of these moments today...I implemented 3D sound with OpenAL, however it was clear to me that it didn't sound exactly right; like sounds switching from left ear to right ear randomly. I didn't manage to find what was wrong, so I closed the computer and went out...and on the cafe, I realized that AL_ORIENTATION would require 2 vectors, direction+upvector...just direction isn't logically enough no matter the API...so I returned home and sure enough, it expects 2 vectors instead of just the 1 I passed. Which, in OpenAL's C world means it expects a pointer to a 6-float array, which means it was just reading garbage for the up-vector. Don't you just love these kind of bugs?(OTOH, maybe I should have read the documentation more carefully :P)

#19 dave j   Members   -  Reputation: 631

Posted 28 January 2013 - 03:32 PM

Not one of mine but a former colleague's. I used to work on an OS written in BCPL. BCPL calls a function named TIDYUP when an application exits. If you define your own, it calls that rather than the default one. (Think of it as a bit like an automatically registered atexit function in C). My colleague spent a day and a half pulling his hair out trying to find why his TIDYUP function didn't seem to be called. Eventually he gave up and asked someone for help. The other guy took one look at his screen and said "It's because you've spelled it TIDUP".

#20 Aurioch   Crossbones+   -  Reputation: 1304

Posted 28 January 2013 - 03:39 PM

My experience isn't interesting but is the only one I remember...


During last summer, when I started working on current project, at one moment I was implementing first collidable object. That time for tank I was using Vector2 Position and Vector2 Origin to tell spritebatch where to draw the sprite of the tank while keeping its bounding box as Rectangle. To be able to properly rotate tank, Origin must be set at the center of the texture itself. Position of tank was set the same as topleft point of its bounding box. I spent one week trying to figure out why was half of the tank going under the wall before eventually leaving it out of burnout and frustration.


2 months later, I remembered that Origin defines the point from which the sprite will be drawn...

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.