• (disco)

    As a general rule, “dead code” should never be commented out, but instead, should be replaced.

    Removed, Shirley?

  • (disco) in reply to PJH
    PJH:
    Removed, Shirley?

    Well, I'd assume you still need the functionality when you refactor... So, tomayto, tomahto, removing old code and writing new in its place is pretty much the same as replacing.

  • (disco) in reply to Maciejasjmj
    Maciejasjmj:
    removing old code

    Old code yes, dead code...?

  • (disco) in reply to PJH

    What about

    It’s a beautiful little collection of ignorance, a willingness to do it the hardware, [...]

  • (disco)

    That catch throw in the uncommented code is not doing anything

  • (disco) in reply to GFK

    At least it's not swallowing it though

  • (disco) in reply to GFK

    I was going to mention that, too. A developer I used to work with did that all the time, he said it was to remind himself that he's calling a method that might throw an exception. I said "meh."

  • (disco) in reply to GFK

    Only reason I heard for doing that is, that it let's you set a breakpoint.

  • (disco)

    At my former workplace, there was a guy that used version control and commented dead code, simultaneously.

    This was, like.

    There's a problem to solve Let's invent and develop a clever solution A. Watch as solution A falls apart at some obscure corner cases that out of the blue, happen unusually often. Let's invent and develop a less clever solution B that works. Let's, though, keep the solution A that didn't work, around, because it was oh so clever and cute, who knows.

    This can also propagate to solutions C and D, if B proves flawed at some point.

    The bonus here is that for a developer that doesn't know exactly that all solutions besides the last aren't actually used for anything, there's a burden to maintain them all. Because it's hard to spot a dead, unused piece of code. It's all Perl, so I'm not kidding, it's hard.

  • (disco) in reply to GFK

    It's a mix of Pokemon Exception Handling (“gotta catch 'em all!”) and Zoologists Exceptions (“a measured programme of capture of critters and release of them back into the wild”).

  • (disco)

    FTA:

    swallowing

    :giggity:

  • (disco)

    This is a statement, not a question (even if it sounds like one, then it is a rhetorical one):

    In the context of refactoring, replacing, enhancing or whatever excuse you want to give: What is the difference between old code and dead code?

  • (disco)

    Actually, that's exception swallowing with regurgitation...

  • (disco) in reply to PJH
    PJH:
    Removed, Shirley?

    He is serious.

  • (disco) in reply to Shoreline
    Shoreline:
    PJH:
    Removed, Shirley?

    He is serious.

    and stop calling him shirley

  • (disco) in reply to wft
    wft:
    It's all Perl

    :theresyourproblem.pdf:

  • (disco) in reply to antiquarian

    Code hoarding can happen in any language.

  • (disco) in reply to wft
    wft:
    Code hoarding can happen in any language.

    Sure, but it's more fun to say bad things about Perl. :laughing:

  • (disco)

    my favorite anti-patterns: swallowing exceptions.

    no.... that's not what that code does....

    it doesn't swallow them at all.

  • (disco) in reply to accalia
    accalia:
    it doesn't swallow

    then it has no choice but to spit

  • (disco) in reply to accalia

    uh...

    // catch { }
    
    Does exactly the anti-pattern @Remy is talking about when commenting on the commented code.
  • (disco)

    Ugh... these damn post that make me click a link and read....

    Paula needs to post the article in a collapsible box like the forum software used to do.

  • (disco)
    CreateThumbnail(fulProfileImage.FileBytes, 400.0f, 400.0f);
    Specifying the dimensions of a bitmap using floats? WTF?
  • (disco) in reply to antiquarian

    The bad thing about Perl is that it is impossible for a tool (like Eclipse IDE) to immediately identify a piece of code, or a variable, or whatever, that is never used by anyone. So you think, it's better to mend that code along with others, because who knows what may need it, and looking for potential callers is a long and dull process. As a result, you spend time feeding a dead horse.

  • (disco) in reply to wft

    I'm not currently using Perl, but I have recently (last 2-3 years). My issue is exactly this. I use netbeans, and it is quite good at telling me that something is unassigned, or unused. It will (eventually) do the stuff with classes and functions and variables etc.

    but what it cannot do, and this is part of the problem with Perl is understand the concept of "include". So, just because a variable in the very old code don't appear to be used, it don't mean it isn't. Searching through the code base, and checking the program flow each time is a right royal pain.

    Oh bollocks

    As for the "use source control" attitude. I work with interpreted code. I use, what used to be known (and probably still is) Rapid Development techniques, but I now identify as a sorta Unit driven Agile variant (CBA to list all the Agile tickboxes I use).

    So: Code; Save; Click; Check; Code; Save; Click;Check....... is a damn sight faster than Code;Save;Compile;[loop on compile fail];Document;Store;Deploy;Run;Check

    THIS DON'T MEAN I DON'T USE CVS, I do. Once a day or week or project.

    The issue is removing the dead /old code before "Go Live" (translate into your own vernacular). The problem is, there very often is not time / budget for that - just like all that bitching about documentation elsewhere.

    :)

  • (disco)

    A fellow I work with does this a lot. Only, he'll also attempt to comment out a PHP block by surrounding it with a HTML comment.

  • (disco)

    There is a time for commenting out dead code, with additional comments; and that's when some other clueless developer thinks his code was right and has a tendency to put it back again.

    //some line of code //the line above does not work because.... //some line of code //the line above fails when....

  • (disco) in reply to xaade

    Just for you, I edit my Greasemonkey script...

    // ==UserScript==
    // @name        TDWTF
    // @namespace   custom
    // @description Makes comments visible and helps connect articles to their discussions better.
    // @include     http://thedailywtf.com/*
    // @include     https://what.thedailywtf.com/*
    // @grant       GM_xmlhttpRequest
    // run-at       document-end
    // ==/UserScript==
    
    try {
        function parse() {
            var d;
            if (d = document.getElementById("wrapper")) for (var e = [d]; e.length; e.shift()) {
                if (e[0].nodeType === e[0].COMMENT_NODE) {
                    with (e[0].parentElement.insertBefore(document.createElement(e[0].parentElement.tagName == "P" ? "span" : "p"), e[0])) {
                        e[0].parentNode.removeChild(e[0]);
                        with (style) {
                            fontStyle = "italic";
                            color = "#008000";
                            whiteSpace = "pre-line";
                        }
                        innerHTML = " " + e[0].data.replace(/<(?!\/?(a|b|strong|i|em|p|u|span|div)(\s|>))([^>]*)>/g, "&lt;$3&gt;") + " ";
                    }
                } else {
                    if (e[0].style) with (e[0].style) if (display == "none" || visibility && visibility != "visible") {
                        display = "";
                        visibility = "visible";
                        fontStyle = "italic";
                        color = "#008000"
                    }
                    if (e[0].hasChildNodes()) for (i = 0; i < e[0].childNodes.length; e.push(e[0].childNodes[i++]));
                }
            }
        }
        
        var a, d, p, t;
        if (a = document.querySelector(".discourse-link")) {
            a.target = "_blank";
            var req = new XMLHttpRequest();
            req.onload = function () {
                if (d = this.response.querySelector(".top-discourse-link")) {
                    a.text = "View Comments »";
                    a.href = d.href;
                    
                    GM_xmlhttpRequest({
                        onload: function (r) {
                            try {
                                a.href = r.finalUrl;
                                t = r.responseText.match(new RegExp("PreloadStore.store\\([\"']topic_.*"))[0];
                                var PreloadStore = {store: function (n, o) { t = o; }};
                                
                                eval(t);
                                var n = t.highest_post_number, l = t.last_read_post_number || 0;
                                
                                a.href += "/" + Math.min(n, l + 1);
                                a.text = "View " + t.posts_count + " Comments (" + Math.min(n - l, t.posts_count) + " unread) »";
                            } catch (e) {
                                console.error(e);
                            }
                        },
                        method: "GET",
                        url: d.href
                    });
                }
            };
            req.open("get", a.href);
            req.responseType = "document";
            req.send();
        }
        
        if (p = document.querySelector("meta[name='description']").content.match(/^(?:Discussion.*)(http:.*)$/)) {
            function inspect() {
                try {
                    var d;
                    if (d = !document.querySelector("#wrapper") && document.querySelector("#post_1 .cooked")) {
                        d = d.insertBefore(document.createElement("span"), d.firstChild);
                        d.id = "wrapper";
    
                        GM_xmlhttpRequest({
                            onload: function (r) {
                                try {
                                    // add a base href for the article page so relative URIs work correctly
                                    t = r.responseText.replace(/<\/head>/i, "<base href='" + p[1] + "'/></head>");
                                    
                                    // parse the HTML and grab the class article-body element
                                    t = new DOMParser().parseFromString(t, "text/html").querySelector(".article-body");
                                    
                                    // grab the byline and move it to the top of the article
                                    t.insertBefore(t.parentElement.querySelector(".articleMeta"), t.firstChild);
                                    
                                    // overwrite a.href and img.src with absolute URIs since base href is different
                                    Array.apply(0, t.querySelectorAll("a"))
                                       .forEach(function (e) { e.href = e.href; });
                                    Array.apply(0, t.querySelectorAll("img"))
                                       .forEach(function (e) { e.src = e.src; });
                                    
                                    Array.apply(0, t.querySelectorAll(".admin-only,link,script"))
                                       .forEach(function (e) { e.parentElement.removeChild(e); });
                                    Array.apply(0, t.childNodes)
                                       .forEach(function (e) { if (e.textContent.indexOf("[Advert") + 1) t.removeChild(e); });
                                    
                                    d.appendChild(t);
                                    setTimeout(parse, 1);
                                } catch (e) {
                                    console.error(e);
                                }
                            },
                            method: "GET",
                            url: p[1]
                        });
                    }
                } catch (e) {
                    console.error(e);
                }
            }
            
            var observer = new MutationObserver(inspect);
            observer.observe(document.getElementById("main"), {childList: true, characterData: true, subtree: true});
        }
        
        parse();
    } catch (e) {
        console.error(e);
    }
    

    Making it a collapsible box is left as an exercise for the reader.

    edit: just noticed that relative URIs stayed relative and made broken links on what.thedailywtf.com instead of pointing back to thedailywtf.com. Fixed by adding a <base href=...> to the page and code to replace image src and link href attributes with the correct absolute URIs.

    Filed under: I should probably make this a linked topic but I can't be bothered coming up with a title for it

  • (disco) in reply to loose
    loose:
    I did promise myself not to get involved with this topic

    Mistakes were made.

  • (disco) in reply to kupfernigk
    kupfernigk:
    There is a time for commenting out dead code, with additional comments; and that's when some other clueless developer thinks his code was right and has a tendency to put it back again.

    That's what a severe code review is for. Try to give the offender the smallest chair you can find; he needs to be looking up at everyone else…

  • (disco) in reply to dkf
    dkf:
    That's what a severe code review is for. Try to give the offender the smallest chair you can find; he needs to be looking up at everyone else…

    What do you do when the person concerned is the CEO's blue eyed boy?

  • (disco) in reply to kupfernigk

    I know this one. You need to fill the following list:

    1. 1 large lightproof sack
    2. 1 large tiewrap :tm:
    3. A fluffer
    4. Some recreational chemical, that induces a don't care type of euphoria
    5. Somebody who is prepared to take a bullet for the Team.

    Then you:

    1. Surreptitiously cause chemical to be ingested by the Blue Eyed Boy
    2. Wait for it to take effect.
    3. Apply sack to CEO, ensuring he don't see it coming
    4. Apply tiewrap :tm: to same, ensuring the CEO can get free by himself after a short while
    5. Place CEO and Blue Eyed Boy in same room
    6. Bugger the CEO
    7. Get the fluffer to work his or her stuff on the Blue Eyed Boy
    8. Retire
    9. Profit

    I do appreciate that of the list of prerequisites, there will be one item difficult to obtain, thus making it a "choke point" in the task flow. But I am absolutely positive that one of your Team knows how to get theirs hands on a fluffer at short notice. Who has a Team that doesn't?

  • (disco) in reply to kupfernigk
    kupfernigk:
    dkf:
    That's what a severe code review is for. Try to give the offender the smallest chair you can find; he needs to be looking up at everyone else…

    What do you do when the person concerned is the CEO's blue eyed boy?

    Shout even more loudly / use an even more contemptuous tone of voice / laugh even more jeeringly. If he complains to CEO about how he was treated, and CEO wishes to communicate with you on the matter, stand your ground. Point out to CEO that b-e-b is a twit. And if as CEO he is not prepared to accept your assessment of him, maybe you are better off somewhere else.

  • (disco) in reply to loose
    loose:
    I DON'T USE CVS
    You'd better, because I don't consider that a real Version Control System.
  • (disco) in reply to JBert
    JBert:
    I DON'T USE CVS

    LOL freudian slip.

  • (disco) in reply to kupfernigk
    kupfernigk:
    What do you do when the person concerned is the CEO's blue eyed boy?

    You're (probably) not hitting him, just giving him a browbeating. The message he needs to take away is get good and going easy on him won't do anyone any favours. If he can't take it and goes blubbing to daddykins, either he'll get a rude awakening or you'll be best out of there anyway (because the meddling won't ever stop).

    The alternative is to get the idiot promoted to some entirely different part of the business (or another one entirely) but that's a lot more difficult to arrange. Code Reviews are Clearly Best Practice, and easy to set up.

  • (disco) in reply to Matt_Westwood
    Matt_Westwood:
    b-e-b

    hehe.. bewbs.. :giggity:

  • (disco)

    Probably not a 1:1 case here, but sometimes I had to do things like the hacky looking commented out code because the people making some library had one version that would take a filename and do the needful, except wrong, and another version taking the byte[] as input and handle it correctly. I think even years later they didn't get it right. No excuse for swallowing exceptions or unused filenameparts variable.

  • (disco) in reply to Zemm
    Zemm:
    What about

    It’s a beautiful little collection of ignorance, a willingness to do it the hardware, [...]

    :facepalm: I've only got that it was a typo after reading your post. I thought it was just a botched sentence referring to retrieving the file from the hardware again instead of using one you already have loaded.

  • (disco) in reply to Matt_Westwood
    Matt_Westwood:
    CEO wishes to communicate with you on the matter, stand your ground. Point out to CEO that b-e-b is a twit. And if as CEO he is not prepared to accept your assessment of him, maybe you are better off somewhere else.

    In the particular case I was thinking of, yes I was better off somewhere else. (The b-e-b was fired but after I ceased to be around). But other people might not have other sources of income. Some people are dependent on their jobs and live in places where other jobs are hard to find. So while I appreciate everybody's well meaning advice, not everyone is placed to make use of it.

  • (disco) in reply to kupfernigk
    kupfernigk:
    There is a time for commenting out dead code, with additional comments; and that's when some other clueless developer thinks his code was *right* and has a tendency to put it back again.

    //some line of code //the line above does not work because.... //some line of code //the line above fails when....

    A similar situation exists where the "obviously right" succinct code isn't right, but the :wtf: code has to stay in place because of some bizarre corner case.

    You leave the unsuccessful code enshrined in commentage, so that the next person to slap their palm either finds a clean way to address the corner cases, or moves along to some part of the code which actually does need to change.

  • (disco) in reply to Crunger
    Crunger:
    but the code has to stay in place because of some bizarre corner case.

    I have worked with printers, and there are so many bizarre corner cases they become the norm. It's like Microsoft's document XML format, which is just one strange fiddle after another - which is why it's so huge. Anyone might think the writers of Word did it to make reverse engineering as hard as possible without adding any value.

  • (disco) in reply to kupfernigk
    kupfernigk:
    Anyone might think the writers of Word did it to make reverse engineering as hard as possible without adding any value.

    I suspect it just reflects the fact that the Word internal document model is itself one strange fiddle after another. I bet there are people in Microsoft who would love to clear that shit up too, but can't because some big customer has demanded that their documents continue to format exactly as they did 15 years ago (in some product that nobody has any more either) and that's the sort of customer that MS has bent over backwards for for a long time.

  • (disco) in reply to dkf
    dkf:
    I suspect it just reflects the fact that the Word internal document model is itself one strange fiddle after another.

    I suspect so too; I think the original designers of Word didn't understand typesetting or the need for a proper workflow, and just produced ad hoc solutions to everything. But when it comes to Word, which I hate with a passion having spent some time automating Word document handling, I prefer to think of evil rather than incompetence.

  • (disco) in reply to kupfernigk
    kupfernigk:
    I prefer to think of evil rather than incompetence.

    Why differentiate? :neutral_face:

  • (disco) in reply to dkf
    dkf:
    Why differentiate?

    It's just a preference and it doesn't affect any business logic.

  • (disco) in reply to kupfernigk
    kupfernigk:
    I suspect so too; I think the original designers of Word didn't understand typesetting or the need for a proper workflow, and just produced ad hoc solutions to everything. But when it comes to Word, which I hate with a passion having spent some time automating Word document handling, I prefer to think of evil rather than incompetence.

    Yeah -- people who insist on preparing anything longer than say, a few dozen pages or so in a word processor are insane freaks.

    :passport_control:

    Filed Under: \begin{document}

  • (disco) in reply to dkf
    dkf:
    I bet there are people in Microsoft who would love to clear that shit up too, but can't because some big customer has demanded that their documents continue to format exactly as they did 15 years ago

    That doesn't stop them from moving to a new format and cleaning things up. It's going to be slightly inconvenient, but they'd just need to support loading and saving the old files for backward compatibility.

    ...in fact they did this anyway when they created the XML-based document formats, so there was their prime opportunity to clean up their shit - there's no reason why the new XML-based formats should've also been a :wtf:.

  • (disco) in reply to anotherusername
    anotherusername:
    in fact they did this anyway when they created the XML-based document formats, so there was their prime opportunity to clean up their shit

    I don't have it to hand but I seem to recall that in the XML there are things like <windows95workaroundnnn screwiness='94'>allow</windows95workaroundnnn> (thanks @Jaloopa, oh wie ich bin ein Dummkopf) (I may not remember exactly due to having to take sedatives after working with it.)

  • (disco) in reply to kupfernigk
    kupfernigk:
    anotherusername:
    in fact they did this anyway when they created the XML-based document formats, so there was their prime opportunity to clean up their shit

    I don't have it to hand but I seem to recall that in the XML there are things like <windows95workaroundnnn screwiness='94'>allow</windows95workaroundnnn> (I may not remember exactly due to having to take sedatives after working with it.)

    FTFY

Leave a comment on “Mistakes Were Made”

Log In or post as a guest

Replying to comment #:

« Return to Article