Talking to the code



  • I just found this on the code I'm trying to fix... Not really a big WTF but anyway.

    # Go DEBUG almight, show us what's is going on!
    if ($debug)
    {
        print "\n\t - Environment:Device selected: $environmentsAndDevices\n";
    }
    		
    (local $envName, local $hostame) = split(':',$environmentsAndDevices);
    			
    # Chompz! 
    chomp($envName);
    chomp($hostame);
    			
    # Clean! to assure it will be empty (concatenated variable)
    $arrGrpName = "";
    $arrUserName = "";
    
     (snip...)
    


  • @LegacyCrono said:

    I just found this on the code I'm trying to fix... Not really a big WTF but anyway.

    # Go DEBUG almight, show us what's is going on!
    if ($debug)
    {
        print "\n\t - Environment:Device selected: $environmentsAndDevices\n";
    }
    		
    (local $envName, local $hostame) = split(':',$environmentsAndDevices);
    			
    # Chompz! 
    chomp($envName);
    chomp($hostame);
    			
    # Clean! to assure it will be empty (concatenated variable)
    $arrGrpName = "";
    $arrUserName = "";
    
     (snip...)
    

    Possibly a case of CDD (Comment Driven Development).

    1. Type comments in empty text files
    2. Have someone translate comments in Hindi or Chinese
    3. Send text files to off-shore programmers so they fill the blanks between comments
    4. Have someone translate comments back to English
    5. Compile and run

    I see no weakness in this model.



  • Talking to the code is a great method of debugging, actually. Coding Horror refers to it as rubber duck problem solving.



  • @nexekho said:

    Talking to the code is a great method of debugging, actually. Coding Horror refers to it as rubber duck problem solving.

    +1 Like :thumbs-high:



  •  @zelmak said:

    @nexekho said:

    Talking to the code is a great method of debugging, actually. Coding Horror refers to it as rubber duck problem solving.

    +1 Like :thumbs-high:

    Reminds me of Alan Turing's teddy bear: the first student for each of his lectures, and your first point of call at King's College help desk.

     



  • I tend to wrie comments for every method.. Step-by-step of what needs to happen, then I go code it.

    It works better because I care less about stupid things when thinking, and more about the overall result and flow.



  • @nexekho said:

    Talking to the code is a great method of debugging, actually. Coding Horror refers to it as rubber duck problem solving.
     

    However, saying "chompz" to your code, doesn't really do very much, does it? It's the

    [code]

        i++; /* increment i by one */

    [/code]

    style of commenting.



  • @gu3st said:

    I tend to wrie comments for every method.. Step-by-step of what needs to happen, then I go code it.

    It works better because I care less about stupid things when thinking, and more about the overall result and flow.

    But then you delete the comments, right, instead of leaving a useless crap in the code?



  • @LegacyCrono said:

    $arrGrpName = "";
    $arrUserName = "";

    (snip...)

     

    Hungarian Pirate Notation. Nice.

     



  • @nexekho said:

    Talking to the code is a great method of debugging, actually. Coding Horror refers to it as rubber duck problem solving.
    Seems more like a coder psychoanalysis to me... (solving your problems [i]because[/i] you formulate/verbalize them)



  • @TGV said:

    However, saying "chompz" to your code, doesn't really do very much, does it?
    No, but it might make you feel better.
    @TGV said:
    Coding Horror refers to it as rubber duck problem solving

    Not to be confused with rubber duck typing (duck typing with extra sado-masochism) that everyone says is such WTF in PHP but what about python eh? eh?



  • @token_woman said:

    @TGV said:
    However, saying "chompz" to your code, doesn't really do very much, does it?
    No, but it might make you feel better.
    @TGV said:
    Coding Horror refers to it as rubber duck problem solving

    Not to be confused with rubber duck typing (duck typing with extra sado-masochism) that everyone says is such WTF in PHP but what about python eh? eh?

    What's so WTF about it? Most languages have facilities for something like this. Staticly compiled languages (Java, C#, etc) tend to do this via interfaces (to ensure the object does, in fact, quack like a duck), and you typically have to invoke a reflection namespace in order to create new objects whose classes you don't know at compile time, but conceptually it's no different.



  • @pkmnfrk said:

    What's so WTF about it?
    Nothing, to my mind - I think it's rather good. I'm about to start PHPing again after a foray into the static-typed world, and being able to do $classname.someStaticMethod() is something I'm looking forward to.


    Point (highly distracted) I was trying to make was ... people always say it is a WTF in PHP and their reason is usually that it is easy to end up with unmaintainable code (hence the SM joke) and that is true if you try and be too clever with it and don't comment etc, but you don't hear so much that it is a WTF in python. I think my point was, stop discriminating against PHP ... or something ... yes you're right you can do something similar in Java (reflection ... not sure I agree about interfaces doing the same thing but I do see what you mean by it) although I've never been Java enough to do it and it looks like a ball-ache. Ironic really that the reason for calling it a WTF seems to be largely that in PHP it is too easy to do and therefore people do it! Not such a disgrace, one would think, for a language feature. </ramble>



  •  This to me speaks of someone just out of college with that still beaten in notion that you must "comment your code" with no teaching done on how to do it correctly or even why it is important. They simply understand that code needs comments, so they will put comments in.

     

    TRWTF is clearly that this is readable PERL and last I checked that was against policy.



  • @morbiuswilters said:

    @gu3st said:
    I tend to wrie comments for every method.. Step-by-step of what needs to happen, then I go code it.

    It works better because I care less about stupid things when thinking, and more about the overall result and flow.

    But then you delete the comments, right, instead of leaving a useless crap in the code?

    I'll go comment my code again based upon the actual implementation, yes.



  • @pkmnfrk said:

    @token_woman said:
    @TGV said:
    Coding Horror refers to it as rubber duck problem solving

    Not to be confused with rubber duck typing (duck typing with extra sado-masochism) that everyone says is such WTF in PHP but what about python eh? eh?

    What's so WTF about it? Most languages have facilities for something like this. Staticly compiled languages (Java, C#, etc) tend to do this via interfaces (to ensure the object does, in fact, quack like a duck), and you typically have to invoke a reflection namespace in order to create new objects whose classes you don't know at compile time, but conceptually it's no different.

    Apart from the fact that it wasn't my statement: compilation is static, I think you meant statically typed. And there is no interface involved: it's in the syntax. You can't even invoke an arbitrary interface, unless the type is correct. And where the heck did the need for a "reflection namespace" come from? There is a whole "pattern" book devoted to just avoiding that. And it's just called reflection: it's not important that some language puts certain library functions in a separate namespace. And yes, static typing is rather different than dynamic or "duck" typing.

    Where did you go to school? Did you go to school? Are you just copying wikipedia and brainoverflow.com?



  • @TGV said:

    @pkmnfrk said:

    @token_woman said:
    @TGV said:
    Coding Horror refers to it as rubber duck problem solving

    Not to be confused with rubber duck typing (duck typing with extra sado-masochism) that everyone says is such WTF in PHP but what about python eh? eh?

    What's so WTF about it? Most languages have facilities for something like this. Staticly compiled languages (Java, C#, etc) tend to do this via interfaces (to ensure the object does, in fact, quack like a duck), and you typically have to invoke a reflection namespace in order to create new objects whose classes you don't know at compile time, but conceptually it's no different.

    Apart from the fact that it wasn't my statement: compilation is static, I think you meant statically typed. And there is no interface involved: it's in the syntax. You can't even invoke an arbitrary interface, unless the type is correct. And where the heck did the need for a "reflection namespace" come from? There is a whole "pattern" book devoted to just avoiding that. And it's just called reflection: it's not important that some language puts certain library functions in a separate namespace. And yes, static typing is rather different than dynamic or "duck" typing.

    Where did you go to school? Did you go to school? Are you just copying wikipedia and brainoverflow.com?

    It is different, but mainly in implementation. If you are expecting an object to have a quack() method, and a feathers property, but don't care what kind of object it really is, that's duck typing. That can be represented as dynamic dispatch at run time, or by interfaces at compile time, in languages that support these respective features.

    In C#, my specialty, you use interfaces to get this behaviour. To take it a step further, and completely isolate class dependencies (eg, IoC), you don't even specify the concrete type at all, and instead put it in a config file or some such bullshit. Now, the class name is in a string and cannot be bound at compile time. That means you cannot write new myStringVariable(), and have to use reflection to instantiate it instead, and cast it to whatever interface you are expecting.

    That's all I'm saying, I don't see why hostility is necessary.

    Edit: Also, I wasn't even replying to you or rubber-duck problem solving, I was replying to rubber-duck typing which, I guess, means doing "new $class()" in PHP, and how that can be done in other languages, and isn't that big of a WTF.



  • @pkmnfrk said:

    don't see why hostility is necessary.

    You must be new here.



  • @boomzilla said:

    @pkmnfrk said:
    don't see why hostility is necessary.

    You must be new here.

    Oh, shoot, yeah, I'm sorry. I often forget about that.

    Dick.



  • @TGV said:

    duck typing

    Is it the same as dick-tation?



  • @pkmnfrk said:

    That can be represented as dynamic dispatch at run time, or by interfaces at compile time, in languages that support these respective features.

    Interfaces are not an example of duck typing. An interface is a defined, static type; implementations of the interface are nominal subtypes. Templates/generics can exhibit similarities to duck typing (although not Java generics, I believe, because the type variables are strictly enforced).



  • @alegr said:

    @TGV said:

    duck typing

    Is it the same as dick-tation?

    Is that anything like lac-tation?



  • @morbiuswilters said:

    @alegr said:
    Is it the same as dick-tation?

    Is that anything like lac-tation?

    Yes



  • @token_woman said:

    @morbiuswilters said:
    @alegr said:
    Is it the same as dick-tation?

    Is that anything like lac-tation?

    Yes

    I'm not sure whether I should hate you for stripping away the last of my dignity and humanity, or love you for giving me yet another tool to strip away the dignity and humanity of others.



  • @morbiuswilters said:

    @token_woman said:
    @morbiuswilters said:
    @alegr said:
    Is it the same as dick-tation?

    Is that anything like lac-tation?

    Yes

    I'm not sure whether I should hate you for stripping away the last of my dignity and humanity, or love you for giving me yet another tool to strip away the dignity and humanity of others.

     

    oh my fucking goodness me



  • @nexekho said:

    Talking to the code is a great method of debugging, actually. Coding Horror refers to it as rubber duck problem solving.

    @a comment from a link from your link said:

    For a while, I used a dinosaur hand puppet for this, and gave him Strong Bad's voice.




Log in to reply
 

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