A Rant About the Abuse of N-Tier Architecture

by AlmostAtheist 13 Replies latest jw friends

  • AlmostAtheist
    AlmostAtheist

    When you sit down to write a program, there are tons of different ways you can go about it. The "best" way doesn't exist. Sometimes it's driven by how many people will be using the program, or how quickly it has to be written, or how much money is supposed to be spent writing it.

    But sometimes none of that comes into play because of the standards established by the company you're working for. In that sort of environment, you do what you have to do, regardless of any other factors.

    Today I've been beating a program into submission under my company's "n-tier architecture" policy. It's driving me mad!

    Basically, each "tier" -- or "layer" -- of an application is broken apart and made separate from every other. (N-tier just means "multiple tiers") So the layer that talks to the user (the screen display, for instance) is wholly separate from the piece that decides if the data entered by the user is acceptable. (The "business rules" layer) These two are separated from the layer that manipulates the database, storing and retrieving the data. (The "data layer"). ('Wholly separate' might not be quite accurate, but the point is that I can yank out and completely overhaul one layer without disturbing the others.)

    There are good reasons for doing this. One is security. The user -- no matter how hacker-sharp he is -- can't find anything in the screen display or underlying code that tells him how to get to the database. (Though of course it could help him find the business layer, which leads into the database...)

    Another plus is that if you decide to put a different display on an application (like a handheld display, or a telephone-based interface), the only layer you have to change (theoretically) is the display layer. The other layers remain unchanged.

    Those plusses are more-or-less real.

    But they come at an incredible development cost. For instance, my boss said he'd like me to add a "Would you like to be contacted about this issue?" field to the screen, with a yes/no option. Single field in the database, single field on the screen. Should be easy, right?

    Here are the steps I went through to accomplish this:

    1. Create field in database.
    2. Modify stored procedure in database that inserts new record in table; add field.
    3. Modify stored procedure that updates existing record; add field.
    4. Modify stored procedure that retrieves record; add field
    5. (test all stored procedures by hand)
    6. Modify VisualBasic Component class that handles this record, add variable to hold the value of the field.
    7. Modify class, add "get" method for this variable
    8. Modify class, add "set" method for this variable
    9. Modify class, modify method that saves record to send the value of the variable to the database when it calls the previously modified stored procedure.
    10. Modify class, modify method that updates the record
    11. Modify class, modify method that retrieves the record
    12. Modify Display layer, add field to the "new record" screen
    13. modify display, add field to the "update record" screen
    14. modify display code, add call to "set" method on "new record"
    15. modify display code, add call to "set" method on "update record"
    16. modify display code, add call to "get" method on "update record"
    17. (test display and business layers together because I couldn't bring myself to write a script to test just the business layer)

    (I should note that this application is itself not written terribly well, the "new" and "update" should really be in the same program, rather than two separate ones. I inherited this code, and it's not worth merging them now.)

    Believe it or not, it gets worse. Rather than simply registering the DLL's on the web server, we run them as COM+ Applications. (To allow the web server to be on one machine and the COM calls to be shuttled over to some other machine.) So whenever I make a change to the COM layer (which is every 5-10 minutes for about 3 hours while I'm working on it) I have to:
    Unload the web application (to get it to release the DLL)

    1. Delete the COM+ application
    2. Compile the DLL
    3. Recreate the COM+ application
    4. Drop the DLL into the application to show it the methods available

    Then I run a test. And it fails. So I dig around, try something else, and repeat the above process. It's absolutely mind-numbing!!!

    Especially because it is SO UNNECCESSARY!!!

    Any purist that wants to leap in here and tell me that it's developers like me that make lousy applications that are hard to pull apart later, and that can't be split over multiple machines, and yada yada, go right ahead. It won't matter, I HAVE to do it this way anyway. But I'll never agree it's a good idea. (Not applied across the board, to every damn app in the enterprise, anyway.) The time it takes to write one of these n-tier apps could easily write the same thing twice without it. Probably thrice. So if you build 2 applications without it, and that forces you to completely rewrite one of them to handle some new display or database or whatever, you're still money ahead. And in my experience, that next-to-never happens. You 'keep the door open' for whatever changes they think they might want to make, then they never make them. It's like having a trunk full of spare tires for cars you don't own -- just in case.

    Not only does all of this take a ridiculous amount of time to code, but it adds complexity to the program. Complexity always means more bugs, and a steeper learning curve for the next poor fool that has to work on the code. I try to be helpful and name all the related variables the same. The field in the database, the variable, the set/get methods, the field in the HTML form, the javascript variable that holds the value for client-side validation -- they're all named the same. That helps, but there's just so MANY of them. Sheesh!

    (And of course, you have to factor in the time it takes to go online and rant and rave about it.)

    There. I got it out. Thank you for letting me take up a spot of your time to holler at this stuff! I do feel a touch better.

    Dave

  • daystar
    daystar

    homeboy-say-what?

    Really, I halfway understood what you're saying. I hated coding. I started with Basic, as many have, and progressed onto C and Pascal before completely losing interest.

    Some of the sort of thing you're talking about is all too familiar to me though. Our poor, poor developers...

  • Simon
    Simon

    I know what you mean but you can make things easier on yourself with the right tools and libraries. For instance, with OR/M mappring (such as [N]Hiberate) and some class generators you would just have:

    1. Create field in database.
    2. Modify stored procedure in database that inserts new record in table; add field.
    3. Modify stored procedure that updates existing record; add field.
    4. Modify stored procedure that retrieves record; add field
    5. (test all stored procedures by hand)
    6. Modify VisualBasic Component class that handles this record, add variable to hold the value of the field.
    7. Modify class, add "get" method for this variable
    8. Modify class, add "set" method for this variable
    9. Modify class, modify method that saves record to send the value of the variable to the database when it calls the previously modified stored procedure.
    10. Modify class, modify method that updates the record
    11. Modify class, modify method that retrieves the record
    12. Modify Display layer, add field to the "new record" screen
    13. modify display, add field to the "update record" screen
    14. modify display code, add call to "set" method on "new record"
    15. modify display code, add call to "set" method on "update record"
    16. modify display code, add call to "get" method on "update record"
    17. (test display and business layers together because I couldn't bring myself to write a script to test just the business layer)

    I removed the last one because a good xUnit test setup should make that very quick and easy (to just add another field and check the CRUD uperations)

    It can be sould destroying when the sun outcome of two days work is just a link on a page ! (and you know no-one will see or care about all the layers it goes through to get it).

    The reason for all the layers and patterns though is to make it easier to replace and re-use layers and to use best-practice when developing, eg. mocking other layers when doing unit testing.

  • Billygoat
    Billygoat

    Translation:

    ????? ?? ?????? ?????? ?? ???????? ?????????, ??? ?????? ??????? ??-??????? ?????, ????? ?? ?????? ????? ? ??. "????? ??????" ?????? ?? ??????????. ?????? ??? ??????????? how many ???? ????? ???????????? ?????????, ??? ??? ?????? ??? ?????? ???? ????????, ??? ????????????, ??? ???? ? how much ????? ??????????? ??????????????? ???. ?? ?????? ??????? ?? ???? ???????? ? ???? ??-?? ?????????? ????????????? ?????????, ????? ?? ????????? ???. ? ??? ???? ?????????? ?????, ?? ??????? ?? ? ????? ???????, regardless of ??? ?????? ???????. ??????? ? ??? ????????? ? ????????????? ??? "????????? ????????? ?-4rusa" ???? ????????. ??? ????????? ???? ??????????! ???????, ?????? "????" -- ??? "????" -- ?????????? ????????? Dave

    *giggle* Andi

  • ackack
    ackack

    You this this is bad, but imagine splitting this across multiple vendors... everything takes sooo much time.

    ackack

  • Billygoat
    Billygoat

    Thanks Simon. See? What would we do without you techie-folk???

    Andi

  • DanTheMan
    DanTheMan

    holy shmokes

    you know those SQL queries I told you about Dave? Heh, well, that post made me realize that I am light years, LIGHT YEARS away from being an actual programmer.

  • Simon
    Simon
    Believe it or not, it gets worse. Rather than simply registering the DLL's on the web server, we run them as COM+ Applications. (To allow the web server to be on one machine and the COM calls to be shuttled over to some other machine.) So whenever I make a change to the COM layer (which is every 5-10 minutes for about 3 hours while I'm working on it) I have to:

    Unload the web application (to get it to release the DLL)
    1. Delete the COM+ application
    2. Compile the DLL
    3. Recreate the COM+ application
    4. Drop the DLL into the application to show it the methods available

    Then I run a test. And it fails. So I dig around, try something else, and repeat the above process. It's absolutely mind-numbing!!!

    WebServices and some .NET / Com Interop would probably ease some of this pain too ...

  • Elsewhere
    Elsewhere

    Something my years of development have taught me is that doing things according to strict programming theory is not always the best way. Sometimes you have to bend, or even break, programming theory rules in order to get an application to do what it is supposed to do in a timely manner.

    I've seen programs that followed programming theory perfectly but ended up being massive inefficient programs that ate up obscene amounts of recourses.

  • seattleniceguy
    seattleniceguy

    I feel your pain, Dave.

    Seeing that you probably can't change technologies over there, this may just be rubbing it in your face, but have you had a chance to use .NET technologies like the ones Simon mentioned? Especially when it comes to debugging, these are incredible tools because you can step through the code, across DLLs, even across processes in the case of Web Services. So for example, in debug mode, you can actually step from the client call into the server code and continue debugging. My eyes popped out of my head and rolled around on my desk for several minutes when I first discovered this. Makes development a dream.

    Anyway, good luck getting through your project.

    SNG

Share this

Google+
Pinterest
Reddit