Do your research WTF



  • Continuing the discussion from A Million Lines of Bad Code [article]:

    @dstopia said:

    I'm self taught and I make a bunch of mistakes all the time. One of the first projects I had full control of in Java involved me building JSON by hand because I didn't even know what JSON was. Imagine the embarrassment once I found out what it was -- which was long after I wasn't in control of the project anymore. In my defense, I was given less than two weeks to implement something I had estimated in six. Hey, at least it worked!

    It is something you get better at the more you do. One thing I'm quite proud to be good at is that I pick up stuff fairly fast, which helps a lot now that I'm maintaining an application practically by myself.

    This reminds me of a WTF from my early programming days.

    Back in the early 2000s, I was, among other things, into Delphi 7 and music. So, as a mostly self-taught and pretty isolated programmer "computer guy", I decided to make a Windows app to organize my huge collection of MP3-s. Multi-rename files, set ID3-s from filenames, filenames from ID3, etc. The kind of stuff you'd nowdays do with mp3tag or just let iTunes mangle for you.

    Either way, I soon had the basics working. In an early version, you could do something like: "rename all files to {Id3Num} - {Id3Title}.mp3".

    But I wanted more. I thought, wouldn't it be cool if users could capture arbitrary parts of the input string and use them in the output? And maybe even combine them with the arbitrary variables from the file metadata? And.. and, perhaps you could tell it to capture just the digits... and and specify the wanted length!?

    It wasn't easy. But I persevered, hacked at this huge nested loop algorithm, and finally got it working. So in version 2, you could do something like this:

    Search : *{artist} - *{song}.mp3
    Replace: {artist} - ~num - {song}.mp3

    I was so proud of myself. I thought I was the biggest genius to have invented something so useful.

    And then, after I got steady internet and started getting into the wider programming world, I stumbled upon something called regex...

    ... yeah.

    Let's look at a few pages from my user manual and imagine what could have been if my genius had blossomed 15 years earlier... or if I did my fucking research.



  • @cartman82 said:

    Delphi 7

    Ain't that a WTF in and of itself.

    In terms of music, I've written (luckily, only for myself) an app to assign covers to my music collection - it basically took the directory tree of my music collection, made a list of album names, made a list of image files in another directory and tried to assign one to the other based on Levehnstein distance between file/directory names.

    A few months later, I had my girlfriend around, and since she was interested in picking up programming, I wanted to show her one of my projects and explain what the code does, for her to get a general grip on what it's about. I picked this one.

    *opens code*

    *stares*

    *a lump of horrible parsing, directory traversal and ID3 tagging mess stares back*

    "...well, shit, let's try a different one, since even I can't figure out how this thing even works"



  • Hey, don't diss on Delphi 7! Interface designer was fucking rad (see what I did there?), and the language was certainly better than fucking Basic. I'm riding on a wave of nostalgia right now, reading through my old pas files and playing with my old programs I have long since forgotten. They all work and look good on Windows 8.

    Delphi was great.



  • @cartman82 said:

    They all work and look good on Windows 8.

    Well you must be a wizard. When I had a class which required us to write in Delphi 7 (in 2011. Don't ask...), I had to set up a friggin' XP VM.

    Looking back, the interface designer and all the VCL stuff was actually quite cool (certainly for its time), but Object Pascal... eh, give me C++ Builder anytime.



  • I have some C++ Builder stuff too. Tried to start my old L-system fractals drawing thing and...

    All the Delphi stuff worked. Explain that, @Maciejasjmj! WHERE IS YOUR C++ GOD NOW!?



  • Delphi 6 and 7 didn't have an external runtime, they were pure Windows API calls.

    Unfortunately setting up the compilation environment was hideous. I'm currently hoping a Delphi project obsoletes itself before I have to update it, entirely because I don't think I can set up the environment again.



  • @lightsoff said:

    Unfortunately setting up the compilation environment was hideous. I'm currently hoping a Delphi project obsoletes itself before I have to update it, entirely because I don't think I can set up the environment again.

    Really? I remember it being just install Delphi and run.

    But I guess if you have a bunch of custom components, that's a different story. When I looked it up yesterday, I discovered my wannabe regex implementation was a non-visual component you had to have installed within the IDE in order to build the main program.



  • If I had the first code I wrote I'm sure I would rip my eyes out (Macintosh Pascal or TurboPascal, IDR) but then, I still get to see some of my code in different places and also feel proud and amazed that it still works.

    I can't either find my PalmPilot apps source code and download.com seems to have removed all their PalmPilot categories too.Nope, still there, but I can't find none I made.



  • @Eldelshell said:

    If I had the first code I wrote I'm sure I would rip my eyes out (Macintosh Pascal or TurboPascal, IDR) but then, I still get to see some of my code in different places and also feel proud and amazed that it still works.

    Yeah, that's the thing with this regex wannabe library. It's stupid that I made it, but the code itself... is not that bad, actually. It's sort of like a tokenizer and parser wrapped into one, with final product being a linked list made out of instances like TextPart, JokerPart, NumberPart... For some reason I was using three spaces to indent code (WTF was I thinking!?) and everything is tangled into an ugly twine of functions with too many responsibilities, but otherwise, there are no major WTF-s that I see.

    I was expecting worse, honestly.



  • @cartman82 said:

    For some reason [...] everything is tangled into an ugly twine of functions

    Comments? That's another thing with n00b code. No usable comments :confounded:



  • @Eldelshell said:

    Comments? That's another thing with n00b code. No usable comments

    To my shame, the old code seems to have more comments than my current code...

    Looks like I peaked early :-)



  • @Maciejasjmj said:

    Ain't that a WTF in and of itself.

    When I was learning programming, we used Delphi 6, on windows 2000 machines, without any concept of objects, AND WE LIKED IT!



  • I'm leaving my current company in two weeks and I've been working through my code, adding documentation where it's lacking. I've just reached code from when I first started here and it's making me cringe. Here are examples of some of the horribleness I'm encountering in the User model (PHP code):

    • Instead of making use of the framework's built in active record functionality to fetch data and return it nicely packaged up in User objects, I wrote a bunch of methods that use plain SQL to query the database and return the data as associative arrays.

    • I have a static method that checks the status of a user by accepting a user ID, loading the corresponding User model using active record, then returning the status attribute and discarding the User object.

    • A method that returns an HTML link to the admin edit page for the loaded User record. Yes, the User model which corresponds to a table in the database is generating HTML for a link pointing to a controller action somewhere in the system.

    • Several methods that perform operations and return a string error message on failure, or boolean true on success.

    In my defense, I was new to both MVC and PHP frameworks at the time and user registration and management was the first task for the site. It's still making me squirm though.



  • @Keith said:

    Instead of making use of the framework's built in active record functionality to fetch data and return it nicely packaged up in User objects, I wrote a bunch of methods that use plain SQL to query the database and return the data as associative arrays.

    Ugh

    @Keith said:

    I have a static method that checks the status of a user by accepting a user ID, loading the corresponding User model using active record, then returning the status attribute and discarding the User object

    Just add caching, no problem. You'll probably need user model on every request.

    @Keith said:

    A method that returns an HTML link to the admin edit page for the loaded User record. Yes, the User model which corresponds to a table in the database is generating HTML for a link pointing to a controller action somewhere in the system.

    That's why God gave us ViewModels.

    @Keith said:

    Several methods that perform operations and return a string error message on failure, or boolean true on success.

    Not a big deal. You should probably throw, but in certain conditions, return is ok.



  • @Maciejasjmj said:

    required us to write in Delphi 7 (in 2011. Don't ask...)

    We still do Delphi here, apparently.


Log in to reply
 

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