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

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 …

  1. AndrueC Silver badge
    Happy

    I reordered the words in it to isPenUp. I'll leave it to you work out the original variable name.

    Ha, ha. I always used to chuckle at an identifier that Microsoft came up with. Mind you it was the only thing that was remotely humorous about their shell API. Still, to a Briton, 'SHITEMID' does offer a small glimmer of pleasure while fighting the idiocy :)

    1. tiggity Silver badge

      I would have retained the original names

      Any vague scintilla of amusement in code is wlecome

      1. AMBxx Silver badge
        Happy

        Re: I would have retained the original names

        Plenty of accountancy systems with database columns called ANAL

    2. Anonymous Coward
      Anonymous Coward

      For additional genitalia-related chuckles, there's also .NET's System.Diagnostics.FileVersionInfo.FilePrivatePart.

      1. TRT Silver badge

        I had a user-written script for a National Instrument's interface box...

        that had a few subroutines for locking the binary output lines (TTL) at a set or held (clamped) state and then releasing or clearing them.

        BOLOCKS_SET, BOLOCKS_CLAMP, BOLOCKS_REL and BOLOCKS_CLR

        1. The Equestrian

          Re: I had a user-written script for a National Instrument's interface box...

          Once had to document a change to a report where the column "Cost Unit" had been added. The abbreviated column header: "C.UNT" - strange but none of the accounts people saw anything wrong with it!!!

          1. Anonymous Coward
            Anonymous Coward

            Re: I had a user-written script for a National Instrument's interface box...

            I once worked on a system where "Case Units" was a common measure. Many of the relevant variables started with the same letters as your column header, without the period. (No pun intended.)

          2. GerryMC

            Re: I had a user-written script for a National Instrument's interface box...

            20 odd years ago I worked with data from an old DOS Point of Sale. It was written in an in-house "database language" - (like dBase but worse). They used two character names for most of the files, so the stock file was st.dat, products pr.dat and customer cu.dat. Memo fields for each table were stored in "notes" files named by adding 'NT' to the file name, so stock was STNT.dat, products PRNT.dat and customers was ....

            1. Anonymous Coward
              Anonymous Coward

              Re: I had a user-written script for a National Instrument's interface box...

              Wasnt Sandmar was it?

          3. Glenturret Single Malt

            Re: I had a user-written script for a National Instrument's interface box...

            The full abbreviation C.U. was presumably used by Glasgow accountancy companies.

        2. Yag
          Gimp

          Re: I had a user-written script for a National Instrument's interface box...

          BOLOCKS_CLAMP? sounds painful.

    3. Anonymous Coward
      Anonymous Coward

      I built a manufacturing system which has the concepts of production lines which are manual (Hand Lines) and production lines which are machine-based (Machine lines)

      There is now a flag called MachineJob = [TRUE|FALSE] the flag was initially used for the inverse purpose, I'll leave it to you to work out why we changed it...

    4. JQW

      Back in the early 1990s I was involved in supporting an obscure RDBMS. Application code ran on MS-DOS PCs which communicated with a central server, which at the time seemed to be the only one which ran on our cranking server operating system. The resultant code was fairly huge, particularly if you elected to use their optional DOS text menu API.

      As code was compiled on MS-DOS systems the various development files had 8.3 file names with fairly sensible names. The standard include files for the various APIs all had 6 letter file-names - the SQL API was SQLAPI.H, and SQLAPI.LIB for example.

      However for development testing purposes they also provided a standalone server that ran in the background on a development PC. To compile against this meant substituting some of the API files with their standalone server variants, which meant adding the letters SS to the end of each include and library file - hence SQLAPISS.H and SQLAPISS.LIB.

    5. Snivelling Wretch

      I remember once foolishly choosing the variable name "TotalCount" - and would constantly mistype with profanity...

  2. Mike Pellatt
    Joke

    Yabut... The BSD implementation of true(1) doesn't give you any help. A serious omission, IMHO.

    1. This post has been deleted by its author

      1. SolidSquid

        man true: returns true

        1. Colin McKinnon

          > man true: returns true

          So does `man false`

      2. LionelB

        The Linux TRUE(1) man page magnificently sums up my day so far: true - do nothing, successfully.

        1. Androgynous Cupboard Silver badge

          man true.

          Comrade, the FSF would prefer you run "info true". It's quite easy, there is some documentation on how to use it. Just type "info info".

    2. John Robson Silver badge

      More importantly the BSD implementation fires up a whole new shell to return 0.

      If you need truth to be repeatedly called, lots of times, then there might be a benefit to something compiled - but there is still no justification for the other approach.

    3. Rusty 1
      WTF?

      The BSD implementation is on version 1.2. Just how wrong were versions 1.0 and 1.1?

    4. Soruk

      The Solaris version of /bin/true was a shell script where every single line was a comment, first of which was a warning that it was unpublished proprietary source code belonging to AT&T.

      (This was about 10 years ago when I saw this, my memory could be a little hazy.)

      1. Jonathan Knight

        A zero byte executable file will (by default) be run by the shell, which returns 0 (true). Old versions of unix (version 7 et al) would have /bin/true as a zero byte executable file.

  3. JeffyPoooh Silver badge
    Pint

    All these coder drones are now...

    They're all now working on 'self-driving' cars.

  4. Doctor Syntax Silver badge

    A long time ago I had Microsoft FORTRAN for CP/M. It came with some assembler source for a library or something. In it was a comment from one programmer to another to the effect of "I can't get this to work, can you?"

  5. Anonymous Coward
    Anonymous Coward

    Tailes from the support desk

    A customer sent in this complaint as a bug in the C compilers optimizer. When they were developing their code it all worked but when they finsihed and compiled with the -O option it all fell apart.

    The problem boiled down to them having 2 processes communicating using shared memory and having a line of code which read

    while(flag); (The other process used while (!flag);

    Where flag was in the shared memory. This was back before ANSI C so no volatile option. The optimiser just thought that since flag was being used a lot it may as well keep a copy in a register.

    I asked the customer what their CPU usage was like. Oh 100% but it's a big complex program and I've already bought the fastest system you make. I sent him an example of a semaphore.

    In terms of cutNpaste errors lots of terminal emulators replace tabs with spaces and occasionally this makes a difference.

    I remember a case where a lab engineer was asked to patch the sendmail.cf file (tabs are important here) and just pasted the lines in they were given and sent it out without actually doing the tests and then wondered why all the customers email systems broke.

    In terms of comments, above a particular section of code was a comment /* Yuck, this sucks but we release on Monday and we need to have something */

    1. Anonymous Coward
      Anonymous Coward

      Re: Tailes from the support desk

      > /* Yuck, this sucks but we release on Monday and we need to have something */

      Yep, indeed. As a deadlines approach, my comment-this-block-out shortcut goes into overdrive (generally, I try to postpone new features or even bug fixes until they have been properly validated, though not everyone has that luxury).

      Speaking of which, I better fire up the IDE.

    2. Trixr Bronze badge

      Re: Tailes from the support desk

      Regarding the Sendmail snafu, all I can say is thank god for Postfix. Everytime I see a Sendmail config, I say it again. Over and over.

      1. Dazed and Confused

        Re: Tailes from the support desk

        OH but sendmail.cf is a truly beautiful thing. You just need to remember that Eric was a poor student and therefore obsessed with dollar signs.

        Configuring was lovely to people started messing it up with bloody macro languages, I could never get my head around why anyone would want to use M4 let alone worry about how it worked.

        I remember teaching one OpenMail class where a student's company had paid serious bucks for a couple of different consulting companies to get something done differently in their sendmail config only for them to eventually say it was impossible and send in a big bill. He was late in the morning when we covered sendmail.cf and arrived while I had everyone doing labs. I sat him down and walked him through it, then added 1 line to the file and got it doing just what they'd been asking for.

        Then again I was always being told my head was screwed on wrongly.

  6. Anonymous Coward
    Anonymous Coward

    Code Review

    RE: That SQL where code block...

    My eyes...

    What happens when they want 10 or 11 where clauses?

    Is it a paid CCN (Contract Change Note)?

    Who reviewed the code and why is it not in a function?

    1. hatti

      Re: Code Review

      if ( reviewer == coder ) {

      return 'omit code review stage';

      }

    2. Anonymous Coward
      Anonymous Coward

      Re: Code Review

      I'm quite sure that's code from a Delphi developer. You'd be surprised how many of them write code like that. Once I was assigned an application to manage insurance agents for a large insurance company, written in Delphi.

      Each release I made added new features and code shrinked, up to the point the people installing it on the insurance company PCs asked me why each new version they were installing was actually smaller than the previous one - they were expecting the opposite..

      The reason is for each release I started first by heavily refactoring the old code of the portion I was going to modify, and eliminating all the duplicated and truly useless stuff (to ensure it coudn't bite back)... the bad thing of easy-to-use progamming languages and tools it's they give access to development to a lot of people with very little clues about true programming best practices - and cut&paste is the quick way to add new code, isn't it?

      At least then there was no stackoverflow and "developer" blogs, and thereby there were less of the s*****y code I see today blatantly copied from some other clueless developer... regardless of how many "meee toooo" votes it got.

      1. Anonymous Coward
        Anonymous Coward

        Re: Code Review

        > At least then there was no stackoverflow and "developer" blogs, and thereby there were less of the s*****y code I see today blatantly copied from some other clueless developer... regardless of how many "meee toooo" votes it got.

        /bin/true to that. Amazing how popular shitty code is in some corners of StackOverflow. The other thing over there is that "votes" do not seem to expire over time, and in some technologies what was a great solution five years ago is now obsolete twaddle (typically some ungodly hack because technology X lacked feature Y at the time), yet is still comes out at the top of your searches and, what's worse, in new code which has zero need for it.

        1. Robert Carnegie Silver badge

          Re: Code Review

          I got caught out by reading something on a support blog.

          "Why does powershell 4 automatically convert my UTF-8 text to Unicode?"

          That was what actually I wanted it to do.

          But it doesn't. It just treats it as ASCII or ANSI or something.

          Powershell 5 does allow e.g.

          powershell -version 5.0 -command "&{gc -encoding utf8 euro-utf.txt | sc -encoding unicode euro-ucs.txt}"

          I am going to need a little more than that though. Specifically, arbitrary input file name, e.g. to be dropped onto the CMD file. I can have four of those, because I want four output files.

        2. Anonymous Coward
          Anonymous Coward

          Re: Code Review

          ... As well as the shitty & useless Linux-advice on StackOverflow & Co echo-chambered and propagated by leech-sites all over the internet: "Z doesn't work" - "try A", "try B", "try C", "try D", "try E", Try and effing Try, until "Now it works" OR "Silence". Whatever random shit that happened to be the last "try" in the chain becomes "The Solution" to the problem where the cause was never discovered.

          Gone are the happy old days of rational thinking and check-lists: "Z probably doesn't work because Y isn't running or maybe Q needs to be installed. First check Y, then ...."

          FreeBSD is much better than Linux on this point (and many others).

      2. KimMadsen

        Re: Code Review

        Bad form to bash Delphi developers, just because there are examples of bad Delphi code.

        Ive seen plenty of bad code in Javascript, C#, C, C++, Java, but I dont bash developers using those languages in general.

        In fact the absolute majority of all these bad code examples are in anything but Delphi.

        Check:

        https://www.reddit.com/r/badcode

        http://c2.com/cgi/wiki?BadCode

        http://thedailywtf.com/

        1. Anonymous Coward
          Anonymous Coward

          Re: Code Review

          It's not just for that code, because I happened to be a Delphi developers as well and I worked with many of them. Delphi was an excellent tool and language - when used properly.

          I was just pointing out how some tools and languages may have attracted a lot of people who never learnt to code properly just because it is easier to code something somewhat working with them. It was true as well for Visual Basic in the old days, and today for PHP and Javascript. Learn a few basci blocks, cobble something together, and it looks to work.

          It is also true I've see my share of bad programmers in other languages, for example I've see one using C++ as if member functions didn't allow parameters and everything should be exchanged through class fields (very much alike "local-global variables") - which he was also using as if they were CPU registers. Just, in some languages is far easier to be caught because they are more complex and with less safety nets and ready-to-use components.

        2. 9Rune5

          Re: Code Review

          In the Delphi code example, the one with lots of code redundancy, in what development language would such code be impossible to write?

          In C# developers are strongly encouraged to use a StringBuilder object to concatenate strings (surely a result of having slower performing string performance than Delphi...), but that does nothing to prevent this particular type of code rot. I've certainly seen a lot of messy C# code around.

          Delphi is a strongly-typed development language underpinned by a fast compiler/linker (unless that changed after introducing support for generics?). These days I favor C#, but that is mostly down to practical reasons, not due to any technical shortcoming of Delphi (though they still lacked generics, unicode and 64-bit support back when I stopped using it, but those features have since been duly implemented afaik and I expect they have something similar to LINQ too).

          1. Buzzword

            Re: Code Review

            > in what development language would such code be impossible to write?

            You couldn't write like that in a functional language, such as Lisp or F#. Actually in F# you could just use the StringBuilder, but it goes against the ethos of the language.

            1. Michael Wojcik Silver badge

              Re: Code Review

              You couldn't write like that in a functional language, such as Lisp or F#.

              That's not correct. The original example (the copy-pasta) works just fine with a purely functional language - it needn't mutate any objects, as written. It can create a new string object for each concatenation, and indeed that's what will happen with any language that has immutable strings, including anything in the LISP or ML families (like F#), or any JVM- or CLR-based language.

              It's performing destructive assignment, but that just changes what value the variable is bound to, not the object itself. In a pure functional language, you wouldn't be able to do that - you'd have to rewrite the code slightly to return the new string each time rather than assigning it to the same variable (or assign it to a new variable each time, which would be uglier but work just the same).

              Neither most LISP variants nor F# (or most other ML variants) are purely functional. LISP has the "set" family of special forms, for example.

              The actual series-of-if-statements style is procedural, not functional; but converting it to functional form is trivial and could easily be automated in a functional language as syntactic sugar.

              The hip way to do it these days would be with a list comprehension - think a string join operation with the literal " AND " as the delimiter, filtered with "length > 0" as a predicate. And list comprehensions are notionally purely functional, though the actual underlying implementation may operate on a destructive temporary.

        3. Daniel von Asmuth
          WTF?

          Re: Code Review

          Bash is the name of the language I currently develop in:-(

      3. MJI Silver badge

        Re: Code Review

        I once merged a lot of code into one set, replaced around 60 tab pages with ONE base version inheriting into 10 so specific ones.

        Shrunk by a lot and so much easier for ME to maintain.

        The original writer found it confusing, but I did have to add a new feature to every page, took about 40 minutes rather than hours

      4. Anonymous Coward
        Anonymous Coward

        Re: Code Review

        Every time I see code like this I have to remind myself that there was a time when many programmers were judged more on the number of lines of code they produced (and how quickly) rather than on the quality of that code. So in that case they might actually get penalized for producing good, tight, easily-maintained code. This may still be true in some places.

    3. The First Dave Silver badge

      Re: Code Review

      To be honest, I'd rather see code like that, than the 'optimised' code that same person would have written if pushed...

      1. IsJustabloke

        Re: Code Review

        Yes normally its optimzed to the point of being unreadable :/

        I do so enjoy working on a big pile of c# carbonara

        1. AndrueC Silver badge
          Happy

          Re: Code Review

          Resharper > Part of loop's body can be converted into a LINQ-expression

          Developer > Go on then..hey, cool!

          {a bit later}

          Resharper > Part of loop's body can be converted into a LINQ-expression

          Developer > Go on then..this really is neat.

          {a bit later still}

          Resharper > Part of loop's body can be converted in to a LINQ-expression

          Developer > Oy, Bill! Come and look at this..'click'.

          Developers > What the <censored to protect the innocent>. Okay, let's not always do that, okay?

  7. Alan J. Wylie

    /bin/true copyright: http://trillian.mit.edu/~jc/humor/ATT_Copyright_true.html

    and "You may want to close your eyes, the next bit is kludge." reminds me of the classic UNIX comment "You are not expected to understand this"

    Unfortunately the UNIX Heritage Society and Bell Labs sites archiving Dennis Ritchie's comments seem to have suffered from bit-rot.

    1. Anonymous Coward
      Anonymous Coward

      > http://trillian.mit.edu/~jc/humor/ATT_Copyright_true.html

      Cool link that one! It also explains the reason for the difference between the BSD and Linux versions.

      Interestingly, /bin/true in my systems is up to versions 8.21 to 8.24, variously. I'm tempted to search the bugtracker see what has been fixed.

    2. 2+2=5 Silver badge

      > reminds me of the classic UNIX comment "You are not expected to understand this"

      For the younger readers, this comment is present not because the code it relates to was particularly complicated but because the source comprised part of the Computer Science degree course at Berkeley at the time. The comment was to let the students know that that piece of code wasn't part of the syllabus and they didn't need to learn it.

      Proof that even the industry pioneers we look up to find it hard to write unambiguous comments. :-)

    3. JBowler

      See here

      I think this is what you are referring to:

      https://blogs.oracle.com/DaveEdstrom/entry/you_are_not_expected_to

      I..e. it means what anyone who has been doing this long enough understands it to mean, "I don't have the faintest idea what is going on here, but it seems to work."

  8. Anonymous Coward
    Anonymous Coward

    true - do nothing, successfully

    false - do nothing, unsuccessfully

    Kind of a metaphor for life.

    1. Old Handle

      But since false actually does do nothing, that seems incorrect. Shouldn't it be:

      true - does nothing, successfully

      false - fails to do anything

      1. BasicChimpTheory

        Yep. If to unsuccessfully do nothing would be to do something then False would be false.

  9. Reginald Marshall

    That quip about hard things in CS...

    I prefer the version which says that yes, there are two hard things in computer science, and they are cache invalidation, naming, and off-by-one errors.

    1. TRT Silver badge

      Re: That quip about hard things in CS...

      There are only 10 kinds of people when it comes to understanding binary...

      1. Peter2 Silver badge

        Re: That quip about hard things in CS...

        There are only 10 kinds of people when it comes to understanding binary...

        I have always thought it's more accurately actually 11 kinds of people.

        1) Those who understand binary.

        2) Those who don't.

        3) Those who understand the theory and can explain the concept to others, but then proceed to put the numbers in the columns back to front because last time they had to do anything in binary was (equivalent to) two lifetimes of the new entrants to the workplace ago.

        1. Geoff May

          Re: That quip about hard things in CS...

          @Peter2 - it isn't funny if you have to explain it.

      2. BasicChimpTheory

        Re: That quip about hard things in CS...

        BOOOOOO!!!! @ TRT

      3. PDurrant

        Re: That quip about hard things in CS...

        as a purist there is only 1 type of person that understands binary, ---- zero or one, but that wouldn't give the unknowing a clue

        Paul

      4. shraap

        Re: That quip about hard things in CS...

        There are 10 kinds of people in the world...

        * Those who understand binary

        * Those who do not

        * Those who weren't expecting a Base 3 joke.

        1. Fibbles

          Re: That quip about hard things in CS...

          There are in fact only 2 kinds of people in the world. Those who can extrapolate from incomplete data.

  10. Chewi
    Linux

    Size doesn't matter

    Say what you like about the GNU version but it is 0.002 seconds faster.

    time /bin/true

    /bin/true 0.00s user 0.00s system 79% cpu 0.001 total

    time ./true

    ./true 0.00s user 0.00s system 88% cpu 0.003 total

    1. d3rrial

      Re: Size doesn't matter

      int main(int argc, char** argv){ return 0; }

      Does the exact same thing and it's also 0.001 in time.

      1. Anonymous Coward
        Anonymous Coward

        Re: Size doesn't matter

        > Does the exact same thing

        No it doesn't. It does not provide help, version number, or attribution. And it uses a magic number.

        1. BasicChimpTheory

          Re: Size doesn't matter

          Upvoted for the pedantic callout on the magic number.

        2. D P Duck

          Re: Size doesn't matter

          This is very tr..? How did that command work again?

    2. Anonymous Coward
      Anonymous Coward

      Re: Size doesn't matter

      Which makes a difference seeing as true is often used in infinite loops.

      Anyway, I've profiled these three scripts:

      (./bsdtrue.sh is a copy of the BSD code shown in the article)

      #!/bin/bash

      C=0;

      while ./bsdtrue.sh; do

      C=$(( $C + 1 ))

      [ $C -eq 1000 ] && exit 0

      done

      Using the /bin/true binary

      #!/bin/bash

      C=0;

      while /bin/true; do

      C=$(( $C + 1 ))

      [ $C -eq 1000 ] && exit 0

      done

      Using the Bash built-in (hence why calling specifically Bash, though it's also my default shell)

      #!/bin/bash

      C=0;

      while true; do

      C=$(( $C + 1 ))

      [ $C -eq 1000 ] && exit 0

      done

      > time ./test0.sh # BSD true

      real 0m10.125s

      user 0m4.716s

      sys 0m4.004s

      > time ./test1.sh # GNU true

      real 0m3.211s

      user 0m0.276s

      sys 0m0.668s

      > time ./test2.sh # Bash built-in

      real 0m0.081s

      user 0m0.072s

      sys 0m0.004s

      As you can see, the second and third options allow you to do nothing a lot faster to BSD's doing nothing slowly. That's why busy nihilists love Linux.

      1. Anonymous Coward
        Anonymous Coward

        Re: Size doesn't matter

        The K&R version: magic numbers, implicit int type, no superfluous args...

        main(){return 0;}

        1. the spectacularly refined chap

          Re: Size doesn't matter

          No, it would be:

          main(){}

          No need for an explicit successful return, it's implied. It's also (theoretically) more portable if you ever encounter some system where success is indicated by something other than 0.

          1. Anonymous Coward
            Anonymous Coward

            Re: Size doesn't matter

            Dangerous, I accidentally did this once and it occasionally (sun forte compiler,) returned a non zero value, took me a couple of days to track down why it was going wrong!

          2. Anonymous Coward
            Anonymous Coward

            Re: Size doesn't matter

            Sir,

            > if you ever encounter some system where success is indicated by something other than 0.

            I have downvoted your comment in the name of everyone who was around comp.lang.c in the nineties.

  11. Kubla Cant Silver badge

    Horrible, but maybe unavoidable

    The sample code that laboriously build a where clause is truly horrible. But it's quite possible that it isn't that way because of the developer's addiction to copy-n-paste.

    It looks like it's using the stored procedure language from a database. In their early incarnations these languages frequently didn't support any kind of array or collection, and they were often syntactically feeble, making it hard to do the kind of abstraction that is usual in proper programming languages.

    1. Ben Bonsall

      Re: Horrible, but maybe unavoidable

      Looks like Delphi to me... But the title still stands.

    2. Anonymous Coward
      Anonymous Coward

      Re: Horrible, but maybe unavoidable

      This doesn't look a Pascal-based procedural language like Oracle PL/SQL, this looks like Pascal (probably Delphi) code. PL/SQL IF blocks are terminated by END IF and don't require the begin..end blocks.

      This looks a symptom of bad copy&paste, lack of knowledge of proper containers (arrays, lists, etc.), sloppy variable naming, and probably lack of security - that code may be easily vulnerable to SQL injection.

      1. redtux

        Re: Horrible, but maybe unavoidable

        Actually its probably TSQL. And this sort of appraoach is actually reccomeded by a lot SQLServer bods (and also why not in a function - RBAR)

  12. Anonymous Coward
    Anonymous Coward

    What is deceptively true ...

    ... is that the GNU version is vastly more efficient. It'll make a massive difference if called a few thousand times in quick succession.

    Also, kudos to the author for pointing out the edge case where /bin/true may, in fact, return false.

  13. paulc

    one of our 'comments'

    //This works, but nobody can explain why it does...

  14. Sil

    WAT

    High-end c++:

    int main(){<:]()<%[](){[:>()<%}();}();}();}

    From the hilarious C++ WAT presentation of Piotr Padlewski at CppCon 2015

    https://youtu.be/rNNnPrMHsAA

  15. oneguycoding

    Of course, to be fair, the gnu implementation of true is also false. And it's compiled. Perhaps you should also post the code to the exit() function for the 'exit 0' code in the somewhat glib BSD example.

  16. Michael H.F. Wilkinson Silver badge

    In a desert-like piece of Pascal code, devoid of any real oases of comments, with single-letter variable names throughout, and naturally lacking any proper documentation, I came across a lonely comment

    (* Wulf *)

    And no, that wasn't the culprit's name. If he is reading this column, he will know I am talking about him. Having said all this, I could by dint of quite some effort make sense of his code (which algorithm-wise and structurally was fine), but I can still recognize those bits of code I contributed to that system after decoding his work: My variable names grew longer, my comments more detailed, my documentation actually existed!

  17. Simon Rockman

    It's all about the annual review

    One company i worked for measured programmer performance by the number of lines of code written.

    You'd get marked down for elegance.

    That's what happens when you have people who can't code in charge of coders.

    And I was one of them.

    So the coders in my team made me write a little bit just to go all the way through using the dev system.

    Simon

    1. Fibbles

      Re: It's all about the annual review

      Did they strip comments before counting the lines?

      "Why does this function contain a sci-fi novella?"

    2. JeffUK

      Re: It's all about the annual review

      Message_First_Word = 'H' + \

      'e' + \

      'l' + \

      'l' + \

      'o'

      etc. etc.

    3. BasicChimpTheory

      Re: It's all about the annual review

      "One company i worked for measured programmer performance by the number of lines of code written."

      Story points are okay.

  18. 1Rafayal

    The worst thing is when a junior dev commits a howler to SCM that passes a code review conducted by an architect. I have encountered that a couple of times, when I ask the architect in question how the review was undertaken I was told "I just approved it, once its in prod its a support issue.".

    Go team.

  19. Flocke Kroes Silver badge

    Shorter true and true that returns false

    Back in the dawn of time, true was an empty file. The OS interpreted it is 'do nothing', which it was always able to do, and returned success. Then there were lawyers who ordered everything to have a copyright notice. You can see the results here. Note that the AT&T version does not start by identifying the required interpreter. The OS sees the file is not empty, so clearly it has to do something, but has no idea what it is. As the OS cannot execute AT&T's true, it returns failure!

    Sun licensed AT&T true (anyone know how much true costs?), and fixed the bug for Solaris.

    It could be worse: man echo.

    1. the spectacularly refined chap

      Re: Shorter true and true that returns false

      The OS sees the file is not empty, so clearly it has to do something, but has no idea what it is. As the OS cannot execute AT&T's true, it returns failure!

      It knew exactly what to do - early Unix would always pass an executable in an unrecognised format to the shell for interpretation so it was a well-defined semantic. Problems only arose when csh was introduced and that was covered by a magic value: if the first byte matched (may have been % but don't hold me to that - it's along time ago) it went to csh, otherwise sh. #! is a surprisingly late addition to Unix. ISTR It first appeared perhaps 1988 or 89 but it wasn't universal until the mid nineties.

  20. fruitoftheloon
    Happy

    Humbled by two error codes...

    This is a little off-topic, but related...

    Aeons ago (I had hair) we were attempting to get a Sun 3/60c talking to a Vax 11/785, we were steadily climbing our way up the chain, towards the end of the 'process' the 3/60c put this on the screen:

    "Are you sure you really know what you are doing?", clearly we didn't, well not for a while anyway, so we took the message as a hint that we should go to the pub.

    After lunch it shared this gem: "I am not entirely sure what you are looking for, but I am pretty sure it's not out there..."

    Memory may have failed a bit (it was ~28 years ago), still makes me giggle, mmdv.

    Cheers,

    Jay

  21. Anonymous Coward
    Anonymous Coward

    Leap year....

    Back in 1992 I had to fix a problem in a PL/1 program that was checking if it was a leap year. The program was written in 1986. The code (I forget the syntax, too long ago) was something like :

    leapyear = false

    if (year = 1988) then leapyear = true;

    So it ran for 6 years until it failed. I guess the author never expected it to run that long.

    AC, because I still work for the same company, although PL/1 is long gone :)

  22. Anonymous Coward
    Anonymous Coward

    Honestly, I can write good code, just not that day.

    It's fun to laugh at bad code, but can anyone honestly say they've never been guilty multiple times. Just look at some code you wrote 10 years ago and feel yourself cringe.

    It's Friday, deadline fast approaching, and you think to yourself I'll tidy it up in the next release but that of course never happens and because it works you happily forget about it. Then a few years pass and that spotty faced junior programmer stumbles across it and you quickly have to think of a good excuse to stop him thinking what all junior programmers think "What a dinosaur, shouldn't be allowed near a computer."

    This of course fails and you spend the the next 3 months desperately trying to find fault with any code they've written to try and regain some credibility.

    I'm not bitter about it at all, but wait till the ba£$%rds annual review, i'll show him.

  23. Graham Bartlett

    My favourite typos

    I literally don't know how many times I've mistyped "bugger" instead of "buffer". Mostly I catch them. Occasionally they make it through to code review. I've only once had it get out to customer code though.

    My most annoying one though was at a company who were subcontracted to Ford in the early 2000s. Ford had coding standards which had been set sometime in the mid-80s and never really tweaked. The result was that we were limited to 16-character variable and function names. By the end we'd found that Ford engineers were breaking this rule with impunity so we stopped worrying about it, but at the start we had to stick with it because we were under the microscope a bit. This was harder for us, because every variable had to start with the name of the module (in my case "ipc_") and our double-stored variables (this was safety-related so we needed to detect data corruption) were suffixed "_ds". This left 9 significant characters, so abbreviation was a fact of life.

    Where this went wrong was that one engineer with a fairly loose sense of humour decided to abbreviate "done" to "dun" to save one character in the variable name. We were doing silly hours, so at the time we all thought "hey, it's quirky, we'll keep it". Two years down the line, when I was having to do presentations on how to integrate our code with Ford engineers and their managers and their managers' managers, and the codebase was locked down and couldn't be changed, the joke looked a bit less clever.

    1. BasicChimpTheory

      Re: My favourite typos

      "I've only once had it get out to customer code though."

      Ha!

      Back in my uni days, "debugging"/"testing" consisted of console echo/printf/println/etc messages.

      In order to make sure none of my hacky "debugs"/"tests" made it through to an assignment submission I constantly made sure the console messages were as vulgar as humanly possible. How could I leave that in the code?

      I recall a particularly bitter exchange with a professor who marked me down on working code for some reason...?

  24. Dave 32
    Pint

    IEFBR14

    For a real howler, look up the story of IBM's IEFBR14 routine. Nuff said.

  25. Dave 32

    Temporary Fix

    Not too many years ago, I was doing some maintenance on a compiler, and came across a comment which stated:

    /* The following two lines are a temporary fix for the xxxxxx problem 11 September 1971*/

    I wisely decided that a temporary fix that was old enough to drink legally wasn't one that I wanted to touch. As far as I know, that temporary fix still exists!

    Dave

    1. Anonymous Coward
      Anonymous Coward

      Re: Temporary Fix

      There's a comment like that in an application I wrote. It was added when I turned a DOS batch program into a DOS "windows" mouse interactive version in short order to satisfy my internal users. That was in1990.

      The comment says something like "This interactive mechanism will do until I find a better way to do it". Revisited the concept several times - but always had to admit that first method worked extremely well.

      It became the yardstick with which to measure the limitations of equivalent commercial Windows products. It still works well after the application was turned inside out to be a Windows Console application. Turning it into a true Windows application worked - but was just too clunky.

  26. Anonymous Coward
    Anonymous Coward

    /bin/false

    http://ieeexplore.ieee.org/iel7/52/7057030/07057573.pdf

  27. Anonymous Coward
    Anonymous Coward

    One of my comments

    One day my company suddenly denabled a source code style checker when checking in. It checks for copyright, tabs and curly brackets in the "right places".

    And here was what I wrote at that check in after adding a fail-safe part and seeing red from the checker:

    "Conforms to the "coding style" - doesn't make it more readable of course or bugs free.

    And if you can't read unformatted code then you should not be a programmer/coder.

    Also the (c) after Copyright is not recognised legally. Use © instead and you may stand a chance."

    It took me over 10 minutes to move the curly brackets from it's own line to one space after the "if", "do", "when", "for", etc. Also I needed curly brackets around a single statement too.

    Yes, you guessed it, I hate coding style, especially when a single person imposes them onto the rest of the company.

    Incidentally, the "best" comment I have written while debugging some awful code was:

    "If you can't do simple maths then don't bother with programming". It has a huge switch statement on some variable N to create a string of N zeros (1 to 10 iirc). I replaced it with a single line of course.

    Anon just in case they are reading :P

  28. David Bird

    Too horrible to contemplate

    I wrote communications software in assembler for Honeywell Level 6 in the late 70s. I am fairly sure this isn't one of mine...

  29. Pomgolian
    Pint

    I once had to write a report for a service management application, that produced a list of outstanding service exchange jobs. Being limited to an 8 character name space resuted in O S EX JOBS, or as it became known, the SEXJOBS report.

  30. Anonymous Coward
    Anonymous Coward

    Original Unix version of 'true'

    Well, it's unprintable, but here's how to generate it:

    # touch /bin/true

    # chmod 0755 /bin/true

  31. eswan

    "It's said that there are only two hard things in computer science:

    cache invalidation and naming things." And off by one errors.

  32. Deltics

    const

    QUERY1 = 'SELECT .... blah blah blah':

    QUERY2 = 'SELECT .... blah blah blah':

    // etc

    function GetQueryText(aQueryName: String): String;

    var

    sQueryName: String;

    begin

    sQueryName := Uppercase(aQueryName);

    if sQueryName = 'QUERY1' then

    GetQueryText := QUERY1

    else if sQueryName = 'QUERY2' then

    GetQueryText := QUERY2

    else if sQueryName = 'QUERY3' then

    GetQueryText := QUERY3

    else if ....

    etc etc

    end;

    And there were dozens and dozens of constants that this runtime constant lookup function helped resolve.

    Give. Me. Strength.

  33. Mike 16 Silver badge

    Hardly Horrible

    The sources for DEC's RT-11 (Real Time OS for PDP-11) contain many comments that reference Gilbert and Sullivan. For example, the block comment above the code that twiddles the console lights in the idle loop was "A source of innocent merriment". This was of course a very important piece of the OS, as the various OSes for the PDP-11 each had a distinctive pattern. Unix had the dullest and most useful, IIRC. It read the console switches and displayed the contents of that location (from kernel space or the current user space, depending on the lsb). I never had the nerve to examine the kernel space address that mapped to the console UART data register.

  34. GreenJimll

    Source code control fun

    Many years ago I was doing some contract work for a company that was one of our suppliers (which was OK with my bosses as we were also one of its shareholders - its was a complex relationship). I was at their offices and was finally given access to their source code to help track down a bug we'd been experiencing.

    The first source file I opened up had an SCCS control header comment in it detail the name of the file, when it was last checked out, etc. That's good I thought - at least we can go back through the deltas to see where the bug appeared from and why. But my hunting took me from that source file to another. And this file also had an SCCS header comment.

    The same SCCS header comment.

    The _exact_ same SCCS header comment.

    I quickly looked through several other source files of the many in the directory and they all had exactly the same SCCS comment at the top, referencing the name of the first file I'd looked at (which was the entry point for this program). I queried one of the development managers there and he was pleased to confirm that they had used SCCS for some years, after another contract programmer had showed them it. Except by "use" he meant that all of them just cut and pasted the same comment template at the top of each new source file and sort of assumed that some deep magic then kept track of the file, without ever really understanding how source code control systems in general, and SCCS in particular, worked.

    When I explained it to him and a few other programmers there I could see the life force draining out of them. It always amazed me even back in the 1980s that Universities and Polys never seemed to mention version control systems to their students.

  35. el_oscuro

    badsql.sh

    I hate copy and paste. It is better to use a script to generate your code:

    #!/bin/bash

    for i in 1 2 3 4 5 6

    do

    (echo " if Length( Where$i ) \> 0 then"

    echo " begin"

    echo " if Length( WhereClause ) \> 0 then"

    echo " WhereClause := WhereClause + \' AND \' \;"

    echo " WhereClause := WhereClause + Where$i\;"

    echo " end\;") >> run.aspx

    done

    # Now to test our SQL logic in our website

    wget 192.168.1.2/run.aspx?q=robert'; drop table students; --

    1. Soruk

      Re: badsql.sh

      Upvoted for the Little Bobby Tables reference!

  36. Dick Pountain

    Oh Bollox!

    I'm in the habit of using "Bollox!" instead of "Hello World!" as my first program example when reviewing a new system (blame my upbringing). Back in PCW days, around 1983, was given Tandy's Model 100, an early handheld computer to review, and time being short had to take it straight to the photographer's studio. Regrettable it still showed "Bollox!" clearly on its small LCD screen, but no-one noticed till after it was printed. Reprinting is surprisingly expensive.

  37. JBowler

    Variable names should be self documenting

    Is Pen Up? Is a question.

    Pen Is Up. Is a statement.

    Get A Life is one too.

  38. Oengus Silver badge

    Assembler days

    The Assembler I used in the early days of my programming life had a limit of 8 characters name. We had a naming standard that the first 2 characters of the variable name described the data type which left 6 characters for the descriptive part of the variable name. This naming convention was carried to other modules used across various programs.

    ST stood for Standard Table (a shared table that was centrally maintained and could be accessed by any application). One day we were asked to create a new standard table for a list names of Credit Unions. We had to come up with a name and definition to put to the committee that approved the shared modules. The front runner was "Credit Union Name Table".

    The standards review board rejected the name. :)

  39. Potemkine Silver badge

    You can be certain of two things in life, no wait, three: death, taxes, and errors.

    No true for taxes, if you are rich enough.

  40. Dallas IT

    I have an app I wrote that distributes "scoops" about company activities to people within our company. One of the variables is a hash of which people within my company should receive these scoops - it's named "pooperscoopers".

  41. Anonymous Coward
    Anonymous Coward

    Not worth your while...

    I was debugging some service code for a telco app. I had to dig into the driver it was accessing to work out what was going on. I found:

    int i = 0;

    while(i < 10) {

    i = i + 1;

    }

    ...so I just went home.

  42. Anonymous Coward
    Anonymous Coward

    Can you guess?

    When working for a company a large portion of whose business was with the US in the era of "self-documenting" code and with an 11 character variable name limit, we needed to name a flag to filter out the units which weren't selling in the US. The full name of the flag was:

    commercial units nil in Greater US (i.e. incl Hawai and Alaska).

    Can you guess what we set the variable name to?

  43. pabc

    Anal Technique

    from my edit.php

    <tr<?php echo $alert;?>>

    <td valign=top>

    <p class=boxtext>Anal Technique

    </td>

    <td valign=top>

    <p class=boxtext>

    <select name=anal_technique>

    <?php

    // analyst

    $anal_technique_options=array("","UHPLC","HPLC","SFC");

    foreach ($anal_technique_options as $anal_technique_option){

    $selected="";

    if ($anal_technique_option==$anal_technique){

    $selected=" SELECTED";

    }

    echo "<option value=\"$anal_technique_option\"$selected>$anal_technique_option</option>\n";

    }

    ?>

    </select>

    </td>

    </tr>

  44. GrizzlyCoder

    I'll name that app in one...

    I contracted for a company who were supporting a Higher Ed management system called 'Banner' across 14 sites and no-one had had the wherewithall to write an app that would auto-login to each site in turn and allow the management of user accounts (drop, expire, create, etc.) across all the SaaS accounts. The team lead asked me if this could be done as I had already written an app that would run a script in each account and log the results, so I hacked the baseline user account control system to facilitate this, stuck on a reasonably user-friendly front end and gave it to him. I dubbed my app the "Banner User Management Utility" and named the executable by the acronym.... not sure if it's still in use but I left it with them...

  45. Anonymous Coward
    Anonymous Coward

    POS

    Used to work on a P.O.S. [as in retail] system in the mid 90s using a custom IBM BASIC compiler.

    A parade of consultants had touched the system's source code, but I'd often see:

    'DO NOT DELETE THE FOLLOWING LINE OR IT WILL CRASH

    followed by some string operation before calling a procedure.

    Well, that dev hadn't read the manual - which clearly stated that the WHOLE STRING, not a reference, was passed on the stack when calling a procedure....

  46. BaronMatrix

    Resume Builders

    I came later though initially used the mainframe terminal to type in BASIC... Used more managed code than un-managed... But that doesn't mean cut and paste can't make your C# life a damn nightmare, not to mention SQL, JS and HTML...

    I once saw some code where they were calling a DB to get user info in a Windows domain... The same place had SQL drawing HTML...

    The worst cut and paste was a major city's reporting web site... The dev copied and pasted a whole javascript module to extend Web Form.. Which anyone knows BREAKS THE DESIGNER...

    But I can say I don't check certain things like adding two known numbers...

    The DB was even worse... Some of the logic in a workflow made me nauseous...

  47. Spod

    This is not why copy'n'paste should be banned from developer IDEs. That just slows the idiots down or forces them to use another editor. However it IS why all developers should be given a coding test before hiring them... !

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019