• (disco)

    Today's article is brought to you by the department of local variable preservation.


    Filed under: You never know when you will run out unless you really save on them.

  • (disco)

    Re: code snippet; ew, icky.

    Though, to be fair, even the solution I have in mind is a little :wtf: in its own way

    <!-- Emoji'd by MobileEmoji 0.2.0-->
  • (disco)
             return String.IsNullOrEmpty(address.Line1) ? "" :  (address.Line1 + "<br />" )+
             String.IsNullOrEmpty(address.Line2) ? "" : (address.Line2 + "<br />" )+
             String.IsNullOrEmpty(address.Line3) ? "" : (address.Line3 + "<br />") +
             String.IsNullOrEmpty(address.City) ? "" : (address.City + "<br />") +
             String.IsNullOrEmpty(address.PostalCode) ? "" : (address.PostalCode + "<br />" )+
             address.Country;
    
  • (disco) in reply to Jaloopa
    SELECT  CONCAT(
        COALESCE(CONCAT(Line1,,''),
        COALESCE(Line1,''), '<br />',
             String.IsNullOrEmpty(address.City) ? "" : (address.City + "<br />") +
             String.IsNullOrEmpty(address.PostalCode) ? "" : (address.PostalCode + "<br />" )+
             address.Country;
      FROM address
    

    ... I'm just going to have to stop there.

    damn almost self nerddsniped by trying to make that formatting in a SQL select statement...

  • (disco)
    "<br />\n".join(i for i in (address.line1, address.line2, address.line3, address.city, address.postal_code) if i)
    
  • (disco) in reply to accalia

    OMG BUSlNESS LOGIC IN TEH DATABASE

  • (disco) in reply to Jaloopa
    Jaloopa:
    OMG BUSlNESS LOGIC IN TEH DATABASE

    that was going to be the joke. yes.

  • (disco)
    all_values = [address.Line1, address.Line2, address.Line3, address.City, address.PostalCode, address.Country]
    valid_values = filter(None, all_values)
    return '<br/>'.join(valid_values)
    

    Translate to your barbaric languages if you must.

  • (disco) in reply to accalia

    You should have generated JQuery-Code in the database. I heard JQuery was the new big thing on the web and we need it by tomorrow. Also where is the XML? My email said XML once so make that happen.

    Filed Under: PHB

  • (disco) in reply to Kuro

    hm... i can do that. but i'm going to need a fifth of rotgut, a conference room for the day, a lot of snacks and a little bit of your special relaxin' herbs.

  • (disco) in reply to accalia

    You can take the useless intern from the department on the upper floor. He don't know a thing about programming but I thnik he is related to friend of the big boss so you KNOW he has to be useful!

    Filed Under: I expect results in 30 minutes. I already told everybody this would be great

    Addendum: I didn't even notice how the intern is now useless and useful in one statement... my PHB is strong today :D

  • (disco)
    kupfernigk:
    If you are generating HTML on the fly this problem is trivially easy to solve using the ternary operator.
    As @Jaloopa has done. Still makes my quills itch though; there must be a better way…
    icebrain:
    Translate to your barbaric languages if you must.
    OK!
    var parts = new List<String>{address.Line1, address.Line2, address.Line3, address.City, address.PostalCode, address.Country};
    return parts.Where(s => !String.IsNullOrWhitespace(s)).ToList().Join("<br />");
    

    Yes, C# does allow you to omit the parentheses when there's no constructor arguments and you're using a collection initialiser :stuck_out_tongue:

    Oh, and +5 using LINQ to Objects when it's not at all obvious it's the right way to go :laughing:


    Single-line version:

    return new List<String>{address.Line1, address.Line2, address.Line3, address.City, address.PostalCode, address.Country}.Where(s => !String.IsNullOrWhitespace(s)).ToList().Join("<br />");
    

    Not actually sure it'll compile like that… :smile:

    <!-- Emoji'd by MobileEmoji 0.2.0-->
  • (disco) in reply to RaceProUK
    RaceProUK:
    Not actually sure it'll compile like that…

    why wouldn't it?

    oooooh.

    return "<br />".Join(new List<String>{address.Line1, address.Line2, address.Line3, address.City, address.PostalCode, address.Country}.Where(s => !String.IsNullOrWhitespace(s)));
    

    that compiles and works correctly (for .NET4.5)

  • (disco) in reply to accalia

    Damn girl! And I thought my solution was :wtf:y enough… :laughing:

    <!-- Emoji'd by MobileEmoji 0.2.0-->
  • (disco) in reply to RaceProUK

    well asside from the fact that it didn't compile... yeah it was. i just made it compile and removed the redundant ToList (join will happily work on a raw IEnumerable)

  • (disco) in reply to RaceProUK
    RaceProUK:
    it's not at all obvious it's the right way to go

    LINQ is always the right way to go

  • (disco) in reply to Jaloopa

    Who said it's on the database? I develop all my local applications in pure SQL for extra simplicity. This way I don't have to learn two languages.

  • (disco) in reply to accalia
    well asside from the fact that it didn't compile... yeah it was. i just made it compile and removed the redundant ToList (join will happily work on a raw IEnumerable)
    http://i1.kym-cdn.com/entries/icons/original/000/011/848/cold.jpg
  • (disco)

    A moment's browsing of the rest of the codebase revealed an even better part: it modified the fields on the address, leading to odd validation bugs later on when the city (which might contain the postcode now, or even the country) or postcode were used.

    Why did that require even a moment's browsing of the rest of the codebase? It was pretty obvious that was going to happen from the snipped posted:

    address.City = address.PostalCode;```
    

    etc.

     

    Ashleigh typed into an email she knew she wouldn't send.

    Why not? She only had one day left on her contract — not a lot to lose, even if it did piss someone off enough to fire her.

  • (disco) in reply to operagost
    operagost:
    http://i1.kym-cdn.com/entries/icons/original/000/011/848/cold.jpg
    Eh… I did admit it might not compile at the time :stuck_out_tongue:
    HardwareGeek:
    Why not? She only had one day left on her contract — not a lot to lose, even if it did piss someone off enough to fire her.
    Burning bridges and all that <!-- Emoji'd by MobileEmoji 0.2.0-->
  • (disco) in reply to HardwareGeek
    HardwareGeek:
    Why did that require even a moment's browsing of the rest of the codebase?

    Sentence got mangled, sorry, the browsing was to verify that it does, in fact, cause validation errors. This wasn't a throwaway object, in other words.

  • (disco) in reply to RaceProUK
    RaceProUK:
    Burning bridges and all that
    Of course, but ...

    The best thing about being a consultant, in Ashleigh's opinion, was that you got to leave at the end of a job- meaning you never had to live with the mistakes your pointy-haired supervisor forced on you.

    ... suggested to me that she didn't really care all that much about keeping bridges intact.

  • (disco)

    After a couple years working as an independent contractor, I've realized that one of the greatest things about not being a wage slave is my reaction to stupid decisions made by stupid bosses.

    As a full-time employee: (Head in hands, moaning) Oh my god... we're fucked...

    As a contractor: (Pointing, with a smirk) Oh my god - they're fucked!

  • (disco)

    What language is that? It looks a lot like C#, except that C# uses ||, not or...

  • (disco) in reply to tom103

    I was wondering the same thing but with the string type in lowercase. If it was pseudo, the private doesn't make sense either.

  • (disco) in reply to Eldelshell

    It's not Java either.

    In fact, I can't think of a single C-family language that uses or as a keyword for… well… anything.

    <!-- Emoji'd by MobileEmoji 0.2.0-->
  • (disco) in reply to Twerlotzuk

    As a full-time employee on a contractor: (running away) kill it with fire already!

  • (disco) in reply to Eldelshell

    string in lowercase is just an alias for the System.String type.

  • (disco) in reply to RaceProUK
    RaceProUK:
    In fact, I can't think of a single C-family language that uses or as a keyword for… well… anything.

    http://php.net/manual/en/language.operators.logical.php

    PHP :heart:

  • (disco) in reply to HardwareGeek

    There's still a difference between not having to live with the fallout of bad decisions vs not ever needing another contract with that person or company again, though.

  • (disco) in reply to operagost
    operagost:
    http­://i1.kym-cdn.com/entries/icons/original/000/011/848/cold.jpg

    was that really a burn? cause it wasn't supposed to be a burn.

  • (disco) in reply to accalia
    accalia:
    was that really a burn? cause it wasn't supposed to be a burn.
    S'OK love, I didn't take it as a burn ;) <!-- Emoji'd by MobileEmoji 0.2.0-->
  • (disco) in reply to RaceProUK

    C++ https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#C.2B.2B_operator_synonyms

    Example:

    alicev@Iris-xu1310:~/dev/wtfC$  cat or.cpp
    #include <iostream>
    int main(){
        std::cout << (false or false) << "," << (true or false) << "," << (false or true) << "," << (true or true) << std::endl;
        return 0;
    }
    alicev@Iris-xu1310:~/dev/wtfC$  g++ or.cpp -o or.o
    alicev@Iris-xu1310:~/dev/wtfC$  ./or.o
    0,1,1,1
    alicev@Iris-xu1310:~/dev/wtfC$ 
    
    
    
  • (disco)

    I cannot believe we've gone through close to 40 posts without someone mentioning that building HTML by concatenating raw strings without escaping special characters means problems just waiting to happen.

    So without further ado: Building HTML by concatenating raw strings without escaping special characters means problems just waiting to happen.

  • (disco) in reply to Ragnax

    It's because we all know it, so it doesn't need to be said ;)

    <!-- Emoji'd by MobileEmoji 0.2.0-->
  • (disco) in reply to Yamikuronue
    Yamikuronue:
    There's still a difference between not having to live with the fallout of bad decisions vs not ever needing another contract with that person or company again, though.

    But if their devs are that bad, do you really want to work there again. Besides, if the boss's hair isn't pointy, he just might smile and say, "Yeah, I wish..."

  • (disco) in reply to anonymous234
    anonymous234:
    I develop all my local applications in pure SQL for extra simplicity

    I think this has been linked here before:

    http://spw.thefrozenfire.com/

  • (disco)

    The problem here was not the code (which is horrid), but the task. The task seemed to be "We are getting all these blank lines in our addresses. Fix the addresses so it doesn't happen".

    Which is exactly what they did. Which is all they could have done.

    The fix (in an OO language) is to add a method to the Address class to output the formatted address, and then change every document to use that pretty-print method. But that was likely not an option given to the offshore developers. I wonder what the penalty is for passing "That is the dumbest idea I have ever heard of" back up the managerial chain, for a lowly offshore code macaque?

  • (disco) in reply to Ragnax

    What could possibli go wrong?

Leave a comment on “The Address Shuffle”

Log In or post as a guest

Replying to comment #447337:

« Return to Article