14

Not Speaking The Same Programming Language

(It is the mid 80s, and I have a coworker come to me with two full pages of computer programming source code.)

Coworker: “Hey, can you help me with this? This function is not working right.”

Me: “Sure. What’s it do?”

Coworker: “Well, on the first line I copy…” *drones on for a few seconds about stuff I can clearly read*

Me: “Wait! Let me interrupt for a moment. I can read the code. In 20 words or less, what does this do?“

Coworker: *long pause that tells me he’s having trouble seeing the forest for the trees* “It, um, converts a date that’s a string to three integers: month, day, and year.”

Me: “Ah! Excellent. And by the time you get the string, has it been sanitized? You know, guaranteed to be pairs of digits with a slash in-between, not blanks or words or other garbage?”

Coworker: “Oh, yeah, all the user input is cleaned up.”

Me: “Okay, good.”

(I scribble “sscanf(text, “%02d/%02d/%02d”, &month, &day, &year);” in a blank spot on the page.)

Me: “Throw out everything and replace it with that.”

Coworker: “You’re kidding.”

Me: “Not at all. Use that. It’ll work. Trust me.”

Coworker: *not sure* “Well, okay.”

(Half an hour later he’s back and looking a bit sheepish.)

Coworker: “That worked. Thanks.”

Me: “No problem.”

(It’s been 30 years. Unfortunately, the new generation of programmers is in the same spot.)

https://notalwaysright.com/not-spea...

Comments
  • 1
    @Lahsen2016 it is, but input has been sanitized before, so it should be ok at this point
  • 7
    @CptFox I would never count on input being sanitized.

    Because as soon as you do some one copies just the sscanf line and applies it to unsanitized input and then blames you since you used it first :/

    If its a string I do not even trust data read from our own db since I cannot know if it was saved safe.

    Pack sanitation code together with parsing in a function thats easy to reuse then laziness works in your favor :)
Add Comment