The Lemming Switch

« Return to Article
  • Hah! 2012-02-16 09:01
    Long time reader, frist time commenter!
  • Nagesh 2012-02-16 09:07
    Can sumone be posting Java version of this code plz?
  • Smug Unix User 2012-02-16 09:18
    Should have just used a cron job.
  • huh 2012-02-16 09:18
    I'm probably being a dumbass but apart from the fact that he made a desktop app instead of a service, where's the wtf? I'd also like to know how the code caused a page fault - I can't see a reason from the code...
  • foo 2012-02-16 09:20
    Kevin continues, "my first reaction to the code was wondering how one might stop this 'service'?
    This was your frist reaction, really? (Doesn't Windows provide some standard ways to terminate programs?) My frist reaction would be the ~1 WTF per line (spread between the "developer" and VB, of course) ... or whether the program does anything at all apart from getting and searching.
  • Daverino 2012-02-16 09:23
    Does this code do anything other than search for files over and over again on an infinite loop? I'm pretty rusty on VB..
  • Knaģis 2012-02-16 09:24
    The code is not something one would be very proud of but where is the WTF?

    Also the author does not seem to know what a page fault is: http://en.wikipedia.org/wiki/Page_fault.
  • Knaģis 2012-02-16 09:25
    Daverino:
    Does this code do anything other than search for files over and over again on an infinite loop? I'm pretty rusty on VB..

    It is not possible to determine that because we are not given the code for "SearchListForFile" method.
  • rohcQaH 2012-02-16 09:26
    strIniFileLoc wasn't initialized, which may or may not cause the custom GetPathFromIni to fail.

    We're also missing the implementation of SearchListForFile, which seems to be responsible for the brunt work.

    Of course TRWTF is that Alex has no clue what a "page fault" is.
  • UrzaMTG 2012-02-16 09:36
    Keep in mind that, from the language used in the article, this wasn't the final code, just a checkpoint along the way. We don't even have the code that does the actual killing of files, just the crazy bad infinite looping structure and half assed (pseudo?)code.
  • Bogolese 2012-02-16 09:36
    Alex or Kevin?
  • Spivonious 2012-02-16 09:36
    Can VB6 even get page faults? It's a managed runtime.

    I don't see anything wrong with this code, assuming the functions we don't see work properly. Is it the best solution? No, but it does the job.
  • PG4 2012-02-16 09:43
    Spivonious:
    Can VB6 even get page faults? It's a managed runtime.



    It's so cute went application devs, and the OP/editor, try to talk about OS basics they nothing about.
  • John 2012-02-16 09:48
    PG4:
    Spivonious:
    Can VB6 even get page faults? It's a managed runtime.



    It's so cute when application devs, and the OP/editor, try to talk about OS basics they nothing about.


    FTFY
  • Gieron 2012-02-16 09:59
    John:
    PG4:
    Spivonious:
    Can VB6 even get page faults? It's a managed runtime.



    It's so cute when application devs, and the OP/editor, try to talk about OS basics they nothing about.


    FTFY

    I don't about that.
  • PedanticCurmudgeon 2012-02-16 10:04
    I think I speak for everyone when I say that anyone who codes like this shouldn't be let anywhere near the Windows API.
  • Andrew 2012-02-16 10:06
    I worked with someone who did something like this. Platform was .NET though, but I think his implementation beats this one:

    His app needed to 'watch' certain things (about 100 in total). He figured the best way to do this was to kick of a thread for each item, and each thread was running a timer.
    Thing was, he used the System.Timers.Timer, executes in a thread-pool. So for all his work to make sure each thread was truly executing 'individually', they ended up just waiting for the worker thread to be free.

    The whole thing was built as a Windows Forms app so it was easier for him to test, then it just landed up on the server like that. You couln't just dump it in the starup items or schedule it either because some buttons/options needed to be selected to get it going.

  • JolleSax 2012-02-16 10:14
    Is that a Goto I see before me?
  • ClaudeSuck.de 2012-02-16 10:18
    huh:
    I'm probably being a dumbass but apart from the fact that he made a desktop app instead of a service, where's the wtf? I'd also like to know how the code caused a page fault - I can't see a reason from the code...


    A page fault happens when Windows cannot find data in memory and has to go to the disk. The choice for this term is a bit unfortunate because there is not really a fault, just no matching piece in RAM and I/O is starting. For a script that takes care of files 50 page faults should happe quite fast.
  • Brødreskift 2012-02-16 10:19
    First, captcha:
    transverbero
    Means transfix.
    I'm wondering what they meant by page fault, lol. Did they have really really slow disks, like page faults were handled by an old librarian finding the right pages in the book on some shelf in the basement?
    (Maybe they meant segfault, lol)
  • ClaudeSuck.de 2012-02-16 10:24
    PedanticCurmudgeon:
    I think I speak for everyone when I say that anyone who codes like this shouldn't be let anywhere near the Windows API.


    Why? It's a script that you write in 15 minutes with no hassle. You would of course go for an XML solution running in Framework 4.1 using more than 20 mandays for something that just has to run in the background.
  • honnza 2012-02-16 10:38
    Killed after 50 page faults? My dwm.exe produces two thousand each second. Killed after 50 segmentation faults? NOW that's patience.

    transverbero:(1p sg. v. latin):
    (transitive) To render motionless, by arousing terror, amazement or awe.
    (transitive) To pierce with a sharp pointed weapon.
    (transitive) To fix or impale.
    [edit]
  • wllmsaccnt 2012-02-16 10:44
    "After failing miserably to reason on other solutions, the code was deployed to production. After about the 50th page fault on the server, the 'service' was 'stopped' and promptly removed from existence."

    I think he means that the service deleted itself. Notice how he put 'stopped' in quotes. The code sample is not good, but I don't see any obvious WTF.
  • geoffrey, MCP, PMP 2012-02-16 10:46
    huh:
    I'm probably being a dumbass but apart from the fact that he made a desktop app instead of a service, where's the wtf? I'd also like to know how the code caused a page fault - I can't see a reason from the code...


    The gut reaction of the arrogant programmer is to blame the nearest VB application for anything that goes wrong on a computer. This is clearly a hardware issue, and Kevin was wasting valuable uptime with his blame-shifting.
  • ekolis 2012-02-16 10:48
    At least he used Option Explicit...
  • onitake 2012-02-16 10:48
    And the real WTF is, of course, the Option Explicit!
    VB6 is such a clean language, why do we need to bother with the pesky details of strong typing all of a sudden?
  • VB6 hater 2012-02-16 10:52
    Wow, so much hate for the author...there must be a lot of VB6 enthusiasts reading today.
  • Ken 2012-02-16 10:58
    A page fault is a fault, generated at the hardware layer, saying the memory page you requested is not available right now. The OS deals with it, not the application. It is one of the few things an OS should be doing, as opposed to integrating with one of your web browsers, for instance.

    Now an Invalid Page Fault, that's an entirely different animal. Back in the days of Windows 3.x you used to get GPFs (General Protection Faults) all the time. This is where Windows got its reputation for crashing 30 seconds after you back it out of the garage. People hated GPFs. So Microsoft came out with Windows 95 and in a big ad campaign (so effective it had people camping out to buy the software when they had no hardware!) they proclaimed they had gotten rid of all the GPFs! Yaaay!

    Except they just renamed them to IPFs. It was still as crashy as ever.
  • opto 2012-02-16 11:02
    Hah!:
    Long time reader, frist time commenter!


    And another great mind.
  • PedanticCurmudgeon 2012-02-16 11:03
    VB6 hater:
    Wow, so much hate for the author...there must be a lot of VB6 enthusiasts reading today.
    OK, TRWTF is VB6! Are you happy now?
  • wonk 2012-02-16 11:16
    What does "WriteError" do? Is it spitting out the error to a file, then looping back to a module named "Main", or is it writing the word "Main" in the errorlog. If it is the first, then "stopping" the script by moving the ini file would be...an undocumented stability feature?
  • Yoh 2012-02-16 11:22
    wllmsaccnt:
    "After failing miserably to reason on other solutions, the code was deployed to production. After about the 50th page fault on the server, the 'service' was 'stopped' and promptly removed from existence."

    I think he means that the service deleted itself. Notice how he put 'stopped' in quotes. The code sample is not good, but I don't see any obvious WTF.


    I have one!

    blnLoopEternal = False
    Do Until blnLoopEternal = True

    Note that it is never once set to true within the loop. By design, the loop is intended to end at some point, but there is never a clean termination of the loop. It relies on the raising of an exception somewhere. Seems very sloppy to me.

    Here's another: Instead of making this script a scheduled task, the programmer opted to build in the timing mechanism. If the team decided that they wanted to run this script at different intervals, they would have to modify the code rather than just modifying the task.

    TRWTF is no better solutions.

  • Tud 2012-02-16 11:26
    Would you mind enlightening us by explaining where the WTF is? No one has done that yet.
  • Steve The Cynic 2012-02-16 11:27
    Brødreskift:
    First, captcha:
    transverbero
    Means transfix.
    I'm wondering what they meant by page fault, lol. Did they have really really slow disks, like page faults were handled by an old librarian finding the right pages in the book on some shelf in the basement?
    (Maybe they meant segfault, lol)

    On Windows, and even on x86 Linux/*BSD, I doubt very much they meant a true segfault. In "flat" mode(*) on x86, you normally have to work quite hard in application code to produce a true segmentation violation, aka General Protection Fault, as nobody messes with the segment registers, and all the segments are a full 4GB (except a few hacks to do W^X without an NX bit).

    No, undoubtedly what was meant was Invalid Page Faults (i.e. page faults where there isn't supposed to be a page, rather than valid page faults, where the relevant page is not mapped into the process's address space *right now*). Unix-like systems match IPFs onto SIGSEGV, but it isn't normally a segmentation violation.

    Funky code that writes using a CS: override will create a proper segmentation fault, of course, but it's hard to write that in VB.

    (*) Strictly speaking, x86 doesn't have a flat mode. Flat mode would indicate that the segment registers aren't used at all, whereas even in what looks a lot like a 32-bit flat mode, the segment registers don't even contain the same value. They *cannot* contain the same value because CS must contain a selector for an executable or execute-read segment, and SS must contain a selector for a writeable segment. (Writeable is mutually exclusive with executable. This conundrum is the basis for the aforementioned NX hack.)

    On Win32, CS = a 4GB read-execute (code) segment, DS=ES=SS = a 4GB read-write (data) segment, FS = a tiny segment containing the current thread's user-mode thread control block. It is normally used only by Structured Exception Handling. GS is not used.

    On Win32s (Win32 on Win3.1), back in the day, the segments weren't even mapped to the beginning of the 32-bit linear address space, but both full-on Win32 in NT and Win32c in 9x mapped offset 0 to linear 0 (except FS:, duh), but linear 0 doesn't necessarily map to physical 0, paging being what it is, and isn't normally marked present either.
  • Tud 2012-02-16 11:30
    VB6 hater:
    Wow, so much hate for the author...there must be a lot of VB6 enthusiasts reading today.


    Would you mind enlightening us by explaining where the WTF is? No one has done that yet.

    There, I can't edit so I'll just double post. Who the hell invented that "Reply to" shit anyway? Either make the "In reply to" more useful(tooltips would be fine) or just remove the "Reply" button and let people use the "quote" (they can always delete the quote anyway).
  • Steve The Cynic 2012-02-16 11:34
    Tud:
    VB6 hater:
    Wow, so much hate for the author...there must be a lot of VB6 enthusiasts reading today.


    Would you mind enlightening us by explaining where the WTF is? No one has done that yet.

    There, I can't edit so I'll just double post. Who the hell invented that "Reply to" shit anyway? Either make the "In reply to" more useful(tooltips would be fine) or just remove the "Reply" button and let people use the "quote" (they can always delete the quote anyway).

    You can't edit because you haven't registered.
  • Oops FTW! 2012-02-16 11:38
    I think the true WTF is using "Oops" as a exception catching label. It's a distant cousin of "UhOh" and "OhShit"
  • Yoh 2012-02-16 11:42
    Tud:
    VB6 hater:
    Wow, so much hate for the author...there must be a lot of VB6 enthusiasts reading today.


    Would you mind enlightening us by explaining where the WTF is? No one has done that yet.


    "After failing miserably to reason on other solutions,"
  • frits 2012-02-16 11:48
    What? No FreeFile()?
  • Weeks before D-Day 2012-02-16 11:57

    On Windows, and even on x86 Linux/*BSD, I doubt very much they meant a true segfault. In "flat" mode(*) on x86, you normally have to work quite hard in application code to produce a true segmentation violation, aka General Protection Fault, as nobody messes with the segment registers, and all the segments are a full 4GB (except a few hacks to do W^X without an NX bit).


    Remember that 'segment fault' is a UNIX term that predates the x86, and the x86 segment registers, by quite a bit. I agree with you that having a 'x86 segment register violation' is nigh impossible, that's not what a SEGV means. The segment in this case is the processes' legally addressable memory. You could get a SEGV on a 680x0 which never had segment registers.

    captcha: the three ABIGOs.
  • Underrock Bin Livin 2012-02-16 12:02
    The Lemming Switch

    is a great title for a book
    or song or movie
    or something


    Why can't I just copy and paste the captcha? transcribing it is so tedious.
  • Steve The Cynic 2012-02-16 12:07
    Weeks before D-Day:
    Remember that 'segment fault' is a UNIX term that predates the x86, and the x86 segment registers, by quite a bit. I agree with you that having a 'x86 segment register violation' is nigh impossible, that's not what a SEGV means. The segment in this case is the processes' legally addressable memory. You could get a SEGV on a 680x0 which never had segment registers.

    Correct, of course. But the other poster didn't say a SEGV. He said a segfault, perhaps not knowing that a segfault and a SIGSEGV aren't necessarily directly equivalent, but also when talking about a Win32 WTF.

    And I, too, have worked on Unixalikes that didn't have segments as such, notably Ultrasparc III+s on Solaris, and IBM AIX machines. Those were weird, because either by hardware feature, OS design or local config, reading via NULL didn't SEGV your program. (It was a large vendor of financial information services, and had systems so large that IBM had to patch the OS to allow single executables to have more than 256MB in their .text segment.)
  • oldami 2012-02-16 12:09
    The page faults are caused by the OS processing of the ini file. Windows has APIs for dealing with ini files that produce locks (somewhere) that prevent another process from accessing an ini file while it is already being accessed. If you run a program like this and the look at it in detail in task manager you will see the page faults. These faults don't really cause a problem except for a very high OS overhead cost. If you do it often enough it will bring even a powerful server to it's knees. (Don't you just love windoze?)

    I know this, unfortunately, because I made the same mistake when I was younger and even stupider than I am now. Fortunately, it was easy to find and fix. Used the database instead of an ini file.
  • Heywood J 2012-02-16 12:12
    WTF is the WTF?
  • geoffrey 2012-02-16 12:29
    Heywood J:
    WTF is the WTF?


    TRWTF is that programming snobs look down upon VB.
  • T. Roll 2012-02-16 12:46
    oldami:
    ...
    Nice try.
  • Robert B. 2012-02-16 12:53
    [quote user=oldami]The page faults are caused by the OS processing of the ini file. Windows has APIs for dealing with ini files that produce locks (somewhere) that prevent another process from accessing an ini file while it is already being accessed.[/quote]

    That's not a page fault, that's a file access violation. And as along as the other process wasn't writing to the .ini file, it's fine. And since this is a custom ini file and the application is single-threaded, the possibility of some other process having that init file open for writing at the same time is probably nil.

    Perhaps there was another application whose job it was to delete the ini file (you know, like an admin app to stop this app), and instead of deleting upon command by an end-user, did it constantly in a loop.

    (what was probably really happening was the files the app were attempting to delete were open by another application resulting in a file access violation)
  • Really? 2012-02-16 12:54
    oldami:
    The page faults are caused by the OS processing of the ini file. Windows has APIs for dealing with ini files that produce locks (somewhere) that prevent another process from accessing an ini file while it is already being accessed. If you run a program like this and the look at it in detail in task manager you will see the page faults. These faults don't really cause a problem except for a very high OS overhead cost. If you do it often enough it will bring even a powerful server to it's knees. (Don't you just love windoze?)


    I'm sorry, but this sounds like the biggest load of b******t I've heard in a long time :-)
    I fail to see a connection between locking a file and causing page faults.
  • Geoff 2012-02-16 12:54
    Fault is a correct term. It just does not deserve the negative connotation when used in this context. Its a fault in that the MMU is basically saying "That is not here", which is not problem, the fault it handled by paging whatever "That" was into memory from disk or other type of secondary storage.

    Think of it the same way you think about raising an exception in your code. Its a "bad" thing that an exception been raised, it only becomes bad if its not caught and handled in some way that prevents causes the application/process to fail; otherwise its just a fancy kind of branching.
  • The Bytemaster 2012-02-16 13:15
    For those not getting what is wrong with the code:

    First, the loop is crazy. Get a list of files in a folder and then for every file in the folder, check to see if it is on the list. Especially since file system object has a way to check if a file exists, it is a whole lot of extra work as opposed to looping through the contents of the .ini file iteslf and just checking the folder to see if it exists -- much more effecient.

    Of course that is minor. The major problem is that it does not clean up any resources. It keeps grabbing a file and folder handle each loop. It never sets the variable to "nothing", never giving it a chance to clean up before the next loop. Not that VB6 had any great garbage collection in the first place, but still not a good idea to keep grabbing handles to everything in the loop.

    And finally -- it is a VB6 app that does this! Seriously, why would anyone think this is a good idea.
  • Gurth 2012-02-16 13:28
    Yoh:
    By design, the loop is intended to end at some point, but there is never a clean termination of the loop.

    Looking at the code, I get the impression the idea is that the loop doesn't terminate. I can't think of any other ways to set up an endless loop in VB6, but then, it's been quite a while since I last used it.
  • Rick 2012-02-16 13:45
    Do Until False = True?
  • Heywood J 2012-02-16 13:54
    The Bytemaster:

    First, the loop is crazy. Get a list of files in a folder and then for every file in the folder, check to see if it is on the list. Especially since file system object has a way to check if a file exists, it is a whole lot of extra work as opposed to looping through the contents of the .ini file iteslf and just checking the folder to see if it exists -- much more effecient.


    Ok - depending on what portion of the files are to be deleted, and how many are in the directory, this might or might not be stupid.


    Of course that is minor. The major problem is that it does not clean up any resources. It keeps grabbing a file and folder handle each loop. It never sets the variable to "nothing", never giving it a chance to clean up before the next loop. Not that VB6 had any great garbage collection in the first place, but still not a good idea to keep grabbing handles to everything in the loop.


    Why is this a problem? When a variable gets set to a new object, shouldn't the old one be garbage collected?

    As far as being inside the loop or not, if the idea is that the .ini file can be changed without restarting the "service", it looks like all the code belongs in there.


    And finally -- it is a VB6 app that does this! Seriously, why would anyone think this is a good idea.


    Why, specifically, is it a bad idea? Leaving aside the issue of actually making it a proper service (which could have been done in VB), is there any reason not to use the most familiar and convenient tool at hand to implement this small program?
  • Heywood J 2012-02-16 14:02
    It seems that the whole "page fault" thing is really trying to imply that this was a major resource (CPU? Mem? Disk?) hog. (This might be TRWFT.)

    This story is missing quite a bit of context about the size of the directory and file list, and "pseudo codes" away a lot of what's going on.

    If the goal is to remove a handful of files from a directory with thousands, maybe there is a WTF here. But assuming a smallish directory to scan through, it wouldn't seem to be a problem.

    Although "do while true" would be a major style improvement, it wouldn't have any bearing on performance.
  • Anon 2012-02-16 14:09
    Oh I get it, TRWTF is that the loop runs eternally until the flag blnLoopEternal is set to true.

    Should be the other way around. Run until blnLoopEternal is false, obviously.
  • Rfoxmich 2012-02-16 14:10
    Ok..seems like we have Page Faults, SEGFAULTS, General Protection Faults but what we really need are My Faults and Your Faults...This one is clearly Your Fault ;-)
  • Kyros 2012-02-16 14:17
    I hope you aren't actually any sort of programmer. Let's do a quick run through:

    1. There's a GoTo in there.
    2. The entire thing is an infinite repeating loop.
    3. VB6.

    1. GoTos are bad. Yes, even for error handling. Bad. Stop it.
    2. This has got to be the worst possible way in terms of efficiency to code this, and it definitely has a very real negative performance impact. You could of *actually* made a service, or even just set it up as a windows scheduled task, but an infinite repeating loop? This isn't a PIC.
    3. VB6 is slow, messy, and has terrible style. A batch script would of actually been better. Ideally a quick C or C++ program. Java at least would of been neater, even if no faster.

    It takes maybe 20 minutes to write a flexible service to do something about this complex. The article notes it took the developer in question "several days".
  • Jay 2012-02-16 14:27
    It seems to me that the real WTF here is Windows Services.

    Not to sound like a Linux bigot, but in Linux, to make a service you write a program just like any command line program, then run it just like you would run any command line program, except you add an ampersand to the end of the command line. That is, the "Linux Service API" is "type an ampersand after the program name". If you like you can create shell programs to start, stop, and restart the app. But that's purely optional.

    In Windows, to create a service you have to implement an API entirely separate from what you would write for any other program. Why? It's just a ton of junk dumped on top of the Windows developer.
  • Jay 2012-02-16 14:28
    Rick:
    Do Until False = True?


    I think you mean, Do Until False = FileNotFound
  • Jay 2012-02-16 14:33
    Heywood J:
    It seems that the whole "page fault" thing is really trying to imply that this was a major resource (CPU? Mem? Disk?) hog. (This might be TRWFT.)

    This story is missing quite a bit of context about the size of the directory and file list, and "pseudo codes" away a lot of what's going on.

    If the goal is to remove a handful of files from a directory with thousands, maybe there is a WTF here. But assuming a smallish directory to scan through, it wouldn't seem to be a problem.

    Although "do while true" would be a major style improvement, it wouldn't have any bearing on performance.


    Even at that. Say the directory has 20 files that should be kept and a 1000 that should be deleted. Assuming that there is no pattern to the file names, i.e. you can't say "delete tmp*.txt" or something like that, than the only way to delete them is to identify them one by one and delete each in turn. So it's difficult to see how the program could really be made more efficient.
  • Robert B. 2012-02-16 14:41
    1. GoTo's are not inherently bad on their own. Modern constructs merely mask the use of them a lot of the time. Furthermore, in VB1-6, that was the standard way of performing error handling as VB6 did not have try/catch/finally. You either do On Error GoTo (|GoSub) or there was no error handler in that function.

    2. Making it a service or scheduled task doesn't fix the loop, which sleeps for a minute anyhow, releasing resources and letting other things do their thing. A basically infinite repeating loop is how the Windows message pump works in any Windows application with a UI. I suppose that's stupid, too.

    3. VB6 was not slow, didn't have to be messy (this code is far from it), and style is subjective. I don't care for the overly verbose style of BASIC myself, either. If the thing were written in Java, it would probably be as fast or faster than the similar C program but wouldn't be able to (easily) run as a service. Another choice would be .net, where it would be trivial to write a service and be as fast or faster than the equivalent C program (we're talking about blocking I/O here - the speed of the actual compiled code is a barely a measurable percent of the overall speed).

    The thing to do would probably have been to set up a watcher for the directory (ReadDirectoryChangesW or FileSystemWatcher in .net), see if the file (or files) matches the list that was just written, and delete it if so, otherwise do nothing.
  • Not a windows fan 2012-02-16 14:44
    Jay:
    It seems to me that the real WTF here is Windows Services.

    Not to sound like a Linux bigot, but in Linux, to make a service you write a program just like any command line program, then run it just like you would run any command line program, except you add an ampersand to the end of the command line. That is, the "Linux Service API" is "type an ampersand after the program name". If you like you can create shell programs to start, stop, and restart the app. But that's purely optional.

    In Windows, to create a service you have to implement an API entirely separate from what you would write for any other program. Why? It's just a ton of junk dumped on top of the Windows developer.


    The default Windows app is a desktop GUI app. And while X is a joke, Windows can at least have pretty GUIs because of Microsoft's API choices and the hoops they make developers jump through.
  • Jay 2012-02-16 14:46
    I'll join the chorus of "what's the problem" here.

    To summarize the objections raised to this program so far:

    1. It uses VB6, and VB6 is an old language. Okay, so what? Is it adequate to handle the job? Yes. So if the programmer is comfortable with it, why not use it? It wouldn't be my choice, but if it does the job, who cares?

    2. It has an infinite loop so there's no way to terminate the program. The article quotes the programmer as saying you could kill it by moving the ini file. I'd think a more direct way to kill it would be to use TaskManager. Clumsy and messy, but ... exactly how is it better to access Windows Services and click "stop" than to access Task Manager and click "terminate"?

    3. It never frees the directory object for garbage collection. Yes it does: the next time through the loop when it reassigns the variable to a new directory object. Okay, there's the minor issue that it holds that directory object through the sleep, so it is probably using it for a couple of milliseconds, then it sits there wasting space for 60 seconds, then it destroys it and creates a new one that it used for a few milliseconds, etc. You could free up some system resources by fixing that.

    4. It causes page faults. If you are using the correct terminology, then okay, that may be true: every time the sleep expires, it fires up again, and if it got swapped out of RAM, that would cause a page fault and a refresh from virtual memory. So what? That's what virtual memory is for. That's like saying that a progam is flawed because it periodically quits running for no good reason ... except that it's waiting for input from the user. If instead you made it a service or a cron job that ran every sixty seconds, then each time the timer clicked it would reload the program from disk. This way, each time the timer clicks it ... reloads the program from disk. I suspect that reloading a page from virtual memory takes less time than firing up a new process and loading an exe file, so this method is probably more time efficient. If you're constrained on virtual memory, maybe that's a problem.

    So what's wrong with this program again? I don't know that I'd hold it up as a model that should be given an award, but it seems an adequate solution to the problem.
  • Robert B. 2012-02-16 14:48
    Jay:
    It seems to me that the real WTF here is Windows Services.

    Not to sound like a Linux bigot, but in Linux, to make a service you write a program just like any command line program, then run it just like you would run any command line program, except you add an ampersand to the end of the command line. That is, the "Linux Service API" is "type an ampersand after the program name".


    Running a process in the background (which is what the ampersand does) doesn't turn a process into a daemon, which is what would be the equivalent construct in Linux.

    In Windows, the program just has to respond to a few API calls so that the service control manager can interact with it (e.g. to start up, shut down, etc.), similar to the way a proper daemon has a few set things to do (fork a child process, etc.). It's really not complicated.
  • Matt Westwood 2012-02-16 14:59
    Oops FTW!:
    I think the true WTF is using "Oops" as a exception catching label. It's a distant cousin of "UhOh" and "OhShit"


    I had to maintain a FORTRAN program once (it was a long time ago in a time where such languages were commonplace) such that every error condition whose cause originated with invalid data entered by the user was directed to one single location in the code. At that location was the line:


    PRINT 'Oh bugger'


    Addendum (2012-02-16 15:11):
    Sorry, should have been


    PRINT *, 'Oh bugger'

  • Clark 2012-02-16 15:01
    The Bytemaster:

    And finally -- it is a VB6 app that does this! Seriously, why would anyone think this is a good idea.


    Yeah! I would've used JScript.
  • Ludus 2012-02-16 15:09
    1) I don't think VB6 was the WTF; just the poor use of its looping constructs and termination logic.
    2) It "technically" is not an infinite loop, since it is designed to exit based on removing an expected file in order to terminate its process. Killing the process from the task manager is not how this was designed, yet is as effective and probably safer than using the storage media to kill the process.
    3) I don't understand your point...you seem to argue with yourself...probably a "minor issue". :P
    4) Call me a stickler for details, but why would I want to design an application with a known ability to cause any sort of issues with memory? I'm sure the OS can handle it, yet is that an excuse for poor programming practice?
  • Matt Westwood 2012-02-16 15:10
    Aha - I know what the problem is! There's no copyright header or amendment list.

    And another one: the indenting is 3 spaces, when standard programming style is 4 as everybody knows.

    Both issues are outrageous and require the programmer to be disciplined. Edna Krabappel in fishnets and leather basque with a whip, methinks ...
  • Yoh 2012-02-16 15:11
    I said it in an earlier post, but I think I'll word it more directly this time.

    I think that this program should have been implemented as a scheduled task instead of an infinite loop. I do not think using an infinite loop that can only be terminated by moving a file is an elegant, efficient, or intelligent solution.

    If you think about the 1 minute sleep call, clearly the developer was attempting to force it to run at specified intervals; that is, he was trying to schedule it. Wouldn't it make more sense then to manage it as a scheduled task instead of having to go into the program itself, change the sleep call, and then recompile when the intervals need to be increased or decreased? Not only would that make the program easier to manage, but it would also remove the infinite loop. Moreover, you wouldn't have to browse your way into some random directory, and then delete a file just in case you need to terminate it (or end the task for that matter). That seems like a pain in the ass to me, and avoids a much better way to handle the process.

    But that's just me, I guess. Maybe there isn't really a problem with it, but it seems very sloppy to me.
  • facilisis 2012-02-16 15:13
    Matt Westwood:
    Aha - I know what the problem is! There's no copyright header or amendment list.

    And another one: the indenting is 3 spaces, when standard programming style is 4 as everybody knows.

    Both issues are outrageous and require the programmer to be disciplined. Edna Krabappel in fishnets and leather basque with a whip, methinks ...


    I'm not sure what is more disturbing...the leather basque or that you know how to spell "Krabappel".
  • Heywood J 2012-02-16 15:13
    Kyros:

    1. There's a GoTo in there.
    2. The entire thing is an infinite repeating loop.
    3. VB6.

    1. GoTos are bad. Yes, even for error handling. Bad. Stop it.


    That's the way you do generic error handling in VB6. It's hardly different conceptually than wrapping the whole loop in a "try/catch". If the thing blows up, drop to the cleanup code at the bottom. Granted it gets messy when you're only trapping errors over a few lines. VB's shortcoming, not the programmer's.


    2. This has got to be the worst possible way in terms of efficiency to code this, and it definitely has a very real negative performance impact. You could of *actually* made a service, or even just set it up as a windows scheduled task, but an infinite repeating loop? This isn't a PIC.

    How is this inefficient? How would a service be any different? They both do something, wait, and do it again. If you made it a task, what do you think happens inside the scheduler? And, AFAIK, the scheduler would have the overhead of starting a new process evey pass through.

    Definitely lazy to not have a proper exit to the loop. But I wouldn't call it a WTF - the thing really isn't intended to ever stop.


    3. VB6 is slow, messy, and has terrible style. A batch
    script would of actually been better. Ideally a quick C or C++ program. Java at least would of been neater, even if no faster.


    VB6 was slow when there are controls being used. Sometimes painfully slow. When it is just straight code doing some processing, it is as fast as anything else that's compiled. Definitely faster than anything interpreted, provided the program isn't constantly being restarted, and maybe even then.

    As far as messy and terrible style, that's in the eye of the beholder. I would argue that all the memory managment, pointers for a "byref" call, and hoop-jumping to deal with strings in C is much more messy, but C would be acceptable to programming snobs. The use of C and C++ for general application programming instead of something much more sane caused a decade of shitty software quality.


    It takes maybe 20 minutes to write a flexible service to do something about this complex. The article notes it took the developer in question "several days".

    Granted, he's as slow as molasses going uphill in January, but I'm looking at the end result.
  • mh 2012-02-16 15:17
    VB6 is 14 years old, no longer supported, gets no security updates, and VB6 applications will not work on Windows 8. That, in addition to VB6 being a crappy language that encourages programmers to write dangerous and/or unmaintainable code. Like "on error resume next".
  • SJFriedl 2012-02-16 15:24
    Jay:
    Not to sound like a Linux bigot, but in Linux, to make a service you write a program just like any command line program, then run it just like you would run any command line program, except you add an ampersand to the end of the command line.
    Properly writing a Linux daemon is far more complicated than just running something in the background. For one thing, how does the ampersand solution cause the service to be run automatically at boot time? Requiring somebody to do a bunch of things every time they reboot (rather than have them be handled automatically) is definitely a WTF.

    Linux is somewhat scattered on services, there being several mechanisms for running and controlling them (the rc scripts, /etc/inittab, or /etc/xinetd come to mind), plus you can roll your own like DJB has done.

    Even writing the daemon itself requires nontrivial subtleties such as process group leaders and control terminals that you won't ever get right if you think that ampersand is all that's required to start a service.


    I don't care for the Win32 services API much, but it's consistent, robust, and secure, and it's even remotable; assuming I have proper permissions, I can control services on remote systems. Linux pretty much requires that you grant shell access to do this remotely unless you want to roll your own service control mechanism.

    Bashing Win32 for this is a WTF.

    ~~~ Steve (who's written many services and daemons)
  • PedanticCurmudgeon 2012-02-16 15:26
    Matt Westwood:
    Aha - I know what the problem is! There's no copyright header or amendment list.

    And another one: the indenting is 3 spaces, when standard programming style is 4 as everybody knows.

    Both issues are outrageous and require the programmer to be disciplined. Edna Krabappel in fishnets and leather basque with a whip, methinks ...
    Two problems with that: 1) he might like it; 2) we want something of a longer duration - as I mentioned earlier, he knows how to get to the Windows API and therefore could be dangerous if not stopped.
  • aptent 2012-02-16 15:33
    Heywood J:
    Kyros:

    1. There's a GoTo in there.
    2. The entire thing is an infinite repeating loop.
    3. VB6.

    1. GoTos are bad. Yes, even for error handling. Bad. Stop it.


    That's the way you do generic error handling in VB6. It's hardly different conceptually than wrapping the whole loop in a "try/catch". If the thing blows up, drop to the cleanup code at the bottom. Granted it gets messy when you're only trapping errors over a few lines. VB's shortcoming, not the programmer's.



    How do you figure it is conceptually the same? With a try/catch block you can determine scope and logically capture any possible errors within that section of code. Granted VB6 is old, yet I would not conceptually compare it with anything, except an old language that needs to be replaced.

    Besides, you have On Error Resume Next which solves all pesky VB6 errors!
  • Is that a suppository up my ass or are you just happy to see me? 2012-02-16 15:39
    facilisis:
    Matt Westwood:
    Edna Krabappel in fishnets and crotchless panties with a cock, methinks ...
    I'm not sure what is more disturbing...the cock or that you have access to Google.
    Indeed, no one should have access to Google. It will dutifully retrieve some things you just won't believe.

    Like "nailing tits to wooden board". Apparently a German thing. I didn't care for it. Mine started leaking. I was born the wrong sex, you see...
  • venio 2012-02-16 15:40
    SJFriedl:


    Bashing Win32 for this is a WTF.

    ~~~ Steve (who's written many services and daemons)


    So is this code one of your many services? :P
  • LANMind 2012-02-16 15:45
    geoffrey:
    Heywood J:
    WTF is the WTF?


    TRWTF is that programming snobs look down upon VB.


    +1

    Still, it's entertaining to watch people blame a trainwreck on <insert lang here>, when trwtf is the retard behind the code.
  • Bob 2012-02-16 16:00
    LANMind:
    geoffrey:
    Heywood J:
    WTF is the WTF?


    TRWTF is that programming snobs look down upon VB.


    +1

    Still, it's entertaining to watch people blame a trainwreck on <insert lang here>, when trwtf is the retard behind the code.

    Please attempt some sensitivity. I had a son who was retarded, and let me assure you: it is no laughing matter.
  • Heywood J 2012-02-16 16:02
    aptent:

    How do you figure it is conceptually the same? With a try/catch block you can determine scope and logically capture any possible errors within that section of code. Granted VB6 is old, yet I would not conceptually compare it with anything, except an old language that needs to be replaced.

    Besides, you have On Error Resume Next which solves all pesky VB6 errors!


    It's the exactly same in the sense that a for loop is an assignment, a test, an increment, and a goto.

    But I was more thinking in an appearance sort of way. You have a block of code that starts with {on error goto/try}, does it's normal stuff, then has {exit & label/catch}, and then some error handling. When you use try/catch, or on error goto around and entire procedure, I don't think there is a lot of difference in readabily. And you do have access to the error code and can "re-raise" it in the error handler in VB6.

    I know VB6 has it's shortcomings, but it has an undeserved bad reputation that I think is 90% based on the fact that it superficially resembles something from the Commodore-64 (never mind that structually it's more like Pascal) rather than having curly-braces like the cool kids were using on their UNIX boxes.

    The desire to be hip and use something based on C was a tremendous waste of time/source of errors for many, many applications written when VB6 was a current product. I think the switch to Java and C# bears this out.

    There are a lot of things they have that VB6 didn't, but I maintain that the major improvement is not having to incessantly deal with memory and pointers - which is a feature that VB, and a lot of other languages, had for a long time.

    I just like to call people on "VB6 is teh sux0r" and make them defend it.
  • hewioe 2012-02-16 16:12
    Geoff:
    Fault is a correct term. It just does not deserve the negative connotation when used in this context. Its a fault in that the MMU is basically saying "That is not here", which is not problem, the fault it handled by paging whatever "That" was into memory from disk or other type of secondary storage.

    Think of it the same way you think about raising an exception in your code. Its a "bad" thing that an exception been raised, it only becomes bad if its not caught and handled in some way that prevents causes the application/process to fail; otherwise its just a fancy kind of branching.
    Ohhhhhhhhhhhhhhhh, like a file_not_found?
  • johnckirk 2012-02-16 16:23
    mh:
    VB6 is 14 years old, no longer supported, gets no security updates, and VB6 applications will not work on Windows 8. That, in addition to VB6 being a crappy language that encourages programmers to write dangerous and/or unmaintainable code. Like "on error resume next".


    Actually, VB6 apps should run on Windows 8:
    Support Statement for Visual Basic 6.0 on Windows Vista, Windows Server 2008, Windows 7, and Windows 8

    That said, I agree that it's a good idea to convert those apps into a newer language.
  • John Doe 2012-02-16 16:33
    The comment about the page faults is retarded. Let other people said a page fault has to do with virtual memory. When a attempt is made to access a virtual memory address and the required data is not loaded in physical memory then a page fault interrupt occurs. There is some "trap" which is an address of some code that gets executed when a page fault occurs.

    It is a normal thing that happens all the time especially if the machine does not have a lot of memory. Despite fault being in the name it is not an error but just how virtual memory works.

    A proper observation would be "this application uses a ton of memory" or something like that. Looking at the code it doesnt really appear to be the case.

    The true WTF in this article is this comment.
  • MarkJ 2012-02-16 16:38
    Nagesh:
    Can sumone be posting Java version of this code plz?
    No. Please return to your bridge.
  • John Doe 2012-02-16 16:44
    Also I missed the number "50". Got to understand there are hundreds of page faults occuring every second. This number 50

    On the machine I am using right now I launched firefox a few hours ago and it has had over 1.3 million page faults. Time to switch browsers I guess....

    Also memory manager in windows is lazy so first time many things are access a page fault occurs. Things like memory mapped files (loading of any dll or exe into memory) will page fault like crazy until they are loaded.
  • Fedaykin 2012-02-16 18:59
    This post is the WTF.

    A script that does a lot of I/O was "pulled" for generating page faults?

    Really? Is it the poster or the editor that apparently has no idea what a page fault is?
  • bridget99 2012-02-16 19:41
    The real and only WTF here is the fact that this thing does not work. The fact that it's written in VB6, or isn't a true "service", or doesn't use System.Noob.MyFavoriteTimer (or whatever) as its scheduling mechanism, does not matter. If this thing would collect its garbage properly (and do whatever else it needs to do correctly- I don't have the whole code) then it would be OK. People picking out little nits like that are missing the point and, frankly, are calling their own skills (at least, in a real world sense) into question.

    Services are also a WTF in their own right. The debugging experience in Visual Studio is hacked, they have to be specially installed, and so on. I would only develop a service if some kind of heavy-handed IT department requirement made me, and clearly that was not the case in this example.

    Finally, this thread really points out how far this website has fallen. I tried to raise the hurricane warning... this place is turning into a bunch of semiqualified .NET proponents making fun of what amounts to .NET done slightly wrong.
  • Hellbrook 2012-02-16 19:45
    oldami:
    Windows has APIs for dealing with ini files


    So I shouldn't be using the regular windows I/O API when dealing with ini files? Here I am treating them like a regular text file input like a sucker!
  • anon 2012-02-16 20:15
    Still, it's entertaining to watch people blame a trainwreck on <insert lang here>, when trwtf is the retard behind the code.

    Where did this meme come from? I can't find it anywhere else but here.
  • The Real Paula 2012-02-16 21:31
    Know any other way to do an error handler in VB6????
  • enim 2012-02-16 22:29
    The Real Paula:
    Know any other way to do an error handler in VB6????

    On Error Resume Next!
  • J 2012-02-16 23:11
    SJFriedl:
    Jay:
    Not to sound like a Linux bigot, but in Linux, to make a service you write a program just like any command line program, then run it just like you would run any command line program, except you add an ampersand to the end of the command line.
    Properly writing a Linux daemon is far more complicated than just running something in the background. For one thing, how does the ampersand solution cause the service to be run automatically at boot time? Requiring somebody to do a bunch of things every time they reboot (rather than have them be handled automatically) is definitely a WTF.

    Linux is somewhat scattered on services, there being several mechanisms for running and controlling them (the rc scripts, /etc/inittab, or /etc/xinetd come to mind), plus you can roll your own like DJB has done.

    Even writing the daemon itself requires nontrivial subtleties such as process group leaders and control terminals that you won't ever get right if you think that ampersand is all that's required to start a service.


    I don't care for the Win32 services API much, but it's consistent, robust, and secure, and it's even remotable; assuming I have proper permissions, I can control services on remote systems. Linux pretty much requires that you grant shell access to do this remotely unless you want to roll your own service control mechanism.

    Bashing Win32 for this is a WTF.

    ~~~ Steve (who's written many services and daemons)


    Except for something like this, a simple script (without an infinite loop) is enough. Just hand it to cron.
  • Sleep 2012-02-16 23:37
    Yoh:
    I said it in an earlier post, but I think I'll word it more directly this time.

    I think that this program should have been implemented as a scheduled task instead of an infinite loop.

    ...Wouldn't it make more sense then to manage it as a scheduled task instead of having to go into the program itself ... Moreover, you wouldn't have to browse your way into some random directory ...


    Right. Lets split the program logic up into two places, the code and the OS scheduler. That way when you've found the code, you have to searching around for the code that runs the code. Fortunately, you've put script to add the scheduler task into version control, so all you have to do is go searching around your version control database to find...
  • Gibbon1 2012-02-16 23:54
    PG4:
    Spivonious:
    Can VB6 even get page faults? It's a managed runtime.



    It's so cute went application devs, and the OP/editor, try to talk about OS basics they nothing about.


    Page faults happen all the time, code asks for memory that isn't there because it's be swapped out, interrupt occurs, process suspended until the OS gets around to swapping it back in, then the offending instruction is restarted.

    Now a double page fault. But that's not an app developers problem.
  • Matt Westwood 2012-02-17 01:05
    Sleep:
    Yoh:
    I said it in an earlier post, but I think I'll word it more directly this time.

    I think that this program should have been implemented as a scheduled task instead of an infinite loop.

    ...Wouldn't it make more sense then to manage it as a scheduled task instead of having to go into the program itself ... Moreover, you wouldn't have to browse your way into some random directory ...


    Right. Lets split the program logic up into two places, the code and the OS scheduler. That way when you've found the code, you have to searching around for the code that runs the code. Fortunately, you've put script to add the scheduler task into version control, so all you have to do is go searching around your version control database to find...


    You stupid prick. You look it up in the documentation, don't you, pissbrain?
  • Old timer 2012-02-17 01:37
    mh:
    That, in addition to VB6 being a crappy language that encourages programmers to write dangerous and/or unmaintainable code. Like "on error resume next".


    Funny thing: no comments here yet saying "what does that code do?" Must be because VB6 is a crappy language compared to C# or Java. Or some language more than 14 years old like ... C ... or ... Say, how old are you?

    BTW, 'on error resume next' is a neccessary construct for writing scripting languages. It is the reason you can build a scripting language in BASIC, but not in PYTHON. Yes, it is dangerous to write computer programs, but somebody's got to do it.
  • BASIC 2012-02-17 01:45
    Kyros:
    I hope you aren't actually any sort of programmer. Let's do a quick run through:

    1. There's a GoTo in there.

    ...The article notes it took the developer in question "several days".

    Let's do a quick run through:
    1) That is not a GoTo. That is an Exception Handler. The language is different because it a different language.
    ...
    -1) It takes "serveral days" to do the meetings and the documentation. The code only takes minutes. If you think that programming is just coding...I hope you aren't actually any sort of programmer.
  • Severity One 2012-02-17 02:07
    At some point, 'services' at our place were Java programs with a GUI. One of them had a little dog, which ran about when the service was running, and sat down when the service has halted.

    Cute as it was, when I had to upgrade the program, I decided to make it into a headless application.
  • Gurth 2012-02-17 02:33
    Kyros:
    1. There's a GoTo in there.

    Because that's the way VB error handlers work: the GoTo is simply part of the statement. If this is a WTF, it's one with the language instead of by the programmer.
  • Anonymous 2012-02-17 03:41
    Gieron:
    John:
    PG4:

    It's so cute when application devs, and the OP/editor, try to talk about OS basics they nothing about.
    FTFY
    I don't about that.
    You accidentally the whole thread!
  • Omniscient 2012-02-17 04:06
    onitake:
    And the real WTF is, of course, the Option Explicit!
    VB6 is such a clean language, why do we need to bother with the pesky details of strong typing all of a sudden?

    Because otherwise you could get values of 32769, or even beyond, getting into variables that are meant to be Integers!
  • Steve The Cynic 2012-02-17 06:12
    John Doe:
    Also I missed the number "50". Got to understand there are hundreds of page faults occuring every second. This number 50

    On the machine I am using right now I launched firefox a few hours ago and it has had over 1.3 million page faults. Time to switch browsers I guess....

    Also memory manager in windows is lazy so first time many things are access a page fault occurs. Things like memory mapped files (loading of any dll or exe into memory) will page fault like crazy until they are loaded.

    Any sane demand-paging OS does that. There is only one page in an executable module (DLL, EXE, .so, whatever) that is guaranteed to need to be paged in: the page that contains the initial entry point of the module. All other pages might be never referenced, so why waste time explicitly loading something that isn't in the working set, and might never be in the working set? And the *module* is 'loaded' as soon as the mapping of 'this page in the address space corresponds to this page in the executable file' has been established. Even on the sainted Linux, OK?

    Further twiddle on the working set debate: the Windows NT line actually has three kinds of page fault: soft, hard, and invalid. Invalid page faults are easy, you touched a place in your address space where there isn't supposed to be a page, and these are probably what the article was referring to. Hard page faults aren't so difficult to understand - the page is not in physical memory, but is a real page, so the OS goes out to bring it in as soon as you touch it.

    Soft page faults are interesting. The page is in physical memory, but isn't marked as present in your address space. Why might that be? Imagine: another program has caused a page-in event, and to make room, the OS decides to page out one of your writable (and written-to) pages. Because the page is "dirty" (modified since last load) it is queued for writing to disk, while being marked as "out" in your page table. While the page is in the queue (along with dozens of others, presumably), you touch it. A page fault happens, and the OS removes the page from the page-out queue, marks it as being present in your page table, and lets you proceed. Without the page fault, the OS would not be able to remove the page from the page-out queue.

    There are also cases like an executable page in a DLL loaded by another process that you load. Sure, the OS could spend time copying in/out state from the other process to yours, but it could also do lazy loading and allow you to trigger soft faults against the pages that are used in both processes. Also, for various reasons, the DLL might need to be loaded in a different place in your process, and this will cause endless hilarity due to relocations being different in the two processes, but pages affected by that are arguably not soft-faultable. Whatever...
  • Anonanon 2012-02-17 06:44
    Robert B.:

    ...
    If the thing were written in Java, it would probably be as fast or faster than the similar C program
    ...

    I can't believe you said that.
    Go wash your mouth out.
  • retard fixer 2012-02-17 06:52
    Gibbon1:
    PG4:
    Spivonious:
    Can VB6 even get page faults? It's a managed runtime.



    It's so cute went application devs, and the OP/editor, try to talk about OS basics they nothing about.


    Page faults happen all the time, code asks for memory that isn't there because it's be swapped out, interrupt occurs, process suspended until the OS gets around to swapping it back in, then the offending instruction is retarded.

    Now a double page fault. But that's not an app developers problem.


    FTFY
  • Bob 2012-02-17 08:34
    John Doe:
    The comment about the page faults is retarded.

    Are you people so sick that you don't realize that there are people hurting as they deal with this sorrowful condition? Please stop using this hateful, offensive word.

    This is not a joke.
    Askimet, you racist bastard.
  • TheJonB 2012-02-17 08:57
    Matt Westwood:

    And another one: the indenting is 3 spaces, when standard programming style is 4 as everybody knows.


    2 spaces!!!

    Will you people stop pissing horizontal space away!
  • Geoffrey T. Buchanan 2012-02-17 09:20
    Goodness, what the youth of today waste their time on! Inventing problems and over-engineering unnecessary solutions and even wasting time arguing about GOTO statements and page faults! You couldn't make it up.

    Back in the day we would solve this sort of problem in 30 seconds by tasking one of our secretaries to clear out the network drives manually each morning, thus allowing us to continue with our more important COBOL development.

    If you really need to clear the files as frequently as *once every 60 seconds* (!) as the script suggests then I suggest you are doing something wrong. You *shouldn't* be writing the files in the first place if you so urgently need to delete them.
  • Rick 2012-02-17 12:13
    It be interesting to know what happens to objFSO after
    every call to GetFolder() ... Does it allocate more space?
    > Set objKillFolder = objFSO.GetFolder(strKillFileLoc)
  • Math Ninja 2012-02-17 13:42
    Here are some WTFs that haven't been mentioned:

    What happens if I start two instances in different locations with two different Lemming.ini(s)? Shit is gonna get fucked up. Blame the shitty requirement(s?) if you want but first rule of programming, End Users Are Stupid.

    Why isn't there any logging? Even as an internal application, it should at least log starting and terminating.

    Why isn't the sleep duration part of the INI file? That's what they are for, ya know, initialization, configuration, settings. The precursor to XML config files.

  • Henry 2012-02-17 14:24
    > It be interesting to know what happens to objFSO after
    every call to GetFolder()

    VB6 (well, COM in general) is reference-counted. On each call to GetFolder(), the previous folder object is dereferenced and thus deallocated. I'm not sure what you think might happen to objFSO, but there's no obvious memory leak or anything here.
  • mh 2012-02-17 15:59
    I see, thanks for correcting me. Actually, when I checked half a year ago, Microsoft web said it will not work on Windows 8, good to know they changed their mind.
  • Jay 2012-02-18 00:08
    Robert B.:
    1. GoTo's are not inherently bad on their own. Modern constructs merely mask the use of them a lot of the time. Furthermore, in VB1-6, that was the standard way of performing error handling as VB6 did not have try/catch/finally. You either do On Error GoTo (|GoSub) or there was no error handler in that function.


    Not quite. VB has On Error Resume Next, meaning it simply continues onto the next line - which is where you put your error handling. eg:

    On Error Resume Next
    Open "file"......
    If Err Then "MsgBox" FileNotFound
    etc...

    Much neater than the old GoTo handler crap.

    On Error Resume Next is a favourite a poor coders as you can use it to suppress all errors. Awesome, code that never fails!

    As for the WTF, meh. Could have been a VBScript that executed once, kicked off by the scheduler every so often, but yeah, meh.
  • Jay 2012-02-18 00:10
    Bob:
    Please stop using this hateful, offensive word.


    Go to hell. I retarded my carburettor yesterday, and shall continue to do so in the future.
  • Oi de La RocheFoucauld 2012-02-18 01:39
    I'm rusty, but I'm pretty sure that code wasn't written to run as a service. I suspect this is why he put that word in quotes. Proper services shut down in ways prescribed by the service shutdown code - this program has no terminate condition at all.

    It's possible that he confused the term page fault with segmentation fault - someone mentioned earlier that VB is a managed environment and while that's true of later versions, I *think* VB6 was pre dotnet. I don't remember VB being particularly segfault-prone, but then I never used VB very much beyond writing a simple media player in VB4, enthusing at how quickly one could prototype code, and then going back to C++ because I needed the better lower-level access for the kind of code I wrote. I also tended to program defensively - I've always liked code that doesn't fail - so I've typically avoided API Terra Incognito. This code isn't doing that. Terminating it involves removing a file to which it expects access. We're not seeing the whole picture here, but this corner of it isn't very pretty.
  • oheso 2012-02-18 02:30
    Severity One:
    I decided to make it into a headless application.


    That poor puppy ... *shudder*
  • Tud 2012-02-18 11:35
    Steve The Cynic:
    Tud:
    VB6 hater:
    Wow, so much hate for the author...there must be a lot of VB6 enthusiasts reading today.


    Would you mind enlightening us by explaining where the WTF is? No one has done that yet.

    There, I can't edit so I'll just double post. Who the hell invented that "Reply to" shit anyway? Either make the "In reply to" more useful(tooltips would be fine) or just remove the "Reply" button and let people use the "quote" (they can always delete the quote anyway).

    You can't edit because you haven't registered.

    .
    ..
    .
    ..
    .
    Yes.
    I know.
    ...
    .
    ..
    .
    So what?
  • ni 2012-02-18 23:32
    strewth dude ... it's a bit tardy to be saying that in this forum
  • GA2K 2012-02-18 23:40
    Jay:
    Bob:
    Please stop using this hateful, offensive word.


    Go to hell. I retarded my carburettor yesterday, and shall continue to do so in the future.


    I think you meant to say you retarded your ignition timing.
  • Shinobu 2012-02-19 10:04
    Just looked at the Windows services running on my computer. About 10k per process, which is not unexpected given what a page fault is. Something tells me that people were just being judgemental and that someone needed an excuse.
    Instead of doing what they should have been doing (pointing out problems in the code) they probably just wasted his time with pointless nerdy anti-VB rants.
    The thing about programmers that has annoyed me the most is that so many seem to be religious zealots. Some don't want to talk to you for the text editor you use; others fight tooth and nail against the (sorely needed because of type safety issues) introduction of C++ in an existing C code base because they don't want ‘the OOP that will just complicate everything’ and still others rant against VB or Java when they have no experience with those themselves.
  • LOADING 2012-02-19 16:49
    Knaģis:
    The code is not something one would be very proud of but where is the WTF?

    Also the author does not seem to know what a page fault is: http://en.wikipedia.org/wiki/Page_fault.


    It has been many years since I have touched VB6 but page faults sounds familiar. One thing that I am sure about is that I remember VB stability not being the greatest, but nothing was stable on win9x.
  • LOADED 2012-02-19 16:54
    LOADING:
    Knaģis:
    The code is not something one would be very proud of but where is the WTF?

    Also the author does not seem to know what a page fault is: http://en.wikipedia.org/wiki/Page_fault.


    It has been many years since I have touched VB6 but page faults sounds familiar. One thing that I am sure about is that I remember VB stability not being the greatest, but nothing was stable on win9x.


    This is what we're talking about: http://www.fixerror.net/wp-content/uploads/2009/04/kernel32-error2.png
  • LOADED 2012-02-19 17:05
    Brødreskift:
    First, captcha:
    transverbero
    Means transfix.
    I'm wondering what they meant by page fault, lol. Did they have really really slow disks, like page faults were handled by an old librarian finding the right pages in the book on some shelf in the basement?
    (Maybe they meant segfault, lol)


    They meant invalid page fault but as that's usually the only one you care about it gets shortened to page fault.
  • Shinobu 2012-02-19 18:03
    So their server was running 9x huh? And these people were complaining about VB6?
  • Cbuttius 2012-02-21 12:57
    So to stop a loop where blnLoopEternal is False and is tested on being true, you create a state of FileNotFound...

  • Cbuttius 2012-02-21 13:02
    [quote user="Tud"][quote user="Steve The CynicYou can't edit because you haven't registered.[/quote]
    .
    Yes.
    I know.
    .
    So what?[/quote]

    In order to have edit rights they would need to identify you as the original poster. If you post anonymously, you cannot be identified as such.

    By the way I have registered myself as Cbuttius, I just can't be butted to log in.
  • SuperDre 2012-02-21 14:57
    mh:
    VB6 is 14 years old, no longer supported, gets no security updates, and VB6 applications will not work on Windows 8. That, in addition to VB6 being a crappy language that encourages programmers to write dangerous and/or unmaintainable code. Like "on error resume next".


    VB6 runs perfectly on Windows 8 (desktopversion, not on ARM, but any .NET application that is out there now won't run either on ARM).
    VB6 isn't a crappy language that encourages programmers to write dangerous and/or unmaintainable code, ANY language can do that, it's just as easy to write fubar code in C#, it's all up to the developer.. And yes, the error handling is a bit harder, but if done right you can get exactly the same as with any other language, again, it's just up to the developer..
    If you really think otherwise, then you really are a dumb developer..
    Personally I like the original VB6 language, it's much cleaner to read compared to C# (or any language with all their brackets), BUT yes it lacks a lot of newer programming paradigms, and I still hate MS for dumping VB7 and going with VB.net (yes there is actually a VB7 which is real OOP and has try/catch, but MS never released/finished it, because they went for the .NET framework). You can do about anything you want with VB6 if you take the time to understand the underlaying workings, hell there has been people who have even created inline assembly possibilities..
    Saying VB6 is slow, means you just don't know how to handle it, as I said If you know how it works/does things you can speed up a lot, but that's something that goes for ANY language..

    And in regard to the posted code, I also don't see any real problems, especially since we didn't see any of the implementation of the used functions.. Would I do it like this in VB6? I don't think so.. would I use VB6 for something like this? Why not (if I know the VB6 runtimes are available on the server anyway), if it gets the job done..
  • Anon 2012-02-21 20:16
    I think this post was a fail at a WTF itself, as the mistakes in its description presents more lack of knowledge than the script itself.