Noop



  • Got this from our outsourced developers in NZ:

    str = str.Substring(0,str.Length);

    They're also practitioners of the "cut-and-paste school of reuse." But that's a story for another day.



  • @stannius said:

    They're also practitioners of the "cut-and-paste school of reuse." But that's a story for another day.



    ah yes, good ol' "VB inheritance"



  • You have to wonder why they wrote this "Hmm i hope the string isnt longer than itself. Lets shorted the string to it's own length to make sure."

    BTW i'm from New Zealand, and no i'm not submiting any of my code to this site.



  • Depends on the programing language... but that may be the faster way to clone a String.



  • @trollable said:

    Depends on the programing language... but that may be the faster way to clone a String.


    Do it 1,000,000 times in a loop on a large string and we'll know.



  • @paranoidgeek said:

    You have to wonder why they wrote this "Hmm
    i hope the string isnt longer than itself. Lets shorted the string to
    it's own length to make sure."




    Well, if it were Java (which it's not) that actually would make sense,
    because Java Strings are basically wrappers around a char array with a
    start index and a length, The array can be shared between strings, and
    a String referring to a very short part of the array could prevent all
    of it from being garbage collected.



    But in Java, the substring() method always keeps the whole array;
    copying and keeping only the part referred by a particular String is
    done with the String(String) constructor.



    Mybe in whatever language this is, this is the way to do it.



  • @OpBaI said:

    In Python this "substring method" is actually the way how to clone an array:

    >>> a = [17]
    >>> b = a
    >>> a += [1]
    >>> b
    [17, 1]

    is a reference, but

    >>> a = [17]
    >>> b = a[:]
    >>> a += [1]
    >>> b
    [17]

    copies ([:] is a shorthand for [0:len(a)])

    Duh, it's one way to clone a list. I usually use b = list(a) myself.


Log in to reply
 

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