When Toddlers Program



  • // set no timeout
    cmd.CommandTimeout = 0;



  • You ought to look at some of my comments someday. One of the lead devs has a code review policy of "I want to be able to blank out the code, display only the comments, and still know what each line of the procedure is doing and how".



  • Except that setting CommandTimeout to 0 can just as easily (if not more easily) mean the command will timeout unless it succeeds immediately.
    (To mean "no timeout", good apis should either use optional/nullable types or provide you with some kind of INFINITE constant. (Which is usually -1, not 0, by the way.))



  • @Maciejasjmj said:

    One of the lead devs

    Is basically admitting that he can't read code, and needs to go back to go, do not collect $200.



  • @CreatedToDislikeThis said:

    unless it succeeds immediately.

    As in, it goes back in time, undoes the whole execution process, and ends itself? Any sort of "succeeding" involves a non-zero time pretty much by necessity.


    Filed under: you could use -1, but then a guy in a blue police box can fuck your system over too



  • @Maciejasjmj said:

    "I want to be able to blank out the code, display only the comments, and still know what each line of the procedure is doing and how"

    :wtf:



  • Makes refactors double the fun!


    Filed under: certain definitions of fun



  • The instantaneous timeout does actually make sense (for certain definition of sense) and will not be just fancy jump to nok code path - under one condition: it's do...while and not just while.



  • If you can control when the time check happens, that is, and guarantee you won't get one instantly after the call. Then maybe your command has a chance on doing something.

    It's still pointless, but there might be an use case, maybe?



  • @Maciejasjmj said:

    I want to be able to blank out the code, display only the comments, and still know what each line of the procedure is doing and how"

    // bReset = false;
    bReset = false;

    Or:
    cat x.cpp | sed /^////
    (think I got that right - been a long time since I used sed)



  • I was thinking about a simple shell script after 342830948th instance of:

    ///<summary>
    ///Returns all widgets.
    ///</summary>
    ///<returns>A list of all widgets</returns>
    public List<Widget> GetAllWidgets()
    {
        //get a list of all widgets from the repository and return it
        return repository.Widgets.ToList();
    }
    


  • This seems to work:

    $ echo hi | sed 's/.*/\/\/&\n&/'
    //hi
    hi
    

    This also works but comments after the line:

    $ echo hi | sed 'p;s/^/\/\//'
    hi
    //hi
    


  • I was going for the simple 'transform the source into a commented file'. But I like yours... (The 2nd pass is a bitch though)



  • @Maciejasjmj said:

    It's still pointless, but there might be an use case, maybe?

    Let's say I'm writing a unit test for socket... um... opitalacz, from lack of better word. I call a method on unit under test, and it's supposed to synchronously send a message over a socket, and then listen on the other end for it. The message will either get there before I start listening, or it won't be sent at all - anything inbetween would mean there's a race condition in the universe or something.



  • @Gaska said:

    opitalacz

    +1

    That's a bit different than what was in the OP (it's basically a non-blocking receive, which is not an uncommon use case, as opposed to dispatching a task with maximum running time set to zero), and I haven't really considered it.

    What I was thinking about was more like "you send a message over a socket (let's say to a local service, to simplify) and immediately start listening for a response with a non-blocking receive", which would maybe work if you hit a thread switch at exactly the time between sending the message and setting up a receiver, let the service run long enough to respond, and then resumed the program.


  • Discourse touched me in a no-no place

    @Gaska said:

    opitalacz

    What's that mean, for those of us who know 3-or-fewer Polish words? (Google Translate gave up).


  • SockDev

    @Maciejasjmj said:

    One of the lead devs has a code review policy of "I want to be able to blank out the code, display only the comments, and still know what each line of the procedure is doing and how".

    ....... :wtf:

    that is not sane!



  • @FrostCat said:

    Google Translate gave up

    Don't blame it. It means "the one who" + opitalać, which itself is the bowdlerized version of "opierdalać", which aside from stemming from "pierdolić" (meaning "to fuck"/"to talk shit"/"to disregard"/"to mistake"/"to break down"/"to be slow") also means "to chew out", "to eat", "to cut one's hair", or "to fuck around".

    Or, in this context, something like the English "thingamajig".

    You're welcome.



  • @accalia said:

    that is not sane!

    A lot of not-sane things going around with respect to coding guidelines. Obtuse, laid out guidelines for putting changelogs in comments. Heavy pressure on UI/BL/DAL isolation which allows for things like stringbuilding an INSERT query in the click handler. And my colleague just got chewed out for sending an e-mail using SQL Server's builtin instead of a procedure living in a totally different database, despite the latter having strictly less features, and his superior getting chewed out for kindly telling the guy to go screw a tree, they don't have time to rewrite the thing.

    At least my own code reviews are nice - "So, show me your code. *opens VS* Okay, you have code, that's good. Now, can you spend an hour going through all the forms layout with me?"



  • @Maciejasjmj said:

    And my colleague just got chewed out for sending an e-mail using SQL Server's builtin instead of a procedure living in a totally different database, despite the latter having strictly less features,

    "Service isolation for stability, maintainability, reliability. Go convince them to take us as a dependency. And while you're there, go screw a tree."


  • Discourse touched me in a no-no place

    @Maciejasjmj said:

    Or, in this context, something like the English "thingamajig".

    whoo-hoo, now I know about 4 or less Polish words.

    oh, crap, I forgot the others. To be fair it's been like 35 years.



  • @Maciejasjmj said:

    A lot of not-sane things going around with respect to coding guidelines. Obtuse, laid out guidelines for putting changelogs in comments. Heavy pressure on UI/BL/DAL isolation which allows for things like stringbuilding an INSERT query in the click handler. And my colleague just got chewed out for sending an e-mail using SQL Server's builtin instead of a procedure living in a totally different database

    takes notes

    Did I mention one of my KPIs for this year involves establishing some coding guidelines? :grin:




  • Try it here: https://turtleacademy.com/playground/en


  • area_deu

    Something I posted elsewhere before:

    TO DRAWEDGE :level :maxlevel :length
    IFELSE :level >= :maxlevel 
       [forward :length]
       [drawedge SUM :level 1 :maxlevel QUOTIENT :length 3
        right 60 drawedge SUM :level 1 :maxlevel QUOTIENT :length 3
        left 120 drawedge SUM :level 1 :maxlevel QUOTIENT :length 3
        right 60 drawedge SUM :level 1 :maxlevel QUOTIENT :length 3]
    END
    
    TO DRAWFLAKE :iterations :size
    PENDOWN
    REPEAT 3 [drawedge 0 :iterations :size left 120]
    PENUP
    END
    

    Try calling it by typing DRAWFLAKE 6 243 (left parameter is number of iterations, right parameter is edge size)



  • You'd get fucking fired for writing comments like that here.

    (Well, in my dreams at least. Though we do have a guideline that sort of says "don't write comments that are shit".)


  • Discourse touched me in a no-no place

    @PleegWat said:

    sed 'p;s/^////'

    I like this, but you do know that you don't need to use / as a RE delimiter after s?

    $ echo hi | sed 'p;s,^,//,'
    hi
    //hi
    

  • Discourse touched me in a no-no place

    @Maciejasjmj said:

    stringbuilding an INSERT query in the click handler

    :confounded:



  • I often forget.

    Also my test platform last night was busybox, so I wasn't sure on my available featureset.



  • This reminds me of the kind of stuff I inherited from the vendor. Their insistence on using StyleCop has led to people adding the bare minimum in comments just to silence the product.

    And man, do I hate it when a comment is literally the pseudo-code version of the following line. Rather tell me why you had to write code in this particular way, or that something needs to be considered before changing the method.



  • Whoosh



  • Definitely. Not all code needs comments to be readable, and comments inflate your line count leading to larger structures being harder to see in one glance. And no comments are always better than misleading comments, or comments which just duplicate what the code is already telling you.

    I've got a file over here which invokes about 20 semi-related functions, as follows:

    /* Frobnicate the foos
    */
    printf( "Frobnicating the foos" );
    frobnicate_foos();
    


  • I don't know. Misleading comments can be a lot more fun than no comments, especially when your code will be subjected to an "I only read the comments" review.

    /* Make sure that this code is not being executed by the admin user*/
    if ( ( adminflag = 1) && (groupflag == 1) ) { 
      thisshouldneverhappen = 1;
    }
    
    /* We are perfectly safe doing this but only if the user is admin. */
    if (adminflag == 1) {
      system ("/usr/local/bin/command --incredibly-dangerous --disable-holodeck-safety-protocols --suppress-all-warnings");
    } else {
      /* If not, then raise a warning and show the world how smart we are. */
      log_message("Bad user!  Spank spank!");
    }

  • Discourse touched me in a no-no place

    @PleegWat said:

    I've got a file over here which invokes about 20 semi-related functions, as follows:

    /* Frobnicate the foos
    */
    printf( "Frobnicating the foos" );
    frobnicate_foos();
    ```</blockquote>
    
    You're missing another `printf` after the call to announce that the foos have been frobnicated. (Preferably with a stack trace log as well for verbose uselessness raisins, except they're usually a PITA to get with C.)


  • I do believe we've got a stacktrace printer - ~20 lines of code. Used when the setuid daemon segfaults.


  • Discourse touched me in a no-no place

    If you've got one, print a stack trace with each of those logging messages. Like that you'll know exactly what's going on everywhere! (You'll also fill up HDDs like it is going out of fashion…)



  • @Maciejasjmj said:

    One of the lead devs has a code review policy of "I want to be able to blank out the code, display only the comments, and still know what each line of the procedure is doing and how".

    I think s/he should team up with one of my former coworkers who subscribed to the "all code must be self-documenting" school of thought and actively went through repositories deleting comments out of every source file.


  • Winner of the 2016 Presidential Election

    @PleegWat said:

    Used when the setuid daemon segfaults.

    o.O



  • Shit happens sometimes. Full core dumps are disabled by default for security reasons, and the backtrace at least tells you which module you should be looking in, and whether it's a known issue.

    I'm working in a product context - too many different environments and hardware setups that you could reasonably assume crashes never happen.


  • Winner of the 2016 Presidential Election

    Oh so it's more of a defensive programming thing rather than a regular occurrence. I was slightly concerned...



  • Seriously? None of y'all got the joke about toddlers and timeout?


  • mod

    More like it just got ignored.



  • I'm a little ashamed to admit that I didn't.



  • Pretty much. As mentioned, this is a product context so unpredictable hardware/OS setups, it's critical enough that a customer will want to get stuff running first and you don't get access for analysis so you have to make do with what you log. And this one handles too much sensitive info for the average customer to be willing to send a coredump.


  • Impossible Mission Players - A

    Hold on, wait a minute, just one second please!
    There's a JOKE here?! What is the meaning of this?


  • I survived the hour long Uno hand

    @jhanderson said:

    None of y'all got the joke

    I lol'd, liked, and moved on with my day :)



  • @PleegWat said:

    or comments which just duplicate what the code is already telling you.

    Like this?

    ...
    blahblah...;
    
    ///////////////////////////////////////////////////////////////////////////////
    // End of AboutDlg.h
    ///////////////////////////////////////////////////////////////////////////////
    

    (well, duh, of course it's the end of the file.)


Log in to reply
 

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