Ever programmed something and surprised yourself how you got it to work?

Sep 27, 2010 at 2:46pm
Hi there - this is just a general Question.
Has anyone here had that experience where they've just programmed something - and it didn't work at first but then all of a sudden you get this brainstorm and then the program works beautifully.
Later you come back and say "How the heck did I come up with that idea?" or "How did I ever manage to get this work so well?"
Sep 27, 2010 at 2:54pm
Sometimes programming is enough to give one a bipolar disorder.

Highs: squashing a difficult bug or refactoring garbage code into a beautiful piece of Art
Lows: getting stuck in debugger hell in a real-time app where bugs are erratic and irreproducible

The difference between the highs and lows can be immense. Sometimes, a good break or a good night's sleep helps. Other times, getting another POV on these forums helps.
Sep 27, 2010 at 3:35pm
As a matter of fact just the other day. I have been working on a Sudoku Solver and Generator, and am nearing completion. I was testing a sudoku puzzle, known as the hardest sudoku puzzle known, created by a finnish mathematician. It is so hard, that with my current set of inference rules, I am only able to make 1 deduction (i.e. fill in 1 square) before it can't deduce any more. While implementing a new inference rule, or debugging it rather, I commented out a few lines of code to be able to see where the crash was occuring. After several of these attempts, to my surprise, not only did it not crash, but it had solved the entirety of the remainder of the puzzle. I said Oh my god, how did I do that? With the lines of code that I had commented out, my new inference rule shouldn't really have been doing anything, let alone solve the puzzle... (which when I verified on the net had given me the correct puzzle solution, I was amazed!) As it turns out, after I had commented out those suspect lines of code in my new inference rule, what the function was actually doing was going through each cell, eliminating the first possible candidate in that cell, and then returning true.

When I realized that, I was still perplexed because how was it coming up with the right solution? I guess it turns out that by coincidence, eliminating just 2 (which happened to be the first 2) candidates of the first empty cell was enough to allow the rest of my inference rules to solve the puzzle completely. Had the first possibile candidate in the first empty cell had been the actual number for the cell, I'm sure my program would not have found the correct solution. Just by coincidence is all. So kind of a Hi & Low in 1.
Sep 27, 2010 at 3:49pm
Many times when I'm working on something ( not strictly programming ) I wake up during night with the solution to the problem
For this reason I have some paper and a pen near my bed
Sep 27, 2010 at 4:11pm
Bazzy wrote:
For this reason I have some paper and a pen near my bed.

For this reason, I have a pen, pencil, two C++ books and a LOT of paper near my bed. :P
Sep 27, 2010 at 4:22pm
And you need to make sure that your computer if far from your bed or you won't sleep that night
Sep 27, 2010 at 4:29pm
Sometimes I see the answers on my dream ;) I think it occurs when my body and mind is in good condition and I am determined to solve the problem. Right now I'm really so depress I always lack sleep, I notice it's not happening anymore.
Sep 27, 2010 at 5:57pm
For me, this is 24/7. I oftentimes have trouble understanding how I can program on the levels I can with relatively little experience in a language or a field of programming, yet whenever I look at a piece of code or write a piece of code, I understand it, the problem to solve, how to solve the problem, the problems with the code, the solutions, and then some perfectly if my awareness is doing well (if it's not, I miss fine details that make a world of difference). And yet, I never know how I can get something to work like it does.

Let's just say I'm an insane programmer. ;)

-Albatross
Last edited on Sep 27, 2010 at 5:58pm
Sep 28, 2010 at 2:52am
As an oral learner I find telling someone else my problems (regardless if they have any idea of what I am talking about) really helps me solve a problem. Simple problems irk me but when I figure them out I can get euphoric! Programming is full of ups and downs but the ups always make up for the downs.
Sep 28, 2010 at 3:17am
Errr.... not to be a wet blanket but don't you all have social life besides programming? I like to banter around with my daughters and watch CSI after work. CSI fan you might say. Fringe not bad too and so is Bones and Desperate Housewives, Ghost Whisperer etc :P
Sep 28, 2010 at 3:19am
Some of us indeed have social lives outside this forum (myself included). Others no. Why ask here, though?

-Albatross
Sep 28, 2010 at 4:27am
Ahh for a social life.. Sometimes I wonder what happened to my social skills when I started programming. Of course my biggest problem is probably the fact that I then begin to write a program do discover the answer to that very question... Haha I'm actually kidding, I think that my girlfriend said it best, "You seem to love that computer more than me!" On some (if not most) occasions that is indeed true =)
Sep 28, 2010 at 4:57am
Try loving your girlfriend in front of the computer. I guess that would make you both happy :D
Sep 28, 2010 at 1:19pm
I think most of us have social lives but we don't see a reason to discuss them on a programming forum :)
Topic archived. No new replies allowed.