Finally on Try blocks? We've heard of that too.



  • @configurator said:

    @bridget99 said:
    String.Empty?

    I hate it. I think it's useless, and not as clear as "".

    I'm glad somebody else sees this. Few things turn me off more than String.Empty... seeing it in code is often a harbinger of other really wrongheaded coding practices.



  • @bridget99 said:

    @configurator said:
    @bridget99 said:
    String.Empty?

    I hate it. I think it's useless, and not as clear as "".

    I'm glad somebody else sees this. Few things turn me off more than String.Empty... seeing it in code is often a harbinger of other really wrongheaded coding practices.

    As long as we have String.Empty, why not have String.OneSpace or String.TheWordDogInLowerCase?

    Integer.Zero

    Insert rant about strings being objects.


  • FoxDev

    @bridget99 said:

    What do y'all think about String.Empty? It seems a little silly, in light of the fact that one can use "" to equal effect.

    "" could contain a zero-width space, String.Empty is guaranteed not to.

    However, you're guaranteed to drag this down just like last time, so let's just cut to the end with your second present:

    This time I used a better image.



  • @RaceProUK said:

    String.Empty is guaranteed not to.

    Except if you set its value via reflection :evil grin:.

    Seriously though, I'd expect any decent IDE to show you any zero-width space, and not hide characters from you. It's an IDE, not a WYSIWYG editor.



  • @RaceProUK said:

    @bridget99 said:

    What do y'all think about String.Empty? It seems a little silly, in light of the fact that one can use "" to equal effect.

    "" could contain a zero-width space, String.Empty is guaranteed not to.

    However, you're guaranteed to drag this down just like last time, so let's just cut to the end with your second present:

    This time I used a better image.

    You'd have to wilfully insert that into your code to make "" break. Just typing "" still works. And Unicode...OMG what a cesspool.



  • @boomzilla said:

    LOL. Underscores FTW. I hate trying to read camel case.

    Sure, underscored names would make bridget99 happy. Wait...


  • @alegr said:

    @boomzilla said:

    LOL. Underscores FTW. I hate trying to read camel case.

    Sure, underscored names would make bridget99 happy. Wait...

    I like the way names look with underscores, but I object to using a Shift character so heavily. I really prefer using a dash, but mediocre languages don't allow it. So, what I actually do (and direct my employees to do, when I'm in a leadership role) is use lowercase identifiers with no separation or distinction between words.


  • FoxDev

    @bridget99 said:

    And Unicode...OMG what a cesspool.

    Unicodeは、翻訳するのに便利です (Unicode is useful for translations).

    (from Google Translate, so may be gramatically dubious)

     



  • @RaceProUK said:

    @bridget99 said:

    And Unicode...OMG what a cesspool.

    Unicodeは、翻訳するのに便利です (Unicode is useful for translations).

    (from Google Translate, so may be gramatically dubious)

     

    I like how Japanese writing unabashedly synthesizes the Chinese written language, the Roman alphabet, and its own syllabary into a single system. We could learn something from that: you don't have to (or want to) localize everything. If you're building a hotel, "FIRE" and "EXIT" are good signage choices, even if you don't speak English or even like people to do.


  • FoxDev

    @bridget99 said:

    @RaceProUK said:

    @bridget99 said:

    And Unicode...OMG what a cesspool.

    Unicodeは、翻訳するのに便利です (Unicode is useful for translations).

    (from Google Translate, so may be gramatically dubious)

     

    I like how Japanese writing unabashedly synthesizes the Chinese written language, the Roman alphabet, and its own syllabary into a single system. We could learn something from that: you don't have to (or want to) localize everything. If you're building a hotel, "FIRE" and "EXIT" are good signage choices, even if you don't speak English or even like people to do.


    Let me know how your crusade to Amercanise the world goes. Sorry, that should be Americanize.



  • @RaceProUK said:

    Let me know how your crusade to Amercanise the world goes. Sorry, that should be Americanize.

    The world isn't American already?


  • FoxDev

    @configurator said:

    @RaceProUK said:
    Let me know how your crusade to Amercanise the world goes. Sorry, that should be Americanize.

    The world isn't American already?

    There must be somewhere without a McDonalds.



  • @RaceProUK said:

    @bridget99 said:
    @RaceProUK said:

    @bridget99 said:

    And Unicode...OMG what a cesspool.

    Unicodeは、翻訳するのに便利です (Unicode is useful for translations).

    (from Google Translate, so may be gramatically dubious)

     

    I like how Japanese writing unabashedly synthesizes the Chinese written language, the Roman alphabet, and its own syllabary into a single system. We could learn something from that: you don't have to (or want to) localize everything. If you're building a hotel, "FIRE" and "EXIT" are good signage choices, even if you don't speak English or even like people to do.


    Let me know how your crusade to Amercanise the world goes. Sorry, that should be Americanize.

    I attribute the use of English in many realms to the fact that the English people were good sailors and entrepreneurs. It actually predates the century or so of American warmongering that we've just endured. Really, if we wanted to Americanize the world, we'd be better advised to make everything in Spanish, or Navajo or something like that. Yeah, the most important country in America does basically use a form of Pidgin English for daily discourse... but Spanish is the language of America (including that jacked up Spanish they speak in Brazil).



  • @RaceProUK said:

    There must be somewhere without a McDonalds.

    Apparently so.
    @Wikipedia said:

    Former locations

    1. (November 10, 1985 – March 9, 1995) Bermuda [3] - government influence
    2. (June 30 – December 31, 1996) Barbados [4] - slow sales
    3. (October 24, 1997 – November 30, 2002) Bolivia [5] - closed due to slow sales and cost
    4. (April 15, 1995 – October 30, 2005) Jamaica [6] - closed due to government problems and slow sales
    5. (September 3, 1993 – October 31, 2009) Iceland [7] - Closed down by Icelandic affiliate citing prohibitive costs of importing foreign foodstuffs as required by McDonald's. Its former McDonald's outlets will be re-branded as its own chain of Metro restaurants offering similar service and menus with domestically produced ingredients.
    6. (June 1, 2004 – 2007) Montenegro – A McDonalds restaurant was opened in Budva, but it has been closed due to the lack of location.


  • I attribute the widespread use of English to a) cinema; b) computers; c) the internet


  • FoxDev

    @bridget99 said:

    including that jacked up Spanish they speak in Brazil

    Portuguese.



  • @RaceProUK said:

    @bridget99 said:
    including that jacked up Spanish they speak in Brazil

    Portuguese.

    Jesus Christ, do you people not know what "troll" means!



  • @blakeyrat said:

    @RaceProUK said:
    @bridget99 said:
    including that jacked up Spanish they speak in Brazil

    Portuguese.

    Jesus Christ, do you people not know what "troll" means!

    Yeah, I was trolling our large contingent of Brazilian posters. I'm still pissed off over the way their country dominated CART in the 1990s. Also, I'm jealous of their dancing ability and despise Carnival. Deep inside, I know that the Portuguese language has a rich philology and is not really just a messed up version of Spanish.



  • @Zecc said:

    I attribute the widespread use of English to a) cinema; b) computers; c) the internet
     

    Strangely I attribute widespread americanizm contaminants in the English language to those three.


  • FoxDev

    @blakeyrat said:

    @RaceProUK said:
    @bridget99 said:
    including that jacked up Spanish they speak in Brazil
    Portuguese.

    Jesus Christ, do you people not know what "troll" means!

    Party pooper :P

    Is this what you were talking about:




  • @Cassidy said:

    @Zecc said:

    I attribute the widespread use of English to a) cinema; b) computers; c) the internet
     

    Strangely I attribute widespread americanizm contaminants in the English language to those three.

    We still use -ISM over here in the third-I-mean-new world. We just don't use -ISE, and I think that's good. "Z" is the vocalized version of "S." "Capitalise" looks to my eyes like it should rhyme with "nice."



  • Re: Finally on Try blockz? We've heard of that too.

    @bridget99 said:

    "Zapitalize" lookz to my eyez like it zhould rhyme with "nize."



  • @Ben L. said:

    @bridget99 said:
    "Zapitalize" lookz to my eyez like it zhould rhyme with "nize."

    Point taken, but you've got at least two zeds in there that aren't right, even under the most phonetic of spellings. ZH is the sound in "measure," for example... not the sound in "shut."



  • @bridget99 said:

    @Ben L. said:
    @bridget99 said:
    "Zapitalize" lookz to my eyez like it zhould rhyme with "nize."

    Point taken, but you've got at least two zeds in there that aren't right, even under the most phonetic of spellings. ZH is the sound in "measure," for example... not the sound in "shut."



  • @bridget99 said:

    @Sir Twist said:

    .Length is a property, using it as an rvalue calls the getter. That is a function call. Maybe it's not visible, but it's there.

    Well, if you want to pick nits, they're all method calls, not function calls. But if I were really writing this, I would use == to compare the string to "". I'm sure that results in at least one method call beneath the surface... but that's not really what bothers me. I just think that having a static method of the string class called IsNullOrEmpty is stupid.

    Using the string comparison is a slower operation in .Net, and if you run any optimization checker against your code, you will get warinings about comparing to "".  Using the logic of checking for null, then checking the length property is actually the fastest way to go, once it has been JIT compiled.  Using the String.IsNullOrEmpty(x) makes the code more readable and compiles down to exactly (x == Null || x.Length == 0), with no addtional performance hits.

    The newer IsNullOrWhitespace in framework 4.0 is also nice, as it does the first to comparisons and then continues to see if the string is only comprized of whitespace characters, in a nice concise manor in your code.



  • @The Bytemaster said:

    Using the string comparison is a slower operation in .Net, and if you run any optimization checker against your code, you will get warinings about comparing to "".


    Wait, wait, wait.

    You're telling me that comparing a string to "" takes more than O(1) time? Does == determine just how "not-equal" two strings are?



  • @RaceProUK said:

    "" could contain a zero-width space, String.Empty is guaranteed not to.
     

    Yeah, I always accidentally type a character that is not on a keyboard and is pretty much never found in the wild!

    Oh wait.

     



  • @Ben L. said:

    @The Bytemaster said:

    Using the string comparison is a slower operation in .Net, and if you run any optimization checker against your code, you will get warinings about comparing to "".


    Wait, wait, wait.

    You're telling me that comparing a string to "" takes more than O(1) time? Does == determine just how "not-equal" two strings are?

    Using the == operator in C# (and most string comparisons in .Net languages) will actually process and compare the content of the strings, which can be a costly operation.  If you can be 100% sure the reference is not null, comparing the integer Length property to 0 is the absolute fastest comparison you can do against a string object in .Net.  You can run benchmarks on it and test it out yourself.  Many report it taking up to 10 times longer to compare a string to an empty string as opposed to comparing the length property to 0.  I do not remember the specific numbers I have achieved, but it is noticible, especially in loops.

     You can get more of a performance boost in VB.Net, because you get to bypass that language's string handling functions that determine whether you are doing a case sensitive or case instensitive comparison.

     Because of all of this, and because people forget to check for nulls when they really should. it is a "best practice" to always use String.IsNullOrEmpty for these types of checks... and it takes less time than typing out the whole formula while making the code more readable.



  • @The Bytemaster said:

    @Ben L. said:
    @The Bytemaster said:

    Using the string comparison is a slower operation in .Net, and if you run any optimization checker against your code, you will get warinings about comparing to "".


    Wait, wait, wait.

    You're telling me that comparing a string to "" takes more than O(1) time? Does == determine just how "not-equal" two strings are?

    Using the == operator in C# (and most string comparisons in .Net languages) will actually process and compare the content of the strings, which can be a costly operation.  If you can be 100% sure the reference is not null, comparing the integer Length property to 0 is the absolute fastest comparison you can do against a string object in .Net.  You can run benchmarks on it and test it out yourself.  Many report it taking up to 10 times longer to compare a string to an empty string as opposed to comparing the length property to 0.  I do not remember the specific numbers I have achieved, but it is noticible, especially in loops.

     You can get more of a performance boost in VB.Net, because you get to bypass that language's string handling functions that determine whether you are doing a case sensitive or case instensitive comparison.

     Because of all of this, and because people forget to check for nulls when they really should. it is a "best practice" to always use String.IsNullOrEmpty for these types of checks... and it takes less time than typing out the whole formula while making the code more readable.

    So what you're saying is that there's some calculation (well, nine of them, apparently) needed to compare strings to "" in addition to checking if the lengths differ. What exactly needs to be calculated apart from "oh, the lengths are different, the strings must not be equal" or "the lengths are the same, let's check the conte--okay done"?


  • ♿ (Parody)

    @Ben L. said:

    o what you're saying is that there's some calculation (well, nine of them, apparently) needed to compare strings to "" in addition to checking if the lengths differ. What exactly needs to be calculated apart from "oh, the lengths are different, the strings must not be equal" or "the lengths are the same, let's check the conte--okay done"?

    Backwards compatibility. Duh.



  • @Ben L. said:

    @bridget99 said:
    "Zapitalize" lookz to my eyez like it zhould rhyme with "nize."

    Oh, are we trying to turn the world into Zapinalia, not America, now?

    (wonders if anyone gets the obscure reference...)



  • Generally you have to check whether the arguments are null first as well, so yes, there is additional operations.

    Also, I'm with blakey in this particular thread.



  • @Ben L. said:

    So what you're saying is that there's some calculation (well, nine of them, apparently) needed to compare strings to "" in addition to checking if the lengths differ. What exactly needs to be calculated apart from "oh, the lengths are different, the strings must not be equal" or "the lengths are the same, let's check the conte--okay done"?

    I believe there are other checks, but let us just assume you are correct and we can short circuit it that way. Now, taking into account that you are comparing two string objects vs the "shorthand" method. (Doing this in English rather than IL or assembler)

    String.IsNullOrEmpty(x):

    1. Check to see if x is null and return true if it is
    2. Check to see if x.Length >0 and return true if it is

     

    x == "" :

    1. check to see if x is null
    2. check to see if "" is null
    3. return true if they are both null, false if only one is null, else continue
    4. compare the length property of both strings. If they match, continue, else return false
    5. Since the lengths are equal, prepare to loop through characters one by one to compare them
    6. Loop through the characters to do the comparison
    7. No mismatches encountered, ok, we can return true.

     

    If they add a special test for length=0, then they also slow down all other calls to the String equality operator. Because they are both objects, the recommended way to do this (and documented in many different places) is to test for null first and then check the already existing Length property. Length is not a calculation in .Net but an actual value that is part of managing the string.

    In short, the first takes less time because you are comparing properties of one object to static values (essentially a pointer and an integer) instead of comparing one object to another object, with multiple properties that you have to compare.

    And remember that all strings in .Net are not only objects, but stored in 2-byte Unicode (UTF-16 I believe). Not that it really matters with 0 length strings, but it does matter in how the internal string comparison code works.

    That may not be the exact steps, and I may just be feeding trolls here, but other readers who program with .Net still need to know this.



  • Your forgot the check to see if the two objects are reference-equal.
    Not that it matters— 10x a negligible amount of time is still a negligible amount of time.



  • @Salamander said:

    10x a negligible amount of time is still a negligible amount of time.
     

    All processing scripts that operate on strings run in negligible time.


  • Discourse touched me in a no-no place

    @configurator said:

    Montenegro
    Is it still politically correct to use that word?



  • @dhromed said:

    @Salamander said:

    10x a negligible amount of time is still a negligible amount of time.
     

    All processing scripts that operate on strings run in negligible time.

    It depends on what you are programming and where you are using it what exactly is "negligible".  A single pass on some user input, I would agree with you.  A data processing loop where you are iterating over thousands of records, it can make a big difference.

    Just like using paramaters for in-line SQL queries, this is just a good habit to get into and you don't have to figure out whether it is going to truly have an impact on your overall performance or not.  Plus, you get to keep your code consistant without doing it a haf-dozen different ways throughout your code.



  • @The Bytemaster said:

    It depends on what you are programming and where you are using it what exactly is "negligible".  A single pass on some user input, I would agree with you.  A data processing loop where you are iterating over thousands of records, it can make a big difference.
     

    Sounds like you have an incredibly firm grasp of ridiculing hyperbole and sarcasm.



  • @dhromed said:

    Sounds like you have an incredibly firm grasp of ridiculing hyperbole and sarcasm.
     

    I figured you were being sarcastic. but not the post you were responding to.  Besides, by troll meter is borked right now.  It keeps saying I need a red hearing.

     On the other hand, these forums are filled with so much sarcasm that looks like normal bad advice that newer programmers might not realize it is sarcasm either... causing the Daily WTF forums to generate new WTF material in an never ending cycle.



  • @The Bytemaster said:

    causing the Daily WTF forums to generate new WTF material in an never ending cycle.
     

    You broke the code!

    The secret is OUT!



  • @The Bytemaster said:

    It depends on what you are programming and where you are using it what exactly is "negligible".  A single pass on some user input, I would agree with you.  A data processing loop where you are iterating over thousands of records, it can make a big difference.

    Personally I go by the rule of thumb that the time spent differs by a magnitude of at least 100.
    For example, if one part of a loop spends a total of 10 seconds doing something, it's negligible if the rest of the loop takes more than 17 minutes.



  • @Jaime said:

    @bridget99 said:

    The real WTF is String.IsNullOrEmpty(). My first issue with it is that it's trivial to construct a boolean expression that manages the same thing without a function call. I hate crap like that, where extra ways to do things are grafted onto a language for no goddamned reason. After all, if you don't understand nulls and boolean expressions, you're screwed anyway. Second, how many fucking times does Microsoft expect me to hit the Shift key per day? Like, 80,000? I usually just seeth quietly about "camel case," "Pascal case," and the rest of Microsoft's time-wasting, finger-twisting naming recommendations, but this one is ridiculous. It looks like you're sending the runtime a ransom note.
    I don't use the shift key while typing it.  I type the following keys and intellisense does the rest - s, t, r, {dot}, i, s, n, {right parenthesis}

     

     

    Maybe that bridget person is not using Visual Studio to make coed. He should try using VS 2012 and resharper extended for maximum ease of programming.

     



  • @Nagesh said:

    @Jaime said:

    @bridget99 said:

    The real WTF is String.IsNullOrEmpty(). My first issue with it is that it's trivial to construct a boolean expression that manages the same thing without a function call. I hate crap like that, where extra ways to do things are grafted onto a language for no goddamned reason. After all, if you don't understand nulls and boolean expressions, you're screwed anyway. Second, how many fucking times does Microsoft expect me to hit the Shift key per day? Like, 80,000? I usually just seeth quietly about "camel case," "Pascal case," and the rest of Microsoft's time-wasting, finger-twisting naming recommendations, but this one is ridiculous. It looks like you're sending the runtime a ransom note.
    I don't use the shift key while typing it.  I type the following keys and intellisense does the rest - s, t, r, {dot}, i, s, n, {right parenthesis}

     

     

    Maybe that bridget person is not using Visual Studio to make coed. He should try using VS 2012 and resharper extended for maximum ease of programming.

     

    Nice phony link, dude. I just spent about 15 seconds finger-banging my phone trying to get to the site for Visual Boinketyboink Comic Sharper (or whatever it is). Sure, it's the wrong color, but it's got a line under it.



  • @bridget99 said:
    @Nagesh said:

    @Jaime said:

    @bridget99 said:

    The real WTF is String.IsNullOrEmpty(). My first issue with it is that it's trivial to construct a boolean expression that manages the same thing without a function call. I hate crap like that, where extra ways to do things are grafted onto a language for no goddamned reason. After all, if you don't understand nulls and boolean expressions, you're screwed anyway. Second, how many fucking times does Microsoft expect me to hit the Shift key per day? Like, 80,000? I usually just seeth quietly about "camel case," "Pascal case," and the rest of Microsoft's time-wasting, finger-twisting naming recommendations, but this one is ridiculous. It looks like you're sending the runtime a ransom note.
    I don't use the shift key while typing it.  I type the following keys and intellisense does the rest - s, t, r, {dot}, i, s, n, {right parenthesis}

     

     

    Maybe that bridget person is not using Visual Studio to make coed. He should try using VS 2012 and resharper extended for maximum ease of programming.

     

    Nice phony link, dude. I just spent about 15 seconds finger-banging my phone trying to get to the site for Visual Boinketyboink Comic Sharper (or whatever it is). Sure, it's the wrong color, but it's got a line under it.


    LOOK AT ALL THE LINKS!


  • BINNED

    @The Bytemaster said:

     On the other hand, these forums are filled with so much sarcasm that looks like normal bad advice that newer programmers might not realize it is sarcasm either... causing the Daily WTF forums to generate new WTF material in an never ending cycle.

    Anyone foolish enough to use this site as a sole source of programming advice deserves whatever happens to them as a result.



  • @PedanticCurmudgeon said:

    @The Bytemaster said:

     On the other hand, these forums are filled with so much sarcasm that looks like normal bad advice that newer programmers might not realize it is sarcasm either... causing the Daily WTF forums to generate new WTF material in an never ending cycle.

    Anyone foolish enough to use this site as a sole source of programming advice deserves whatever happens to them as a result.

    People who create WTFs don't read this site. Most of the reason they create WTFs is that they have no desire to learn or grow as a developer, meaning they're not spending their lunch break looking for best practices or developer news sites or what-not.

    If you see a WTF-creator in here, like Bridget99, it's because it's a troll account in here trolling.

    EDIT: or it's a WTF that can't be avoided because you're dealing with fucking retard APIs like DOM and you need to send a pixel load on page unload.



  • @blakeyrat said:

    People who create WTFs don't read this site.
     

    We ought to have a poll to determine just how many of us that previously created WTFs by the fuckload now [ spot | refrain from making ] them as a result of knowledge gained on here.


  • Discourse touched me in a no-no place

    @Ben L. said:
    @bridget99 said:
    @Nagesh said:

    @Jaime said:

    @bridget99 said:

    The real WTF is String.IsNullOrEmpty(). My first issue with it is that it's trivial to construct a boolean expression that manages the same thing without a function call. I hate crap like that, where extra ways to do things are grafted onto a language for no goddamned reason. After all, if you don't understand nulls and boolean expressions, you're screwed anyway. Second, how many fucking times does Microsoft expect me to hit the Shift key per day? Like, 80,000? I usually just seeth quietly about "camel case," "Pascal case," and the rest of Microsoft's time-wasting, finger-twisting naming recommendations, but this one is ridiculous. It looks like you're sending the runtime a ransom note.
    I don't use the shift key while typing it.  I type the following keys and intellisense does the rest - s, t, r, {dot}, i, s, n, {right parenthesis}

     

     

    Maybe that bridget person is not using Visual Studio to make coed. He should try using VS 2012 and resharper extended for maximum ease of programming.

     

    Nice phony link, dude. I just spent about 15 seconds finger-banging my phone trying to get to the site for Visual Boinketyboink Comic Sharper (or whatever it is). Sure, it's the wrong color, but it's got a line under it.


    LOOK AT ALL THE LINKS!
    FTFY



  • @PJH said:
    @Ben L. said:
    @bridget99 said:
    @Nagesh said:
    @Jaime said:
    @bridget99 said:
    The real WTF is String.IsNullOrEmpty(). My first issue with it is that it's trivial to construct a boolean expression that manages the same thing without a function call. I hate crap like that, where extra ways to do things are grafted onto a language for no goddamned reason. After all, if you don't understand nulls and boolean expressions, you're screwed anyway. Second, how many fucking times does Microsoft expect me to hit the Shift key per day? Like, 80,000? I usually just seeth quietly about "camel case," "Pascal case," and the rest of Microsoft's time-wasting, finger-twisting naming recommendations, but this one is ridiculous. It looks like you're sending the runtime a ransom note.

    I don't use the shift key while typing it. I type the following keys and intellisense does the rest - s, t, r, {dot}, i, s, n, {right parenthesis}

    Maybe that bridget person is not using Visual Studio to make coed. He should try using VS 2012 and resharper extended for maximum ease of programming.

    Nice phony link, dude. I just spent about 15 seconds finger-banging my phone trying to get to the site for Visual Boinketyboink Comic Sharper (or whatever it is). Sure, it's the wrong color, but it's got a line under it
    .

    LOOK AT ALL THE LINKS!

    FTFY

    FTFY


Log in to reply