Programming Confessions Thread



  • Confession: I wrote a Linux program that can't handle filenames with newlines in them. It merely detects them and throws an error.

    I know, I know, I'm a disgrace.



  • @anonymous234 said in Programming Confessions Thread:

    Confession: I wrote a Linux program that can't handle filenames with newlines in them. It merely detects them and throws an error.

    I know, I know, I'm a disgrace.

    I don't know - shouldn't this be in the brags thread? You handle them. Unlike 99.99999% of other programs that just die (or do really bad things).


  • Impossible Mission - B

    @dcon Either that or in Side Bar WTF, because what kind of moron designs a file system that allows newlines in filenames in the first place?!?



  • @anonymous234 what I want to know is how this business requirement came to be a "feature" of the code in the first place.


  • FoxDev

    @masonwheeler said in Programming Confessions Thread:

    @dcon Either that or in Side Bar WTF, because what kind of moron designs a file system that allows newlines in filenames in the first place?!?

    Someone who was writing it in 1977, and couldn't spare excess bytes on fripperies like excluding nonsensical characters from file paths



  • @dcon To be fair, I'm getting the paths directly from the kernel in their own strings, so all I have to do is strchr(string, '\n') to detect it.

    The problem is that I have to pass that string to another process via a pipe, along with a bunch of other info. The easy way to do that is to output [filename][separator1][other field][separator1][other field][separator1]... and then [separator2] at the end of each record. Then on the other end you can split the input on [separator2] and pass it to a different function, that splits on [separator1] and handles the fields. You get clear, clean code.

    But there is only ONE character that's not allowed in Linux paths (NUL). So that complicates things. Now you have to count fields, or escape the character, or something that takes more than one line of code. Or you can say "fuck it" and do it the easy way.

    (...or I just realized you could use NUL to separate fields and NULNUL to separate records)

    Gee, if only anyone had invented some sort of structured data I could pass around so I wouldn't have to deal with these things.


  • Impossible Mission - B

    @RaceProUK said in Programming Confessions Thread:

    Someone who was writing it in 1977, and couldn't spare excess bytes on fripperies like excluding nonsensical characters from file paths

    And yet somehow the CP/M folks managed it...


  • Discourse touched me in a no-no place

    @masonwheeler CP/M did't have subdirectories.


  • ♿ (Parody)

    @dkf Nevertheless, shethey persisted.



  • One that @boomzilla (IIRC) or anyone else who's used Informatica will understand:

    I made an expression transformation with over 1600 ports.

    I can't easily see exactly how many because once you get over 1000 the port number just shows the first two digits and "...", followed by the last digit which is scrolled onto another line so that only the top is visible. The column width adjustment icon shows up if you try to widen the port number column, but you can't actually change the width.



  • I am working on a legacy app that has been end of life for over 2 years.

    It is a huge monstrosity of ColdFusion/SQL Server.

    I am throwing in some extra reports and because adding to the navigation is a Rube Goldberg process and I am reusing some existing pages.

    One of these has a dropdown for Report Type. I started out hardcoding 9999, then I needed a few more.

    I decided to update the if to

    <cfif ReportType gt 9000> 
    

    Of course, I added the comment

    It's over 9000!



  • @karla said in Programming Confessions Thread:

    It's over 9000!

    (In HAL 9000's voice): Just what do you think you're doing, Karla?


  • BINNED

    @timebandit
    I can't let you do that Karla...



  • @luhmann said in Programming Confessions Thread:

    @timebandit
    I can't let you do that Karla...

    OK, turned out...I didn't need it. :sadface:



  • @karla said in Programming Confessions Thread:

    I am working on a legacy app that has been end of life for over 2 years.

    :wtf: ???



  • @dcon said in Programming Confessions Thread:

    @karla said in Programming Confessions Thread:

    I am ***working on*** a legacy app that has been ***end of life for over 2 years***.
    

    :wtf: ???

    Much of the story is in the lounge.

    But TL:DR;

    The replacement app still isn't ready. Contract changes require the changes to be made in the legacy app.



  • @karla said in Programming Confessions Thread:

    Contract changes require the changes to be made in the legacy app.

    Ah, that "end of life"... It's alive and feasting on developers sanity. Got it! :)


  • BINNED

    $dateTimeformatter = new \IntlDateFormatter($_SESSION['locale'],
    	\IntlDateFormatter::SHORT, \IntlDateFormatter::MEDIUM);
    $dateTimeFormat = $formatter->getPattern();
    // I'm so, so sorry...
    $dateTimeFormat = preg_replace('/([^y])y([^y])/', '$1yyyy$2', $dateTimeFormat);
    
    /* snip */
    
    $sheet->setCellValue($cellName, \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($time));
    $sheet->getStyle($cellName)
    	->getNumberFormat()
    	->setFormatCode(strtolower($dateTimeFormat));
    


  • Over-engineering to the point that it is indistinguishable from avoidance.

    For example, I was recently trying to 'get back on the horse' through what I thought would be a simple, confidence-building project: a simple turtle graphics implementation. Nothing of any real use, just a way to remind myself that, yes, I do know how to code, and can do it well.

    Nice, easy, well-trod ground any competent coder should be able to knock out in a day or two with nothing more than a compiler or interpreter, and a function for plotting a point in a window. Sounds straightforward, right?

    Not if you spend most of a day dithering over which language to do it in. With side arguments in favor or writing a new language just for the sake of the project.

    Eventually, I beat those impulses into submission (temporarily, they would reappear time and again), and settled on using Python with TkInter. Never mind that Python has a perfectly serviceable turtle graphics package, this is just for me to practice with.

    I start by writing a simple TkInter app. I turn that into a class that abstracts to a 'chalkboard' and a 'plot()' function.

    I then start writing a Vector class, as an intermediate between plotting coordinates and moving a turtle - standard stuff, based on the old model from the book Turtle Geometry, though doing a class instead of just using a list to hold them (as the book did in its Logo-esque pseudo-code) might be a bit much. Wait, why I am I supporting vectors of indefinite dimensions, again?

    Halfway through this excess, I decide that I don't like the idea of just passing an (x,y) pair to the plotting function, and divert to a Point class. Which again is going to allow any number of dimensions, for some reason.

    I finally gave up when I found myself writing a wrapper class encapsulating the concept of a a ranged vector space, because I wanted to use it in a class encapsulating the concept of scaling factors, so that I could write a class to encapsulate RGBA colors and alpha compositing which could accept multiple formats in the constructor.

    Yeah. I get like that. A lot.

    This is what happens when Fear Of Success declares war on Fear Of Failure.

    Filed Under: I Am Definitely Not Going To Need It.


  • 🚽 Regular

    @scholrlea said in Programming Confessions Thread:

    Python with TkInter

    The Bad Ideas Thread is :arrows:



  • I became so thoroughly disgusted with all CPAN (it's a Perl thing) clients out there that I write packaging tools for my Perl project in Python. Because fuck Perl, really. I can work with it, but it's like doing autopsies — you really don't want to spend any more time with it than is strictly necessary.



  • @dcon said in Programming Confessions Thread:

    @karla said in Programming Confessions Thread:

    Contract changes require the changes to be made in the legacy app.

    Ah, that "end of life"... It's alive and feasting on developers sanity. Got it! :)

    And holy fuck...looks like it will still be a plan B for 2018-07-01.



  • @luhmann said in Programming Confessions Thread:

    @timebandit
    I can't let you do that StarFox...

    SWTFY, because why not.


  • And then the murders began.

    @karla said in Programming Confessions Thread:

    And holy fuck...looks like it will still be a plan B for 2018-07-01.

    Be honest, though, are you really that surprised? (Or am I just too used to nobody here making their deadlines for replacing deprecated ?)



  • @unperverted-vixen said in Programming Confessions Thread:

    @karla said in Programming Confessions Thread:

    And holy fuck...looks like it will still be a plan B for 2018-07-01.

    Be honest, though, are you really that surprised? (Or am I just too used to nobody here making their deadlines for replacing deprecated ?)

    Yeah, we should have bailed on the replacement a year ago.

    Yeah, I'm now back to I want another job. Because the work I'm going to have to do for the next year is either ColdFusion or Angular web resources to replace the horrible UI that is Microsoft Dynamics CRM. `

    So I will get competent in Angular, get my Scrum certification (which is included with the training they gave us) , etc to put me in a better position to be hired elsewhere.


  • Considered Harmful

    @karla said in Programming Confessions Thread:

    @unperverted-vixen said in Programming Confessions Thread:

    @karla said in Programming Confessions Thread:

    And holy fuck...looks like it will still be a plan B for 2018-07-01.

    Be honest, though, are you really that surprised? (Or am I just too used to nobody here making their deadlines for replacing deprecated ?)

    Yeah, we should have bailed on the replacement a year ago.

    Yeah, I'm now back to I want another job. Because the work I'm going to have to do for the next year is either ColdFusion or Angular web resources to replace the horrible UI that is Microsoft Dynamics CRM. `

    So I will get competent in Angular, get my Scrum certification (which is included with the training they gave us) , etc to put me in a better position to be hired elsewhere.

    What's wrong with MS Dynamics CRM?


  • FoxDev

    @pie_flavor said in Programming Confessions Thread:

    What's wrong with MS Dynamics CRM?

    If it's good enough for the Renault F1 team, then... I'm not sure if that's a good thing or not, tbh.



  • @pie_flavor said in Programming Confessions Thread:

    @karla said in Programming Confessions Thread:

    @unperverted-vixen said in Programming Confessions Thread:

    @karla said in Programming Confessions Thread:

    And holy fuck...looks like it will still be a plan B for 2018-07-01.

    Be honest, though, are you really that surprised? (Or am I just too used to nobody here making their deadlines for replacing deprecated ?)

    Yeah, we should have bailed on the replacement a year ago.

    Yeah, I'm now back to I want another job. Because the work I'm going to have to do for the next year is either ColdFusion or Angular web resources to replace the horrible UI that is Microsoft Dynamics CRM. `

    So I will get competent in Angular, get my Scrum certification (which is included with the training they gave us) , etc to put me in a better position to be hired elsewhere.

    What's wrong with MS Dynamics CRM?

    First it simply wasn't a good use of it. Second the contractors used junior developers who transferred in and out of the contract so they have no developmental standards. There are magic strings everywhere.

    For my issues with CRM itself:
    It is too much of a black box.
    I want to develop code not configure entities.
    As far as I can tell no unit test (not that we have them anywhere else but there's hope elsewhere).
    Difficulty in manual testing to log in as different users.
    Too much tedium, if I want a JavaScript library on every form I have to manually add it to every form.


  • Discourse touched me in a no-no place

    @scholrlea said in Programming Confessions Thread:

    TkInter

    There are worse things to build on. Like… most of the other toolkits. Tkinter looks old, but works well.


  • BINNED

    $data['heard'] = ($data['heard'] == true) ? 'true' : 'false'; // Fuck you, PHP
    

    Long story short, after the all json_encodes and DB abstractions fields set to false don't even get sent to the DB properly...


    Filed under: Ducking typing


  • ♿ (Parody)

    @onyx I'll bet that was a fun one to track down.


  • Considered Harmful

    @onyx Reminds me of one of mine.


  • Notification Spam Recipient

    @anonymous234 said in Programming Confessions Thread:

    (...or I just realized you could use NUL to separate fields and NULNUL to separate records)

    0_1512021512908_130506a8-b38a-4227-9bec-4e199e7d1e00-image.png


  • Notification Spam Recipient

    @tsaukpaetra cross-posted from WTF Bites:

    Status: Made a loop to move to the next delectable button in an array:

    int LastSelectedIndex = SelectedIndex;
    int RotateDirection = Direction == EDirection::Left ? -1 : 1;
    
    for (int newSelectedIndex = SelectedIndex, loops = 0;
    	!SelectButton(newSelectedIndex) || (newSelectedIndex == LastSelectedIndex && loops == 0);
    	newSelectedIndex = newSelectedIndex + RotateDirection + ButtonArray.Num() % ButtonArray.Num())
    {
    	if (newSelectedIndex == LastSelectedIndex)
    		loops++;
    }
    

    I'm not entirely sure I need the LastSelectedIndex variable...

    Edit: And that ButtonArray.Num() (which returns the number of elements, natch) is incorrect here...

    Turns out, taking the full Num and not Num-1 was indeed correct.
    But that exposed a nice bug: In SelectButton(), it tries to de-select the currently selected button. Guess what happens when that's set to -1 (either due to prior de-selection or first-spawn)?



  • @tsaukpaetra what's ButtonArray.Num(), and why were you adding it? Or is that the "incorrect here" one? (edit: nevermind, I figured that out. It's to prevent it going negative.)

    What are you trying to do? Why's it looping more than once?

    It looks like you're trying to find a button where SelectButton returns True, but if there isn't one then it's never going to stop because you have an || in the condition.

    I think you're trying to do this:

    int d = Direction == EDirection::Left ? -1 : 1;
    int newSelectedIndex = SelectedIndex, found = 0;
    do {
        newSelectedIndex = (newSelectedIndex + d + ButtonArray.Num()) % ButtonArray.Num();
        if (SelectButton(newSelectedIndex)) found = 1;
    } while (!found && newSelectedIndex != SelectedIndex);
    

  • Notification Spam Recipient

    @anotherusername said in Programming Confessions Thread:

    @tsaukpaetra what's ButtonArray.Num(), and why were you adding it? Or is that the "incorrect here" one?

    What are you trying to do? Why's it looping more than once?

    It looks like you're trying to find a button where SelectButton returns True, but if there isn't one then it's never going to stop because you have an || in the condition.

    That's what the loop++ is for. It tries to select the next button (in an arbitrary direction) until it succeeds, but stops if it looped all the way around.

    The Num() function is basically the same as Count or Length in higher languages.

    Really, the only real inefficiency is that it first selects the (apparently) already selected button first.


  • Notification Spam Recipient

    This post is deleted!


  • @tsaukpaetra so yeah, you don't need LastSelectedIndex (it stayed exactly the same thing as SelectedIndex -- you never changed either of them).

    As I wrote it, once the loop terminates you can use the value of found to determine whether the button it stopped at was selectable or not.


  • Notification Spam Recipient

    @anotherusername said in Programming Confessions Thread:

    @tsaukpaetra so yeah, you don't need LastSelectedIndex (it stayed exactly the same thing as SelectedIndex -- you never changed either of them).

    As I wrote it, once the loop terminates you can use the value of found to determine whether the button it stopped at was selectable or not.

    It probably got optimized out anyways, and the snippet is basically the entirety of the selectNext(Direction) function.

    This code replaced something that effectively was a recursive call to itself, which caused problems if there were no valid buttons to select.



  • @tsaukpaetra you could easily write it as a recursive function just by passing in ButtonArray.Num() as an extra counter argument that gets decremented each time you recurse. Once that hits 0, you know you've wrapped around and you stop.


  • Notification Spam Recipient

    @anotherusername said in Programming Confessions Thread:

    @tsaukpaetra you could easily write it as a recursive function just by passing in ButtonArray.Num() as an extra counter argument that gets decremented each time you recurse. Once that hits 0, you know you've wrapped around and you stop.

    It was recursive (and a bit heavier than that), I intended to get away from that.

    In the prior version, the direction was always an increment as well.

    Just lemme have my confessional and feel bad about it, yeah? :P



  • @onyx said in Programming Confessions Thread:

    $dateTimeformatter = new \IntlDateFormatter($_SESSION['locale'],
    	\IntlDateFormatter::SHORT, \IntlDateFormatter::MEDIUM);
    $dateTimeFormat = $formatter->getPattern();
    // I'm so, so sorry...
    $dateTimeFormat = preg_replace('/([^y])y([^y])/', '$1yyyy$2', $dateTimeFormat);
    
    /* snip */
    
    $sheet->setCellValue($cellName, \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($time));
    $sheet->getStyle($cellName)
    	->getNumberFormat()
    	->setFormatCode(strtolower($dateTimeFormat));
    

    You're forcing the 'year' part of the format to 4-digits representation?
    Seems okay to me, but I'm not a PHP dev, so what do I know? :thonking:

    One thing I do notice, though, is that preg_replace() only checks for lowercase Y's. What happens if the original format uses uppercase Y's?



  • @djls45 said in Programming Confessions Thread:

    @onyx said in Programming Confessions Thread:

    $dateTimeformatter = new \IntlDateFormatter($_SESSION['locale'],
    	\IntlDateFormatter::SHORT, \IntlDateFormatter::MEDIUM);
    $dateTimeFormat = $formatter->getPattern();
    // I'm so, so sorry...
    $dateTimeFormat = preg_replace('/([^y])y([^y])/', '$1yyyy$2', $dateTimeFormat);
    
    /* snip */
    
    $sheet->setCellValue($cellName, \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($time));
    $sheet->getStyle($cellName)
    	->getNumberFormat()
    	->setFormatCode(strtolower($dateTimeFormat));
    

    You're forcing the 'year' part of the format to 4-digits representation?
    Seems okay to me, but I'm not a PHP dev, so what do I know? :thonking:

    One thing I do notice, though, is that preg_replace() only checks for lowercase Y's. What happens if the original format uses uppercase Y's?

    in PHP, y means 2-digit year and Y means 4-digit year, so it looks like that code "fixes" 18 to 18181818, but only if it's not the first or last thing in the string.



  • @ben_lubar You realize that if some other thread calls that DLL while you're monkeypatching you'll end up with split reads and a jump to some black hole somewhere? You're supposed to put the long jump in the bytes just before the function entry point, and atomically put a short jump at the EP.


  • Notification Spam Recipient

    Confession: I have no idea how ODBC works I guess.

    At the beginning of the loop I do SQLAllocHandle to get me a sweet slick of memory to do the query.
    Then, because before I got here nobody knew what parameterized queries were, I do SQLExecDirect with my query text.
    If that failed, I then do SQLGetDiagRec so I can spit out the text of whatever error happened. If specifically an 08S01 error was reported, I disconnect and reconnect (hopefully successfully) and set the loop condition to true, otherwise just report back there was a problem. If it was successful I do the needful and suck out all the data. At the end of the loop, I do SQLFreeHandle to avoid memory leaks.

    Somehow, (very seldom) the call to SQLFreeHandle tries to access 0x000000000010 in not-my-code.

    NFC how to troubleshoot this, since logically everything should be golden...


  • :belt_onion:

    @tsaukpaetra said in Programming Confessions Thread:

    At the beginning of the loop I do SQLAllocHandle to get me a sweet slick of memory to do the query.

    :wtf: Is that what you meant to write or is the NSFW thread leaking again?


  • Notification Spam Recipient

    @heterodox said in Programming Confessions Thread:

    @tsaukpaetra said in Programming Confessions Thread:

    At the beginning of the loop I do SQLAllocHandle to get me a sweet slick of memory to do the query.

    :wtf: Is that what you meant to write or is the NSFW thread leaking again?

    slice. Apparently my keyboard is getting a little sticky? No wait, that doesn't make sense.... I don't know. But I meant "slice".



  • @twelvebaud said in Programming Confessions Thread:

    @ben_lubar You realize that if some other thread calls that DLL while you're monkeypatching you'll end up with split reads and a jump to some black hole somewhere? You're supposed to put the long jump in the bytes just before the function entry point, and atomically put a short jump at the EP.

    I sure hope that Dwarf Fortress isn't running other threads I can't see with my debugger.


  • Notification Spam Recipient

    @tsaukpaetra said in Programming Confessions Thread:

    NFC how to troubleshoot this,

    Probably should start by using SQLFreeStmt instead. We'll see...



  • @ben_lubar Just define a new enemy type based on a Pern crossover.

    This may just be post 500.


Log in to reply