This is why copy'n'paste should be banned from developers' IDEs

More mind-boggling code unfortunately encountered in the wild


Line Break Welcome to the latest instalment of Line Break, the column in which we share ghastly code readers have sadly encountered in the wild.

Pen is mightier than the source

We'll crack on with this appetizing anecdote sent in by Ian:

A long time ago I was working on the driver for a touchscreen controller chip. This driver was supplied to our customers as sample source code which they then incorporated into their product.

One part of the touchscreen controller code detected whether the stylus (pen) is touching the screen (down) or not (up) to determine whether to send points to the operating system. I was updating the end-of-scribble detection code, and decided to change a variable name before it went to customers. I reordered the words in it to isPenUp. I'll leave it to you work out the original variable name.

Well done, Ian, for avoiding that cockup. Lesson: It's said that there are only two hard things in computer science: cache invalidation and naming things. 'nuff said.

Where and tear

Moving right along, Jamie sent in this complete and utter car crash. It looks as though it's trying to construct an SQL statement in a manner similar to building a house by firing bricks smothered in cement out of a cannon. Hold onto your hats.

   if ( Length( Where1 + Where2 + Where3 + Where4 + Where5 + Where6
      + Where7 + Where8 + Where9) > 0 ) then
   begin

        if Length( Where1 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
                  WhereClause := WhereClause + Where1;
          end;

        if Length( Where2 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
              WhereClause := WhereClause + Where2;
          end;

        if Length( Where3 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
              WhereClause := WhereClause + Where3;
          end;

        if Length( Where4 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
              WhereClause := WhereClause + Where4;
          end;

        if Length( Where5 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
              WhereClause := WhereClause + Where5;
          end;

        if Length( Where6 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
              WhereClause := WhereClause + Where6;
          end;

        if Length( Where7 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
              WhereClause := WhereClause + Where7;
          end;

        if Length( Where8 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
              WhereClause := WhereClause + Where8;
          end;

        if Length( Where9 ) > 0 then
                begin
                  if Length( WhereClause ) > 0 then
                  WhereClause := WhereClause + ' AND ' ;
              WhereClause := WhereClause + Where9;
          end;

        WhereClause := 'WHERE ' + WhereClause;

Enough. We can't take it any more. "A really simple example of why sometimes we wish copy and paste was banned from IDEs," notes Jamie. Lesson: Duplicated code is a code smell – and repetition like the above should stink like a skunk's dirty laundry basket. With a dead body inside.

Can't bear to look

After the previous abomination, Peter cheered us up with this anecdote:

Many, many years ago I administered a quite large Symbolics LISP machine network. One day, whilst browsing through the OS source code, I came across this comment:

"You may want to close your eyes, the next bit is a kludge."

Further on down.

"OK, you can open your eyes now."

Lesson: Comments are nice, but they are not get-out-of-jail cards. Write crap, get smacked.

Point of no return

OK, time for one more story – this time from another reader called Peter:

I remember back in the late 1970s looking through some Honeywell Level 6 communications software and seeing an interesting comment in some assembler code.

After making an operating system call, it was customary to check the register R1 for errors and act according to the value returned from the call. At this particular point in the assembler code, no such check was made and the comment was:

"Error at this point too horrible to contemplate."

Lesson: You can be certain of two things in life, no wait, three: death, taxes, and errors. Always check for them.

Keep your awful code snippets and tales of woe coming in, please – we'll feature a selection every Wednesday. We'll finish off on some code your humble hack stumbled across this week. It's a bit long, so it's over on the next page.

Next page: Scream GNU murder

Similar topics


Other stories you might like

  • Robotics and 5G to spur growth of SoC industry – report
    Big OEMs hogging production and COVID causing supply issues

    The system-on-chip (SoC) side of the semiconductor industry is poised for growth between now and 2026, when it's predicted to be worth $6.85 billion, according to an analyst's report. 

    Chances are good that there's an SoC-powered device within arm's reach of you: the tiny integrated circuits contain everything needed for a basic computer, leading to their proliferation in mobile, IoT and smart devices. 

    The report predicting the growth comes from advisory biz Technavio, which looked at a long list of companies in the SoC market. Vendors it analyzed include Apple, Broadcom, Intel, Nvidia, TSMC, Toshiba, and more. The company predicts that much of the growth between now and 2026 will stem primarily from robotics and 5G. 

    Continue reading
  • Deepfake attacks can easily trick live facial recognition systems online
    Plus: Next PyTorch release will support Apple GPUs so devs can train neural networks on their own laptops

    In brief Miscreants can easily steal someone else's identity by tricking live facial recognition software using deepfakes, according to a new report.

    Sensity AI, a startup focused on tackling identity fraud, carried out a series of pretend attacks. Engineers scanned the image of someone from an ID card, and mapped their likeness onto another person's face. Sensity then tested whether they could breach live facial recognition systems by tricking them into believing the pretend attacker is a real user.

    So-called "liveness tests" try to authenticate identities in real-time, relying on images or video streams from cameras like face recognition used to unlock mobile phones, for example. Nine out of ten vendors failed Sensity's live deepfake attacks.

    Continue reading
  • Lonestar plans to put datacenters in the Moon's lava tubes
    How? Founder tells The Register 'Robots… lots of robots'

    Imagine a future where racks of computer servers hum quietly in darkness below the surface of the Moon.

    Here is where some of the most important data is stored, to be left untouched for as long as can be. The idea sounds like something from science-fiction, but one startup that recently emerged from stealth is trying to turn it into a reality. Lonestar Data Holdings has a unique mission unlike any other cloud provider: to build datacenters on the Moon backing up the world's data.

    "It's inconceivable to me that we are keeping our most precious assets, our knowledge and our data, on Earth, where we're setting off bombs and burning things," Christopher Stott, founder and CEO of Lonestar, told The Register. "We need to put our assets in place off our planet, where we can keep it safe."

    Continue reading

Biting the hand that feeds IT © 1998–2022