Validating that which does not exist



  • Another day, another brownfield development project. Found in the existing codebase:

    public bool ValidateXml(string xmlFile)
    {
        Assert.ArgumentNotNullOrEmpty(xmlFile);
        
        if (File.Exists(xmlFile))
        {
            try
            {
                //xsd validation
                //snip...
            }
            catch (Exception ex)
            {
                errors.Add(ex);
            }
        }

        return errors.HasNoErrors;
    }

    If you give this method a non-existent path, it tells you it's valid xml. Yes, there are unit tests for this.



  •  That which does not exist cannot have any errors.



  • @JimLahey said:

    Another day, another brownfield development project.

    What does "brownfield" mean in this context? I only know of the Evironmental Protection Agency use of the term...


  • BINNED

    Was there a return in the part you snipped out?



  • @blakeyrat said:

    @JimLahey said:
    Another day, another brownfield development project.

    What does "brownfield" mean in this context? I only know of the Evironmental Protection Agency use of the term...

    Brownfield means an old(er) application that still gets regular development (both maintenance and new features), as opposed to legacy (just maintenance and usually infrequently) and greenfield (fresh slate).



  • @blakeyrat said:

    @JimLahey said:
    Another day, another brownfield development project.

    What does "brownfield" mean in this context? I only know of the Evironmental Protection Agency use of the term...

     

    Completely totally off topic... just the mention of brownfield bought this to mind.

    Where I grew up, there was a place down by the reailtracks and the canal where we used to play as kids. It had lots of interesting landscape, wreckage, great for riding dirt bikes around and exploring. There were this interesting mounds, one of them always had smoke coming out of it (we kept away from that). We didn't really know what the site down by the old canal was, it was just a place to hang out.

    Later in life I learnt from my father that this was the site of the old battery factory, which shut down before he even played there and like me he would avoid the smoking mound. Apparently in his era the other mounds where also quite volatile, prone to caving in and full of toxic chemicals.

    The industry that used to work on this site was so toxic it blighted the land for at least two generations and the smoking mound still exists there today.

    Recently they started building on the land, there is a new hospital on the site there now but one thing still stands out...

     

    They developed new roads, put in a new aquaduct to divert the canal, built all the new hospital buildings but one little patch of land still remains undeveloped and fenced off, the smoking mound still remains and it still smokes to this day.

     

    Looking back I can't help wondering if this is the reason I have four breasts, this shit can't be good for the DNA.

     

    Anyway, getting back on topic, I guess brownfield can be used in terms of codebase. Sometimes there are legacies no-one dare touch, that have to be developed around and even when they are remain so toxic that they will cause you problems for generations to come.

     



  • @PedanticCurmudgeon said:

    Was there a return in the part you snipped out?

    Yes there was. If the file exists you can trust the validation but if it doesn't you get something of a false positive.



  • @blakeyrat said:

    @JimLahey said:
    Another day, another brownfield development project.

    What does "brownfield" mean in this context? I only know of the Evironmental Protection Agency use of the term...

    It means a meadow with shit smeared all over it. Quite a useful term in software development.



  • @Hatshepsut said:

    It means a meadow with shit smeared all over it. Quite a useful term in software development.

    An essential term given the horrors I'm confronted with on a daily basis.



  • @JimLahey said:

    @Hatshepsut said:

    It means a meadow with shit smeared all over it. Quite a useful term in software development.

    An essential term given the horrors I'm confronted with on a daily basis.

     

     

    I'm currently trying to repair a filter that filters itself based on itself and is thus reduced to 1 option when you filter, except when the query fails in some vague manner and you get several duplicate options of which only 1 works but the same filter-getter is used for the actual filtered results list where the filtering actually takes place.

    And someone coded this, and said, yes, this is correct. Let's check it in and set the ticket to Resolved.



  • And this kids, is why you should ALWAYS use if/else and not if only. Actually, I think this was the 11th commandment (however is written)... maybe the stone was too short.



  • @ubersoldat said:

    And this kids, is why you should ALWAYS use if/else and not if only. Actually, I think this was the 11th commandment (however is written)... maybe the stone was too short.

    It wouldn't even need that to be honest. Just remove the File.Exists check and any FileNotFoundException would be caught and added to the errors collection which then removes the possibility of a false positive result. Using an errors collection in this way is an entirely different WTF, mind, as it's private in this particular class. Yes, your validation failed, no, you can't find out why.

    It's simplest just to catch the exception and throw a new one with a meaningful message and the caught exception as innerException to preserve the stack trace.



  • @JimLahey said:

    If you give this method a non-existent path, it tells you it's valid xml.
     

    @dhromed said:

     That which does not exist cannot have any errors.

    <pedant>Your statement is technically correct.

    In the context of the JimLahey's post, an empty file (or missing file) is actually invalid[1] XML</pedant>

    [1] further pedantary: I think Jim meant to say "not well-formed". When it comes to XML you can actually have well-formed but invalid XML, something that doesn't match a given schema.

    Oddly enough, if a schema is missing then any well-formed XML is classified as valid, since "if laws do not exist, I cannot be doing anything illegal"


  • Trolleybus Mechanic

    @Hatshepsut said:

    @blakeyrat said:
    @JimLahey said:
    Another day, another brownfield development project.

    What does "brownfield" mean in this context? I only know of the Evironmental Protection Agency use of the term...

    It means a meadow with shit smeared all over it. Quite a useful term in software development.

     

    Would a shit-covered meadow actually be a good thing? Well fertilized, guaranteed to grow in a lush, well fed patch of green later with little or no maintenance.

    You know what? I think I'll just use that next time someone accuses my code of being covered in shit. "You just aren't looking at it botanically..."



  • Not if there's so much shit it smothers the plants and mold starts growing instead.



  • @EncoreSpod said:

    @blakeyrat said:

    @JimLahey said:
    Another day, another brownfield development project.

    What does "brownfield" mean in this context? I only know of the Evironmental Protection Agency use of the term...

     

    <<snippage>>

    Looking back I can't help wondering if this is the reason I have four breasts, this shit can't be good for the DNA.

    So... are you seeing anyone?

     



  • @D-Coder said:

    So... are you seeing anyone?

     

     

    Crazily enough, yes, there are women depserate enough to date 'things' with male genitalia but also four breasts.

     

    Ooooh hang on... I see what you were saying now... sorry I'm not interested.

     

     


Log in to reply