Programming Topics + CVu Journal Vol 29, #2 - May 2017
Browse in : All > Topics > Programming
All > Journals > CVu > 292
Any of these categories - All of these categories

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.

Title: A Hollywood Take on Dangling Pointers?

Author: Martin Moene

Date: 05 May 2017 09:20:59 +01:00 or Fri, 05 May 2017 09:20:59 +01:00

Summary: Silas S. Brown tells a fable about read-only variables.

Body: 

A friend wrote someString.substr(3).c_str() and her code seemed to work but her colleagues were saying something about “going out of scope” that she didn’t understand. So I sent her a film script.

The scene opens in some forgotten alleyway. Cue scary music. In walk the Silly Evil Overlord (SEO) and his Minions, all dressed in black. (Yes, I’m afraid it’s only a B movie. We’re not super-rich you know.)

The SEO speaks. “And now”, he says, “my secret plans for dominating the world are well in progress. I tricked the book-shop chain into opening up a new book shop that contained just the books we wanted. And then”, (turns to shout at his Minions) “Minion Number One! Did you accomplish your Mission for me?”

“Yes my lord. I stole a special piece of paper from the new book shop, my lord. This should tell us everything we need to know.”

“Good”, said the SEO. “And now, because I am Evil, and the audience need to see my Evilness, it’s time for my first Evil Act of the Film. Mwa-hahaha!” (stereotypical evil laughter) “Seeing as we have now got what we want from the new book shop, we have no use for that book shop anymore. Mwahaha!” (Pulls out a small cylindrical gadget marked ‘Scope of Destruction’ and presses a button on it. Explosion sounds. Stock footage of pyrotechnics. Hole in the ground.)

SEO still chuckling. “And now” (pause) “for the second part of my Evil Secret Plan. The piece of paper you took from the book shop contains all the details we need to break into the bank and steal a gazillion dollars.” (We’re in America of course. Where else would make movies this bad? Oh, I’ll probably get some flak for that.)

Scene changes to inside a tunnel. A sign says ‘Bank Vault’ above a myriad flashing lights and buttons. SEO and Minions arrive.

“And now” says the SEO, “Minion Number Five! Read the special piece of paper that tells us the Secret Security Key!”

Minion Number Five starts to read. “Breaking Into Movie Banks for Dummies. The book you require is located on shelf 451 of the Book Shop.”

Minion Number Four steps forward. “My lord, I will go to the book shop and get it at once.” (runs off)

Minion Number Three: “ummmm... my lord? He won’t get very far my lord.”

SEO thunders “WHY not?”

“Because, um, er, my lord, pardon me please, your evilness, I mean, um,”

“You blew up the book shop, my lord” says Minion Two.

SEO is indignant. “We didn’t have to keep the book shop around, wasting all that space! We had no use for it anymore after we took out the one sheet of paper we really needed. Besides, imagine the inconvenience of having to keep a whole book shop on my List of Things to Blow Up Before I Die. Besides, didn’t Mr Black assure us that one piece of paper from the book shop was all that would be needed?”

“With all due respect my lord” said Minion One, “perhaps what Mr Black really meant to say is, he can manage on one piece of paper as long as the book shop is still around for him to...”

“WHY DIDN’T Mr COMPILER pick me up on this??” thundered the SEO.

Enter Mr Complier. “My lord, technically you didn’t break any of my Compiler Rules. You said you needed to keep the piece of paper, and you kept it. You never said the book shop it points to has to still be around for you to check what it refers to. That’s not in my department to spot. Maybe Mr Lint might have seen it, if you’d happen to catch him on a good day, but fundamentally you must understand that, although we do try to point out your mistakes as best we can, there’s a certain class of error that always sneaks past us and -”

“Enough!” thunders the SEO. “I’ll blow YOU up next. Suggestions! There must be Something we can do.”

“My lord”, chimes in another Minion, “we put a special lock on it called const, so it can’t change. Doesn’t that mean the book will have been protected from change even though you blew up the book shop?”

Laughter all round. “Wait” said the SEO, “I want to look into this. Minion Number Five! You didn’t read the whole piece of paper, I know it. Read it again.”

Minion Number Five was nervous. “OK”, he managed, “here we go my lord: Breaking Into Movie Banks for Dummies. The book you require is located on shelf 451 of the Book Shop. The bearer of this Ticket is entitled to read the Book but not to write in it.”

Silence. Camera pans around everyone’s faces.

Minion Three pipes up. “So in other words, const doesn’t mean it can’t change, it just means they won’t let US change it with that ticket. It might still change behind our backs if someone else has a better ticket. Or a…” (looks nervously at the spent detonator and breaks off)

Mr Compiler comes back in, “It means I’ll moan at you if you try to write in the book” he said. “Unless of course you tell me to stop moaning with a Cast. In which case I’ll let you write in it. And yes, of course it’s no guarantee against somebody else writing in it, or moving it, or blowing it up. That’s the trouble with those tickets. If you’ve got the ticket, it doesn’t mean you’ve got the book, so you’d better know where the book is and who’s looking after it.”

“Oh” spat the SEO. “Useless Tickets. Next time I have an Evil Plan, I’ll have my minions copy the whole Book, not just the Ticket!”

Gasps around all the Minions. “My lord! Tickets can be very useful for speed, much faster than copying a whole book! You just have to make sure you know what you’re doing with…”

“Silence!” thundered the SEO. “Until I know what I’m doing, I’m having you all copy out whole books next time before I blow up the book shop, even if that does slow me down a bit! In fact, I’m going to find some more intelligent Minions that know when to steal a book instead of copy it. But that comes later.”

A Minion dares to speak up: “Maybe we should try to get that book anyway, my lord. I mean, it might have survived the explosion. Sometimes they do, especially if nobody’s got around to re-building something else on the same spot before we get there. Like when we vandalised the market stall in the Prequel Film That Shouldn’t Be Made, remember? So it does sometimes work anyway. And if it doesn’t, we’ll just get nothing or gibberish, and we’ll know. It can’t be worse than that, can it?”

Minion Number Four comes back, panting and clutching a book. “My lord, guess what? Your Arch-Rival, sir, the Intelligent Evil Overlord. He persuaded the Town Planners to allocate the freed-up spot to him, and he made sure we still had the access rights. And he built an exact replica of the book shop you blew up, in the exact same place, and sure enough it had the right-looking book on shelf 451. Hot off the press too! And it’s a signed copy, look at this.” (opens at the first page, SEO reads) “Dear SEO, I know you’ll enjoy using this special replacement edition I made specially for you. I wouldn’t normally say anything, but I just had to sign it this time for the audience’s benefit. Mwa-hahaha. IEO.” (Let’s not call him Cunning Evil Overlord because that’s how you get fired.)

Minion grabs book. “Isn’t that kind of him? I’ll start using it at once, my lord. What could possibly go wrong?” (Jarring orchestral chord. Fade to black.)

Two months later my friend was unfortunately fired from her post, saying they'd criticised her for failing to work independently, but also for failure to sufficiently communicate with colleagues.

She found this contradictory, and I must confess I would have expected a little more clarity from an 84,000-employee German enterprise.

I recommended she make a point of asking future potential employers if they practise pair programming – it sounds like that’s what she needs.

Notes: 

More fields may be available via dynamicdata ..