# Coding/Programming nightmares. Those forced on you and the ones you left for others

**URL:** <https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557>\
**Category:** Miscellaneous and Personal Stuff I Must Share\
**Created:** [August 8, 2020, 5:21am UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557 "2020-08-08T05:21:05Z")\
**Posts on this page:** 14\
**Page:** 3

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [December 1, 2020, 11:35pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/41 "2020-12-01T23:35:52Z")

</div>

Do not leave the smart people alone with the toys. We _will_ play with them in unintended fashion.

---

<div class="post-metadata">

**Author:** ![squeegee](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/squeegee/32/14537_2.png) [@squeegee](https://boards.straightdope.com/u/squeegee)\
**Post date:** [December 2, 2020, 1:03am UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/42 "2020-12-02T01:03:44Z")

</div>

I worked with an engineer, the lead guy on a project that I came along to after it was a couple of years mature. It seems this guy knew just one kind of sort: a bubble sort. Every time he needed a set of things in order, he’d write a bubble sort inline in the code (this was long before standard libraries/templates offered good sorts built in). Once when I was trying to figure out why something he wrote was so non-performant, I realized he’d managed to write a bubble sort that called a bubble sort on every bubble. Doing an action in a set with just a couple dozen or so records would just go away and noodle for like 10 minutes every time you did anything in the app.

---

<div class="post-metadata">

**Author:** ![N9IWP](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/n9iwp/32/3154_2.png) [@N9IWP](https://boards.straightdope.com/u/N9IWP)\
**Post date:** [December 2, 2020, 3:25am UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/43 "2020-12-02T03:25:55Z")

</div>

Someone on my floor in my dorm had a project for some Mechanical Engineering class. You had to find a set of gears for a given gear ratio (e.g., 0.8765). There were constraints for maximum number of teeth and total number of gears IIRC. You could use any programming language on any hardware.

He wrote the program in LOGO (a language often used to teach kids programming and typically involves drawing pictures with commands like RIGHT 45; PEN DOWN; FORWARD 25) on his Commodore 128. I am guessing most folks used FORTRAN on the University’s VAX (thus was circa 1987). It ran but it was not the fastest…

Brian

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [December 2, 2020, 2:18pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/44 "2020-12-02T14:18:31Z")

</div>

Going back to dev gamesmanship, if any of you haven’t seen this before it’s kind of cool.

> **[Polyglot (computing)](https://en.wikipedia.org/wiki/Polyglot_(computing))**
>
> Pages for logged out editors learn more
> 
> In computing, a polyglot is a computer program or script written in a valid form of multiple programming languages or file formats. The name was coined by analogy to multilingualism. A polyglot file is composed by combining syntax from two or more different formats. When the file formats are to be compiled or interpreted as source code, the file can be said to be a polyglot program, though file formats and source code syntax are both fundamentally...

It’s not exactly obfuscated coding, but it’s close. And arguably at least some of it has a useful purpose for deployment-constrained settings. I’ve used it a couple times over the years.

---

<div class="post-metadata">

**Author:** ![74westy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/74westy/32/3950_2.png) [@74westy](https://boards.straightdope.com/u/74westy)\
**Post date:** [December 2, 2020, 2:53pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/45 "2020-12-02T14:53:09Z")

</div>

This reminds me of some code I stole from a consultant that implemented height balanced trees.

As you probably know if you’re reading this thread, binary trees are data structures that you can store data in and hopefully retrieve again fairly quickly. In the average case data can be inserted or retrieved in O(log n) time (reasonably fast) but in the worst case, like if the data are already sorted, it’s O(n). (pretty slow)

Height balanced trees avoid the worst case by making sure that the two sides of any sub tree have similar height and the tree is not just a long linear list. So, great, I stole height balanced trees and could use them store and retrieve data quickly.

Problem was all the code that used the trees was really slow. When I looked more closely, I saw that, instead of storing the height of each subtree in its node, the code calculated the height of the subtree every time it needed it. Calculating the height of a subtree is O(n) so inserts into these trees were O(n log n)–worse than a linear list.

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [December 2, 2020, 3:57pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/46 "2020-12-02T15:57:24Z")

</div>

> [@74westy](#):
>
> This reminds me of some code I …

had to fix for a cow-orker.

First we have to enumerate the entire index to check by string comparison if our search key is or isn’t a member. Then once we know it is, we go ahead and issue the query against the data store to retrieve the corresponding object.

Worked OK on mocked hashtables with a couple hundred members. Did. Not. Scale.

“Why??!!” you ask as your forehead repeatedly slams against your keyboard. Turns out the guy in question “didn’t like” how the query operation returned its `KeyNotFound` status and this way he “never” had those failures.

As you might expect, he also was also ~~real bad about noticing~~ blind to race conditions. His mind was single-threaded and therefore the rest of the world was too. No matter how many computers, processors, cores, processes, and threads were involved in the multi-layered app we worked on.

---

<div class="post-metadata">

**Author:** ![BeepKillBeep](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@BeepKillBeep](https://boards.straightdope.com/u/BeepKillBeep)\
**Post date:** [December 3, 2020, 11:01pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/47 "2020-12-03T23:01:57Z")

</div>

My favorite comment I ever wrote myself was in my PhD work.

The comment was something like:

/\*  
All of the strings coming in at this point are provably true.  
Do _ **NOT** _ under any circumstances change any of the strings in any way that compromises the truthfulness.  
Look, you’re going to think that you can split them and find some subset of true or true/false strings. They end up all being true/false and the algorithm breaks.  
Do _ **not** _ try this. You’ve already looked at it for a month. It doesn’t work. You proved it doesn’t work, so don’t try it again.  
\*/

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [December 4, 2020, 3:07pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/48 "2020-12-04T15:07:46Z")

</div>

Brilliant!

Some scabs just can’t remain unpicked for long. There’s that weird nagging amorphous doubt (or potentially awesome insight) that sends you down dead-end rabbit trail after dead end rabbit trail.

I _hate_ it when that happens.

---

<div class="post-metadata">

**Author:** ![begbert2](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/begbert2/32/3357_2.png) [@begbert2](https://boards.straightdope.com/u/begbert2)\
**Post date:** [December 4, 2020, 6:56pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/49 "2020-12-04T18:56:11Z")

</div>

Here’s a comment I made over a decade ago that I still remember.

// 01-20-2006 : This would probably come as a surprise to the original  
// author, but the above function call (SetAllDynamicColProps) can and sometimes  
// does recur, sending us back into this function via HideVisibleCtrl, of all  
// things. The problematic side effect of this is that sometimes the internal  
// state of this object gets replaced in the process, causing pLTBase to be left  
// pointing into unallocated data space.  
//  
// Because this cockeyed recurring system actually does work for the most part,  
// I avoided making any structural changes or rewrites to it. The main problem  
// is that, at the end of this function, the invalid pLTBase pointer is used.  
// Re-populating it destabilizes the algorithm somehow; however, it appears that  
// _restarting_ the process over again does not. On the second time through the  
// recursion doesn’t cause a problem (though it does occur), since the internal  
// objects don’t need changing again.  
goto TRYAGAIN;

Sometimes evil begets evil.

---

<div class="post-metadata">

**Author:** ![leahcim](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@leahcim](https://boards.straightdope.com/u/leahcim)\
**Post date:** [December 4, 2020, 7:05pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/50 "2020-12-04T19:05:54Z")

</div>

I had one project where there were objects with a lot of fields like:

```auto
bool isCase1_m;
bool isCase2_m;
&c...
```

And every method would be structured like:

```auto
void method1() {
   if (isCase1_m) {
     ....
   } else if (isCase2_m) {
     ....
   } else if ...
   }
}
```

With very rarely anything in common between the branches.

I’m not normally one for super-deep object hierarchies, but clearly this is just someone who needed an object hierarchy and didn’t want or know how to make one just implementing a poor-man’s version virtual function dispatch themselves.

---

<div class="post-metadata">

**Author:** ![Rick\_Kitchen](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rick_kitchen/32/522_2.png) [@Rick\_Kitchen](https://boards.straightdope.com/u/Rick_Kitchen)\
**Post date:** [December 10, 2020, 9:43pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/51 "2020-12-10T21:43:49Z")

</div>

> [@begbert2](#):
>
> goto TRYAGAIN;

goto? GOTO!?  
Horrors!

---

<div class="post-metadata">

**Author:** ![begbert2](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/begbert2/32/3357_2.png) [@begbert2](https://boards.straightdope.com/u/begbert2)\
**Post date:** [December 10, 2020, 10:10pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/52 "2020-12-10T22:10:18Z")

</div>

Which is why those two words got a 142-word comment, and why I wrote “Sometimes evil begets evil”.

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [December 10, 2020, 10:20pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/53 "2020-12-10T22:20:51Z")

</div>

> [@Rick\_Kitchen](#):
>
> goto? GOTO!?  
> Horrors!

In old languages without decent loop exit statements gotos sometimes were useful to avoid tying yourself in knots about when to exit the loop. One of my PhD oral questions was on this - a trick to catch anti-goto fanatics. (This was about 1976). I taught assembly language and didn’t get caught.  
Totally useless in newer languages, though.

---

<div class="post-metadata">

**Author:** ![begbert2](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/begbert2/32/3357_2.png) [@begbert2](https://boards.straightdope.com/u/begbert2)\
**Post date:** [December 10, 2020, 10:26pm UTC](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557/54 "2020-12-10T22:26:58Z")

</div>

I wasn’t just exiting, though - I was _rewinding_. I was jumping to an earlier point in the function to give it a second shot at it with the member variable values it had collected the first time through. This is not the sort of thing I would recommend anybody ever do, but dammit, it was an ugly situation and it actually worked.

[Previous page](https://boards.straightdope.com/t/coding-programming-nightmares-those-forced-on-you-and-the-ones-you-left-for-others/917557.md?page=2)
