Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I would probably die of embarrassment if anyone ever saw the number of lines in my code that say

x = x //this doesn't need to be here but it breaks if you remove it



Wouldn't it be better to figure out why it breaks?


The five whys should be applied to successes in addition to failures. https://en.wikipedia.org/wiki/5_Whys

If you figure out some amazing workaround, ask yourself why it works. If you don't know, don't trust the workaround.


If you question it, you might find a way that works better. Then you have to redo all of it, and that's more work, so just keep plugging away, blissfully ignorant!


"If I just wrap everything with if(obj != null), then all the bugs go away!"


It's an example of a time when I'm fooling myself into believing that some stupid little thing has an effect on my code. It probably won't break if I remove it, but this is how those situations go down:

1. Something is broken

2. Try to fix it. Still broken.

3. Try to fix it. Still broken.

4. Sleep on it. Try to fix it in the morning. Still broken.

5. Refactor. Still broken.

6. Make a whole bunch of changes, including adding x = x.

7. It works! x=x must have fixed it! Stupid programming language.

8. Add x=x to all future code because it works because Python sucks and is stupid.

9. (optional) Go on Stack Exchange and HN and tell everyone that you need to say x=1.5 and follow it with x=x because Python is stupid and I am so smart to have figured this out.


How to Program by Coincidence https://pragprog.com/the-pragmatic-programmer/extracts/coinc...

Suppose Fred is given a programming assignment. Fred types in some code, tries it, and it seems to work. Fred types in some more code, tries it, and it still seems to work. After several weeks of coding this way, the program suddenly stops working, and after hours of trying to fix it, he still doesn’t know why. Fred may well spend a significant amount of time chasing this piece of code around without ever being able to fix it. No matter what he does, it just doesn’t ever seem to work right.

Fred doesn’t know why the code is failing because he didn’t know why it worked in the first place. It seemed to work, given the limited “testing” that Fred did, but that was just a coincidence. Buoyed by false confidence, Fred charged ahead into oblivion. Now, most intelligent people may know someone like Fred, but we know better. We don’t rely on coincidences—do we?

Sometimes we might. Sometimes it can be pretty easy to confuse a happy coincidence with a purposeful plan


That's perfect! I program by coincidence all the time. The very definition of a hacker... "it works, I must have done it right". And if it doesn't work, keep adding more console.println statements until you find something unexpected, then add a "x = x" to fix it and BOOM I just wrote Snapchat give me lots of money.


No, no, no. Please tell me you're joking.

If not then maybe, just maybe, I'm actually spending way too much time thinking about what I write, and maybe should stop and just write more code.


I'm joking, but it hits a little close to home because all of us have done that before. You're at the end of your rope and just need this thing to fucking work and you'll deal with the "why" later. For now, x = x works dammit, and it doesn't matter why. Meanwhile the console is filling up with all of your variables being printed out because you couldn't figure out where the value of x was being corrupted.

The next morning you switch to functional programming and forget that day ever existed.


cargo cult programming?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: