Let the cloud catch it



  • Sample code from Microsoft showing how to upload stuff on Azure:


    
    private static void InserData(CloudBlobContainer container) 
             { 
                 try 
                 { 
                     // Retrieve reference to a blob 
                     CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob"); 
     
                     using (var fileStream = System.IO.File.OpenRead(@"localFile")) 
                     { 
                         blockBlob.UploadFromStream(fileStream); 
                     } 
                 } 
                 catch 
                 { 
                     throw; 
                 } 
             } 
    
    




    Interesting items:

    • Typo in method name
    • Hard-coded blob name
    • Hard-coded file name that looks like a variable name
    • Useless @ sign for a hard-coded string which has no escape character in it
    • Useless comment


    Nothing in this code is a huge WTF but even if it was written by some dude this is a Microsoft sample and is likely to be copy-pasted by zillions of n00bs. Sadly it would have taken maybe a minute to make this low-quality skeleton good enough to be a reliable part of a library without modification. Possibly the @ is there to remind coders that if they hard-code a file path they should be careful with the escape characters, but in the big scheme of things it's probably not the proper place to do it.

    What is not shown in this sample is that the method is part of "ClassLibrary3" and includes two of the references that scare me the most when I look at some code ("System.Threading.Tasks" and "System.Text.RegularException") because most of the time people who use them should not.

    In the event that someone is interested to get more of these samples, there is a convenient link at the bottom of this page, it's called "Other storage samples". To preserve the WTF effect I won't put this link here.


  • Winner of the 2016 Presidential Election

    @Ronald said:

    System.Text.RegularException

    Go doesn't throw Regular Exceptions, they return error codes instead. Or panic. Or go into an infinite loop.



  • @Ronald said:

    System.Text.RegularException

    Interesting Freudian slip.



    Also interesting that according to that sample the @ sign is not needed when writing to a file instead of reading.

      private static void GetData(CloudBlobContainer container) 
             { 
                 try 
                 { 
                     // Retrieve reference to a blob 
                     CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob"); 
     
                     using (var fileStream = System.IO.File.OpenWrite("localFile")) 
                     { 
                         blockBlob.DownloadToStream(fileStream); 
                     } 
                 } 
                 catch 
                 { 
                     throw; 
                 } 
             } 
    
    


  •  Microsoft examples on MSDN or elsewhere has never been anywhere near best practice. It is there to get the basic idea of how a particular feature works.



  • Useless try/catch/throw as well.



  • @lucas said:

     Microsoft examples on MSDN or elsewhere has never been anywhere near best practice. It is there to get the basic idea of how a particular feature works.

    This. 



  • @Sutherlands said:

    @lucas said:

     Microsoft examples on MSDN or elsewhere has never been anywhere near best practice. It is there to get the basic idea of how a particular feature works.

    This. 

    I would "this" this also if it had not been super easy to make it a GOOD example. There is litterally 1 minute of work needed to make it perfectly fine. Showing features with throw-away code is one thing, being lazy for no reason is a WTF.



  • @Ronald said:

    Showing features with throw-away code is one thing, being lazy for no reason is a WTF.

    Laziness is what separates the mediocre programmers from the great programmers.

    As in, being lazy means you don't constantly try to do stupid shit like re-invent the wheel or writing a conditional statement with 200 elseif blocks.



  • @Ronald said:

    @Ronald said:
    System.Text.RegularException

    Interesting Freudian slip.

    I prefer

    System.Text.IrregularException

    and

    System.Text.InceptionException


  • @Ronald said:

    System.Threading.Tasks

    That's not a WTF, that's part of the VS2012 boilerplate.



  • @zelmak said:

    System.Text.InceptionException

    public class InceptionException : Exception
    {
        public InceptionException() : base("We have to go deeper!", this) { }
    }
    


  • @zelmak said:

    @Ronald said:
    @Ronald said:
    System.Text.RegularException

    Interesting Freudian slip.

    I prefer

    System.Text.IrregularException

    and

    System.Text.InceptionException

    OutOfMommyException



  • @morbiuswilters said:

    Laziness is what separates the mediocre programmers from the great programmers.

    At MS, great programmers get to work on C# compilers and OS improvements; mediocre programmers work on the samples. Crappy programmers are put into customer support, where they excel at shuttling you from one support person to the next without ever actually finding a solution to your problem.



  • @morbiuswilters said:


    As in, being lazy means you don't constantly try to do stupid shit like re-invent the wheel or writing a conditional statement with 200 elseif blocks.

    That's called constructive laziness!



  • @morbiuswilters said:


    As in, being lazy means you don't constantly try to do stupid shit like re-invent the wheel or writing a conditional statement with 200 elseif blocks.

    That's called constructive laziness!





  • @Ben L. said:

    why the fuck would you pay for cloud space when you can host your own self-maintaining cloud on your employees' computers?
     

    Make it work on other peoples' computers over the Internet, and we'll talk.

     And also not be written in Go.





  • @Ben L. said:

    @drurowin said:

    @Ben L. said:

    why the fuck would you pay for cloud space when you can host your own self-maintaining cloud on your employees' computers?
     

    Make it work on other peoples' computers over the Internet, and we'll talk.

     And also not be written in Go.

    This site is hosted on a cbfs cluster, and written in HTML/JavaScript/SVG.
     

    I meant like a drive-by download I could embed in a banner ad.

     And the cbfs software appears to be written in Go.

    Edit: Also, speaketh the link you posted.  "MCResponse status=KEY_ENOENT, opcode=GET, opaque=0, msg: Not found"

     



  • @drurowin said:

    @Ben L. said:

    @drurowin said:

    @Ben L. said:

    why the fuck would you pay for cloud space when you can host your own self-maintaining cloud on your employees' computers?
     

    Make it work on other peoples' computers over the Internet, and we'll talk.

     And also not be written in Go.

    This site is hosted on a cbfs cluster, and written in HTML/JavaScript/SVG.
     

    I meant like a drive-by download I could embed in a banner ad.

     And the cbfs software appears to be written in Go.

    Edit: Also, speaketh the link you posted.  "MCResponse status=KEY_ENOENT, opcode=GET, opaque=0, msg: Not found"

     




  • @Ben L. said:

    @drurowin said:

    @Ben L. said:

    @drurowin said:

    @Ben L. said:

    why the fuck would you pay for cloud space when you can host your own self-maintaining cloud on your employees' computers?
     

    Make it work on other peoples' computers over the Internet, and we'll talk.

     And also not be written in Go.

    This site is hosted on a cbfs cluster, and written in HTML/JavaScript/SVG.
     

    I meant like a drive-by download I could embed in a banner ad.

     And the cbfs software appears to be written in Go.

    Edit: Also, speaketh the link you posted.  "MCResponse status=KEY_ENOENT, opcode=GET, opaque=0, msg: Not found"

     

    {giant images}

     

    Don't you have a CHARGER for that iPad?  Or is it your only home computer, and you're on it all day?  All the screenshots you've posted have been below 15% battery.

    Also, imgur?  Why can't you be like Miff and at least run your own webserver?  Parents won't forward port 80 for you?




  • @drurowin said:

    @Ben L. said:

    @drurowin said:

    @Ben L. said:

    @drurowin said:

    @Ben L. said:

    why the fuck would you pay for cloud space when you can host your own self-maintaining cloud on your employees' computers?
     

    Make it work on other peoples' computers over the Internet, and we'll talk.

     And also not be written in Go.

    This site is hosted on a cbfs cluster, and written in HTML/JavaScript/SVG.
     

    I meant like a drive-by download I could embed in a banner ad.

     And the cbfs software appears to be written in Go.

    Edit: Also, speaketh the link you posted.  "MCResponse status=KEY_ENOENT, opcode=GET, opaque=0, msg: Not found"

     

    {giant images}

     

    Don't you have a CHARGER for that iPad?  Or is it your only home computer, and you're on it all day?  All the screenshots you've posted have been below 15% battery.

    Also, imgur?  Why can't you be like Miff and at least run your own webserver?  Parents won't forward port 80 for you?



    I only charge it when it's below 10%. It's a family iPad, and I only use it late in the day, and it usually recharges overnight. Also, I do have my own webserver. It's not my parents that are the problem.



  • @Ben L. said:

    I only charge it when it's below 10%. It's a family iPad, and I only use it late in the day, and it usually recharges overnight. Also, I do have my own webserver. It's not my parents that are the problem.
    So they won't forward port 80 for you.  Why not change to cable?  I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

     



  • @drurowin said:

    I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

    Dude, he lives in Milwaukee.. I'm not sure they even have satellite there.

    Still, I can't blame his ISP for blocking port 80. Something like 99.99% of shit running on a home computer's port 80 is probably shady and/or illicit.



  • @morbiuswilters said:

    @drurowin said:
    I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

    Dude, he lives in Milwaukee.. I'm not sure they even have satellite there.

    Still, I can't blame his ISP for blocking port 80. Something like 99.99% of shit running on a home computer's port 80 is probably shady and/or illicit.

    So why allow inbound connections to the end user equipment at all?  My ISP I use here in Britland has everyone behind a NAT.



  • @morbiuswilters said:

    @drurowin said:
    I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

    Dude, he lives in Milwaukee.. I'm not sure they even have satellite there.

    Still, I can't blame his ISP for blocking port 80. Something like 99.99% of shit running on a home computer's port 80 is probably shady and/or illicit.


    Or skype.



  • @Ben L. said:

    @morbiuswilters said:
    @drurowin said:
    I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

    Dude, he lives in Milwaukee.. I'm not sure they even have satellite there.

    Still, I can't blame his ISP for blocking port 80. Something like 99.99% of shit running on a home computer's port 80 is probably shady and/or illicit.


    Or skype.

    Skype runs a web server on port 80? That seems unlikely, seeing as I already have a web server running on port 80..



  • @morbiuswilters said:

    @Ben L. said:
    @morbiuswilters said:
    @drurowin said:
    I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

    Dude, he lives in Milwaukee.. I'm not sure they even have satellite there.

    Still, I can't blame his ISP for blocking port 80. Something like 99.99% of shit running on a home computer's port 80 is probably shady and/or illicit.


    Or skype.

    Skype runs a web server on port 80? That seems unlikely, seeing as I already have a web server running on port 80..

    TRWTF



  • @morbiuswilters said:

    @Ben L. said:
    @morbiuswilters said:
    @drurowin said:
    I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

    Dude, he lives in Milwaukee.. I'm not sure they even have satellite there.

    Still, I can't blame his ISP for blocking port 80. Something like 99.99% of shit running on a home computer's port 80 is probably shady and/or illicit.


    Or skype.

    Skype runs a web server on port 80? That seems unlikely, seeing as I already have a web server running on port 80..

    That's why God created http.sys



  • @Ben L. said:

    @morbiuswilters said:
    @Ben L. said:
    @morbiuswilters said:
    @drurowin said:
    I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

    Dude, he lives in Milwaukee.. I'm not sure they even have satellite there.

    Still, I can't blame his ISP for blocking port 80. Something like 99.99% of shit running on a home computer's port 80 is probably shady and/or illicit.


    Or skype.

    Skype runs a web server on port 80? That seems unlikely, seeing as I already have a web server running on port 80..

    TRWTF

    So it lets you use port 80 as a backup, in case you can't use an ephemeral port? Why is that a problem?



  • @morbiuswilters said:

    @Ben L. said:
    @morbiuswilters said:
    @Ben L. said:
    @morbiuswilters said:
    @drurowin said:
    I'm sure Mediacom or whoever your rural cable TV cooperative is will offer you service that doesn't suck.

    Dude, he lives in Milwaukee.. I'm not sure they even have satellite there.

    Still, I can't blame his ISP for blocking port 80. Something like 99.99% of shit running on a home computer's port 80 is probably shady and/or illicit.


    Or skype.

    Skype runs a web server on port 80? That seems unlikely, seeing as I already have a web server running on port 80..

    TRWTF

    So it lets you use port 80 as a backup, in case you can't use an ephemeral port? Why is that a problem?

    Because if Skype manages to start up before INSERT_WEB_SERVER, it grabs BOTH port 80 AND port 443, making the httpd's startup fail. Also, why the hell would port 80 be more likely to be open (incoming) on a firewall than a skype-specific port?



  • @Ben L. said:

    Because if Skype manages to start up before INSERT_WEB_SERVER, it grabs BOTH port 80 AND port 443...

    That doesn't sound correct. I think you can specify 80 or 443 as an alternative, but by default it just uses an ephemeral port.

    @Ben L. said:

    Also, why the hell would port 80 be more likely to be open (incoming) on a firewall than a skype-specific port?

    I dunno, some firewalls are configured stupidly. That's why so many software programs have to offer alternative ways to bypass arbitrary port blocking.



  • @morbiuswilters said:

    @Ben L. said:
    Because if Skype manages to start up before INSERT_WEB_SERVER, it grabs BOTH port 80 AND port 443...

    That doesn't sound correct. I think you can specify 80 or 443 as an alternative, but by default it just uses an ephemeral port.

    @Ben L. said:

    Also, why the hell would port 80 be more likely to be open (incoming) on a firewall than a skype-specific port?

    I dunno, some firewalls are configured stupidly. That's why so many software programs have to offer alternative ways to bypass arbitrary port blocking.

    I know this from experience, but meh, I could be wrong.



  • @Ronald said:

    // Retrieve reference to a blob
    CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob");

     

    This type of absent-minded commenting really annoys me. A call to a method whose name is "GetBlockBlobReference" does not need to be explained in a comment, and especially not if the comment merely provides a clunky synonym for the word "Get". This type of thing calls into question a developer's very level of critical thinking and awareness when writing code, and I secretly harbour very strong beliefs about the sort of work that this type of developer should really be doing.

     



  • @GNU Pepper said:

    @Ronald said:

    // Retrieve reference to a blob
    CloudBlockBlob blockBlob = container.GetBlockBlobReference("blob");

     

    This type of absent-minded commenting really annoys me. A call to a method whose name is "GetBlockBlobReference" does not need to be explained in a comment, and especially not if the comment merely provides a clunky synonym for the word "Get". This type of thing calls into question a developer's very level of critical thinking and awareness when writing code, and I secretly harbour very strong beliefs about the sort of work that this type of developer should really be doing.

    Ditto.



  • @Ronald said:

    this is a Microsoft sample and is likely to be copy-pasted by zillions of n00bs

    I bet they're fully aware of that...

    @Ronald said:

    Sadly it would have taken maybe a minute to make this low-quality skeleton good enough to be a reliable part of a library without modification.

    luckily, they knew an example should be the most basic bare-bones, because:

    1. it's an example of how to use a very specific function, so it should be very short, specific, and to the point, which it is.
    2. it's supposed to be an example, not a piece of instant code, it's meant to show you how things are done and make you be able to think about it, not to provide a copy-paste way to extend your library.

    @Ronald said:

    Possibly the @ is there to remind coders that if they hard-code a file path they should be careful with the escape characters, but in the big scheme of things it's probably not the proper place to do it.

    the @ is there to remind coders that in the big scheme of things it is a good idea to ALWAYS escape any path this way. you did know you can also use it with assignment,

    string foo = @"C:\bar\is\so\cool.txt";
    ,

    didn't you?

    conclusion: the example is good, in two lines, it explains that I need to retrieve reference to a "value" even if I want to upload data, and it shows me which function to use to do both of those things. it also shows that the call may throw exception, so I should handle it. in short, with a few bare-bones lines it pretty much answers the question it set out to answer.

    but yes, if it's a bad thing to assume that people whose job it is to think effectively and meaningfuly, would actually have these abilities and would use them when reading documentation, then bad microsoft, no cookie this week!



  • @morbiuswilters said:

    That doesn't sound correct. I think you can specify 80 or 443 as an alternative, but by default it just uses an ephemeral port.

    Like I said earlier, Skype is a sneaky bugger. That was always the case. The sound and video technology was always there. Skype made it a product by packaging it with really good abilities to establish connections, by means of various firewall bypasses and masquerading techniques to avoid being blocked. Skype is notoriously difficult to block without blocking other legitimate traffic. The exe was encrypted on disk and contained anti-debugging measurements (SoftICE detection etc) in order to avoid revealing and reverse engineering of all the tricks up its sleeves. But don't take my word for it, have look here for a (quite shallow) review: http://www.eecs.wsu.edu/~cs564/papers/BS06.pdf

    I presume that you won't accept this since Skype has been bought by Microsoft, but just try to imagine that this was not always the case.



  • @Obfuscator said:

    Like I said earlier, Skype is a sneaky bugger.

    I've never seen Skype try to listen on port 80 or port 443. shrug

    @Obfuscator said:

    I presume that you won't accept this since Skype has been bought by Microsoft, but just try to imagine that this was not always the case.

    Skype being owned by M$ has nothing to do with what I believe; what you're describing just isn't consistent with what I've seen.



  • @drurowin said:

    Also, imgur?  Why can't you be like Miff and at least run your own webserver?

    Half the stuff I post is on Imgur anyways because it's more convenient.



  • @Ben L. said:

    It's not my parents that are the problem.

    Looks like your ISP doesn't forward their own Port 80 either. (Yes I know it's a DNS error.)

    [nope]


  • sockdevs

    Anyone whose used C# for more than a second will know the below anyway, but just in case ;)

    @Ronald said:

    Possibly the @ is there to remind coders that if they hard-code a file path they should be careful with the escape characters, but in the big scheme of things it's probably not the proper place to do it.

    Almost.

    In C#, the @ before a string makes it a 'literal string' i.e. it doesn't try to interpret the usual \x escape sequences. It also allows the string to span multiple lines. it's a handy feature for path segments and other backspace/newline heavy strings.To use a " character in the string, you double-up i.e. "".

     



  • @RaceProUK said:

    Anyone whose used C# for more than a second will know the below anyway, but just in case ;)

    @Ronald said:

    Possibly the @ is there to remind coders that if they hard-code a file path they should be careful with the escape characters, but in the big scheme of things it's probably not the proper place to do it.

    Almost.

    In C#, the @ before a string makes it a 'literal string' i.e. it doesn't try to interpret the usual \x escape sequences. It also allows the string to span multiple lines. it's a handy feature for path segments and other backspace/newline heavy strings.To use a " character in the string, you double-up i.e. "".

    Exactly. And it's not necessary here, because there are no escape sequences in the string. So we're wondering why they put in the @ if it doesn't do anything. Ronald suggests it's just general principles. I think it's some sort of cargo-cult coding.

    [/rephrasing the things I just quoted and wasting people's time]

     



  • @Snowyowl said:

    So we're wondering why they put in the @ if it doesn't do anything. Ronald suggests it's just general principles. I think it's some sort of cargo-cult coding.

    When your paths look like they have bogus escape characters, it's probably a reasonable habit to get into. I probably would have coded the example as @"C:\path\to\local\file" or something. It would be amusing if someone forgot to escape or use an @ and then their path happened to have only valid escape characters.

    There's a blakeyrant in there somewhere about the pitfalls of windows paths and string escapes...


  • Discourse touched me in a no-no place

    @boomzilla said:

    @"C:\path\to\local\file" or something. It would be amusing if someone forgot to escape or use an @ and then their path happened to have only valid escape characters.

    Or just use forward slashes.


  • @morbiuswilters said:

    I've never seen Skype try to listen on port 80 or port 443. shrug
     

    It has definitely happened to me, it stopped me from starting apache on my machine. This however was a quite a while ago (2009) since I have seen this behaviour.



  • @PJH said:

    @boomzilla said:

    @"C:\path\to\local\file" or something. It would be amusing if someone forgot to escape or use an @ and then their path happened to have only valid escape characters.

    Or just use forward slashes.

    NO THAT'S NOT THE NATIVE WINDOWS LOOK ITS HORRIBLE AND YOU'RE THE WORST FOR SUGGESTING IT.

    Sorry...I've got ahold of myself again....



  • @boomzilla said:

    @PJH said:
    @boomzilla said:

    @"C:\path\to\local\file" or something. It would be amusing if someone forgot to escape or use an @ and then their path happened to have only valid escape characters.

    Or just use forward slashes.

    NO THAT'S NOT THE NATIVE WINDOWS LOOK ITS HORRIBLE AND YOU'RE THE WORST FOR SUGGESTING IT.

    Sorry...I've got ahold of myself again....

    Hard-coding paths in executables on Windows only leads to problems. My system drive was I:, not C:.



  • @MiffTheFox said:

    @Ben L. said:
    It's not my parents that are the problem.

    Looks like your ISP doesn't forward their own Port 80 either. (Yes I know it's a DNS error.)

    No, it's because I spelled milwaukeepc.com wrong.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.