Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Conversations: Obelisk


January 2001 C++ Experts Forum/Conversations

"—and parties will start going down next week. I think we'll get to go the week after," Jeannine finished. "They're still excavating around the top of the crystal obelisk, but no further news yet. It's hard going, and we didn't plan to do this kind of exploration. This goes way beyond our research and mining mandates. Frenell still thinks it's a hoax."

I laughed. "Frenell's a genuine space oddity and needs to get out more. It's the wrong color; it's in the wrong place; it's—"

"Sure, we've known for months now that it was deep under the ice."

"—it's the wrong shape, and if someone was playing a practical joke, they'd do better than that. Anyway, no joker could ever embed it that deeply."

"I've heard a better one," Jeannine interrupted. "Aubrey believes it's real, all right, but he thinks it's a conspiracy. Decades too late for 2001, but 'still suspiciously similar,'" she imitated the junior officer, exaggerating his characteristic sibilance.

"Aw, Aubrey sees government cover-ups everywhere. Remember when we were kids, and cover-ups about magic ricocheting bullets were all the rage?" I paused, and smiled thoughtfully. "Speaking of monolithic, actually, did I tell you about my bizarre discovery just after New Year's Day, back in the real 2001 . . .? No? Well, it was while I was still at my first job . . ."


It was January 2, a Tuesday, when I discovered Bob's monolithic code. Happy and with loosened belts, we were all just back from the holidays — unfortunately, delivery deadlines wouldn't wait — and we were slowly getting ourselves back into motivated mode. I was mainly happy that I'd managed to survive my job's probation period; I was now a full employee, although some days I still wondered whether that was entirely a good thing, given that the job often had me working in close proximity with the Guru. She was smart, all right, but more than a tad strange.

It was getting close to lunchtime when Wendy interrupted me. "Yo," she called.

I gophered up. "Yeah? What?" I'd been in the middle of a debugging session trying to find an error in my code and was just about ready for a break. Anything had to be better than stepping through the same function for the two dozenth time.

Wendy appeared. "Bahb's still out this week, and I need a quick fix to the utility module he took over from you a month ago; I'm getting a buffer overflow trap at line 510. Can you look at it and fix it by this afternoon?"

"Sure." She gave me the filename, we both ungophered, and I pulled it up in my editor.

Half an hour later, I had to admit that I'd been wrong after all: There were indeed some things that were worse than stepping through my own code in the debugger. I finally gave up and walked over to Wendy's cubicle. "Sorry," I said merrily.

Wendy started; I guess she hadn't heard me come up behind her. I suppressed a smile . . . usually it was the Guru who did that to both of us. "What do you mean, sorry?" she asked.

"You wanted it fixed quickly. I'm sorry, Wendy; I'm afraid I can't do that."

"What's the problem?"

"I think you know what the problem is just as well as I do."

"What are you talking about . . .?"

I sighed and stopped playing. "I can't fix it quickly. Have you seen what Bob's done to the code since I handed it off to him? I swear this bears almost no resemblance; its origin and purpose are a total mystery to me. It'll take me half a day to understand what he's done to it." I reached over her and pulled up the file on her screen, went to the top which is where the function began, and then held down the scroll-down key. Nearly 2,000 lines later, we reached the matching close-brace at the end of the file. "The function is now 1,908 lines long — roughly, a 1,200-line if block, followed by a 700-line else block. Most of the rest can be fixed with a source code beautifier, I think."

Wendy was shaking her head in disbelief, but nodded. "I've seen him do that before, but I really thought we'd broken him of the random tabbing and long code lines, and especially the random vertical whitespace."

"There's at least one spot where you have to page down past a full screen of empty lines before you get to the next code line! And did you notice how he sometimes tabs out when entering a for or while block [1]? The Guru usually won't stand for this . . . doesn't she enforce the coding standards any more?"

"Indeed we do, my child," sighed a voice from close behind us. We both jumped. The Guru continued sadly, "Bob has been warned before. He shall be warned again, and this time be docked of pay. But . . ." she trailed off thoughtfully.

Neither Wendy nor I wanted to speak immediately. The silence settled. Finally, I quietly prompted: "But what?"

The Guru blinked carefully. "How long is the longest line in the file?"

Wendy did a quick check. "Several are exactly 848 characters long. That's the longest."

"And what is the shortest?"

This took Wendy a little longer. "The shortest nonblank line is 212 characters. There are a few that length."

The Guru seemed to do some quick mental arithmetic, and sighed again. "I see. Perhaps he was making a statement."

I thought for a moment, then: "Oh. I get it: One to four to nine. That's the ratio of line lengths to total function size."

Wendy groaned.

The Guru pushed her hair back behind her ear and adjusted her glasses. "Avoid monolithic code," she said. "Bob is a structured programmer, but even he should know well the merits of functional decomposition. Prefer 'one class, one responsibility,' and 'one function, one responsibility.' This function is obviously decomposable into at least two parts, and yet even those parts would be too complex and should be decomposed further. Wendy, instruct this young one: What are the benefits of good code decomposition?"

"Clarity," Wendy said, ticking off each point on a finger. "Reusability. Encapsulation. Maintainability . . ."

And it was at that moment, at just that unfortunate moment, that we heard the front door opening, the whistling wind outside, and the front door closing. And Bob walked in.

"Hey dudes," Bob said, taking off his mittens and knocking snow off his boots all over the carpet. He scratched himself absently. "Whassup?"

"I thought you were off this week," Wendy grumbled.

"Yeah, sure, babe, I just had to swing by to get some files that I'd downloaded here . . . surfing the net . . . er, ah, well, that's not important. Hey," he squinted at Wendy's monitor, the centerpiece to our little gathering. "That's my code."

"That was my code. It used to be good code. Before you turned it into a joke," I said hotly, gathering steam. Bob had more years of experience than I did, but my probation period was over, and I was angry; and I guess I might still have been a little hung over, as I'd had a pretty lively last several nights. I felt like risking it.

Bob shrugged. "Hey, look. I can see you're really upset about this."

"Upset? Bob," I retorted, "you've made a travesty of my code!"

"It can only be attributable to human error," the Guru agreed quietly.

"Hey," Bob said defensively, "I honestly think you ought to calm down. Take a stress pill and think things over."

"Bob," said the Guru, "begone."

"Hey, I didn't ask to be—" Then Bob caught himself, and calmed down. "Hey, look. Okay. I know I've made some very poor decisions recently, but I can give you my complete assurance that my work will be back to normal . . ."

"Bob, this conversation can serve no purpose anymore. Goodbye. Take your vacation. We will discuss it privately on Monday."

Bob grumbled, but seemed to think better of it and left. So did the Guru, after smiling. Once both were out of earshot, Wendy and I dissolved into a fit of the giggles. When we recovered, Wendy ran the file through a source code beautifier as a start, and I spent the rest of the day rewriting Bob's code. Along the way, I discovered that some of the resulting smaller functions could be reused nearby, now that their functionality was better isolated instead of being buried inside a monolithic block. The smaller chunks were also simpler to grasp, and soon I found Wendy's problem and solved it. I added a unit test for Wendy's problem, reran all the unit tests to be sure everything still passed, and checked the module back in.


"You sure picked one hoot of a first job," Jeannine shook her head.

Before I could answer, the rec lounge door opened and Brzenkowski walked in. He started walking over to the far side of the lounge without looking up, which was unusual for him.

"Hey," I called, "you don't say hi any more?"

Brzenkowski looked up. "Hmm? Oh, sorry. Say, have you heard the news yet?"

Jeannine frowned. "What news? From the excavators?"

"Yes. It appears that the obelisk," Brzenkowski said quietly, "isn't just an obelisk. It seems to be the top of a building."


Note

[1] Note from the authors: Believe it or not, this is an actual example of code written by a programmer the authors encountered some years ago.

Jim Hyslop is a senior software designer at Leitch Technology International Inc. He can be reached at [email protected].

Herb Sutter is chief technology officer of PeerDirect Inc. and secretary of the ISO/ANSI C++ standards committee. He can be reached at [email protected].


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.