Wee...writing code again...

Discussion in 'OT Technology' started by deusexaethera, May 30, 2008.

  1. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Nothing like spending a day and a half writing a comprehensive error-trapper before I even know if there will be any errors to trap. As much as I like VB6, the complete lack of built-in global error-handling is a pain in the ass.
     
  2. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    I'm not a big fan of exception handling in the object oriented paradigm. It always seems to lead to some pretty shitty execution paths. I spent some time looking at aspect-oriented programming, and it seemed to handle exceptions pretty well.
     
  3. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Aspect-oriented programming...interesting, never heard of it.

    Yeah, it can be tricky when an object craps out but the program continues to execute; it requires very careful planning of what the failsafe operations should be, if in fact the program shouldn't just terminate itself altogether.

    I'll say this much, though; for two years I resisted putting comprehensive error traps into this program, and finally I just couldn't figure out some of the bugs, so I inserted an error trap into every single procedure (some 200+ of them), and in five minutes I fixed more errors that I never noticed before than I fixed in the past year of playing with the code blindly.
     
  4. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Right, but catching exceptions leads to error handling code being totally separate from the code thats trying to do something. This can be a big downside to exceptions.
     
  5. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I've never had a problem with it. I just structure the code like so:

    Code:
    Function X (arg1, arg2, Optional arg3)
        On Error GoTo CantDoX    'Open error trap.
    [I]        blah[/I]
        On Error Goto 0          'Close error trap.
    Exit Function
    
    CantDoX:
        Select Case Err.Number
            Case 1:
                [I]blah
                [/I]Resume Next
            Case Else:
                MsgBox "Oh shit!"
        End Select
    End Function
    Yes, it's separate, but so what? It's supposed to branch off if it hits an error, so...I don't see what the problem is.
     
  6. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Anyway, so I was worried I wouldn't actually catch any errors. Not to worry. I caught errors. Boy, did I ever catch some errors. But that was the point; finally, after six months of occasionally working on the code and mostly just ignoring the hell out of it, I have another stable release.

    I tell you what, writing my own XML parser was an eye-opening (and hole-opening) experience.
     
  7. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    oh my fucking god why the fuck are you using exit, goto? fucking shit. Why are you not using try, catch, finally?
     
  8. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Doesn't exist in VB6/VBS. When I'm writing in C++ or JavaScript, of course I use try{} catch{}. It doesn't matter though, the underlying mechanism is all the same. When a try{} block fails, it jumps the execution pointer to the start of the catch{} block, which is to say, there is an implicit GoTo call with a built-in Resume call at the end of the catch{} block.

    That built-in Resume makes it neater, I suppose, but to that I say the same thing I said to my CS professors who busted my balls for using raw pointers instead of iterators: "It compiles and runs without errors, so nuts to your concerns." This way, if I halfass it, it's immediately obvious because it throws up all over the place the first time I run it.
     
  9. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    why are you not using .net.

    (the period is there on purpose, this is not really a question)
     
  10. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    The point is that there's typically not a good way to correct the error condition that has arisen and continue normal execution of the program. When an exception occurs, usually there is some stack unwinding that occurs, which pretty much halts normal execution of your program.
     
  11. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I prefer to take the approach of correcting the error or crashing, so I don't have to worry about switching to another mode of execution. Still, though, if there is a way to code for errors where the mode of execution is chosen based on which errors will arise (i.e. preconditions), then I can see merit to that.
     
  12. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Because I don't like .NET. I don't want my code to be dependent on other people's code that can change at any time. And because VB.NET is a totally fucking different language than VB6. When it comes to C-based languages, which is what I use for work (not counting VBA scripts), I could care less if it's based on .NET or not.
     
  13. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    That's exactly the problem. In most situations, when an exception occurs, you are limited to notifying the user about the problem and then halting execution. There's no good way to correct the error and continue executing. When your catch block finishes, execution doesn't resume back where the error occurred; instead, it acts like the end of function execution, and control reverts back to the next stack frame. The only way to get back into the function in which the error initially arose is to re-call the function.
     
  14. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    If your code is simple, thats fine. Its when things get big that exceptions show their downsides.
     
  15. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I'll have to do a line-count on the app that I've been working on, but I'm pretty sure it comes out to over 100 pages of code, without line-wrapping. Haven't run into a problem yet, though it would be nice if VB6 had a built-in error handler for each function -- it would've saved me a lot of typing. Maybe I'll switch to .NET just so I can have that, in the future.

    EDIT: 5049 lines without comments, 6678 lines with comments. That's actually smaller than previous versions; switching to XML saved me a lot of non-reusable file parsing code.
     
    Last edited: Jun 3, 2008
  16. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I used a Java POS library recently that had 1000 exceptions defined in one big file up front, and these were thrown or caught in different ways throughout the program and... it was much less clear than handling them with if/else status codes. There are up-sides and down-sides to the method.

    But wait, is this architect talk? :big grin:
     
  17. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    They put all the exceptions at the beginning? Why? How are you ever supposed to make sense of it if you're reading through the code and you have to keep flipping back to Page 1 (so to speak) every time you run into a possible exception? Separate the exceptions, sure, but at least keep them in the same file as the rest of the code, if not the same function.

    EDIT: I don't know if it would be considered "architect talk". Strictly speaking, the actual structure of the code is below my purview when I'm working on a design; all I technically care about is that the code does what the design says it should do, though obviously some amount of oversight is needed to make sure the code isn't a horrific mess that will never be editable by anyone but the guy who created it.
     
  18. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    No, they define them up front, and they get handled all over. The point being that at that level of complexity the model breaks down.

    And, an architect's job is to pick libraries and methodologies. Thats what he does.
     
  19. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Ah, so kind of a "master coder", if you will. Gotcha.
     
  20. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    okay, so you hate object oriented design. great.

    did I hever mention you == :greddy:
     
  21. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Object-oriented design is great. Good thing VB6 supports it.

    Before you say "but it doesn't support inheritance", no it doesn't, but that's not a core concept of OOP, it's an add-on. Just as Triangle can be a subclass of Shape, it can also be its own class. It's not a big deal.
     
  22. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    ah, but you DID say you hate it:

    that's the whole point of OOD. You build a component once, and re-use many times. It doesn't matter how that component does what it does, just that it does it. It can be re-written a hundred times, extended a thousand more, and it doesn't change YOUR component.
     
  23. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    Most people would argue that inheritance is a core concept of object-oriented programming. Its one of the concepts that empowers OOP.
     
  24. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    ignore douchexathera. if he didn't constantly say he was 25 working in IT, I would just assume he was a 16 year old high school student who's parents bought him a 'puter for christmas and he found some old qbasic books at his local library.

    He definitely re-inforces my opinion that the majority of IT workers are failed CS-majors. These idiots are the reason outsourcing keeps happening. I can't blame businesses for outsourcing. I mean why pay more for us-based help that's just as shitty?
     
  25. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I passed all the classes that CS majors had to take, and I also passed engineering, calculus, physics, and business management classes that only the SE majors had to take. So blow it out your ass.
     

Share This Page