Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Canta como rafaé
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Barcelona
    Posts
    74
    Rep Power
    14

    Logic is not all


    Hi

    I've been programming since I was 13, with my C64, going then through PC with qbasic, C and asm. But it was not until I got to the university where I learned to program.

    Ok, they showed me a lot of concepts hard for me to understand in previous time. Algorithm analisys and efficience, kernel hacks, and lots of pro things.

    But the trouble was when I got to web programming.

    Web programming is a totally different thing that 'standard' programming.

    What if you had to make a C program with the assumption of "do not try to store anything in memory for efficience, you'll have to regenerate it for each query the user does". Incredible, but that's what we are doing in CGIs.

    Use sessions: ok, the user enters, but it's almost impossible to know when the user exits. Cleanup of resources tied to timers.

    But that's the matter of the logic. There's a worse thing: presentation !!

    As a post said once, how do I get to remove this little underscore at the right of an image ? Well, this man should have removed the spaces between the <img> tag and the </td> tag. Oh, don't use inline layers because they are not well supported.

    And in fact, when you ask some programmer to develop multiplattform standard code they say "uff, it's too hard work". But we are supposed to be able to develop for IE, NN4, NN6, Opera, Mozilla, WebTV, AOL, Nokia9110, palm devices, wap phones, and a long list of browsers. And also to be able to make them look fine in each of them, no matter if the user has messed up with the defaults of its browser.

    Well, at least cross-plattform C programming is not as hard as web programming.

    And there's other thing. C programming requires robustness of code, and that's what your boss wants. But web programming only requires that the colors fit well, and that's what your boss is expecting from you, not the logic.

    So in order to be a little pro in web programming, maybe two or three years would be enough.

    Web programming is craaaaazyyy !!

    But here we go ;-)
    Thrasher



    'Y se ahogaron los dooos
    No eran duros pa pagar, cuñaaoo !!'
    El vagamundo - El risitas y su cuñao
  2. #17
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792

    Re: Logic is not all


    Originally posted by Thrasher
    What if you had to make a C program with the assumption of "do not try to store anything in memory for efficience, you'll have to regenerate it for each query the user does". Incredible, but that's what we are doing in CGIs.

    Well, at least cross-plattform C programming is not as hard as web programming.
    First, not storing anything in memory until it is required is simple, just malloc what you need when you need, in the case of CGIs you may have dynamic mallocing involved, but it really isn't that bad.
    Second, have you ever tried writting cross-platform programs in C, or porting something that someone else has written to another platform? I would say that you are making it easier that it really is, and that isn't even touching the issue about making them compliant across multiple compilers.
  4. #18
  5. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    82

    Re: Logic is not all


    Originally posted by Thrasher

    What if you had to make a C program with the assumption of "do not try to store anything in memory for efficience, you'll have to regenerate it for each query the user does". Incredible, but that's what we are doing in CGIs.
    It's actually a nice feature of CGI scripts that you start with a clean environment on each invocation. No worry about memory leaks or stuck variables.

    Anyway, I do practically all my coding with mod_perl. Use mod_perl and IPC::SharedCache if you're really concerned about keeping data structures and compiled scripts persistently.

    PHP keeps compiled versions of scripts too. This is pretty much a non-issue once you get beyond newbie stage.

    Let face it, though. The "parse,compile,run" cycle of interpreted scripts isn't an issue for most sites out there. They don't get enough traffic. For those that do, they should either use PHP or mod_perl.

    Personally, I prefer mod_perl because it offers me the opportunity to make Apache my slave, programming the Apache API to do whatever I want. mod_perl handlers are AWESOME in the power, speed, and flexibility they offer.
  6. #19
  7. No Profile Picture
    Canta como rafaé
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Barcelona
    Posts
    74
    Rep Power
    14
    What I intended to say is that stateless programming is not as efficient as conventional programming.

    Suppose you have a tree of categories (the most common thing in forums) and you want to get the list of subcategories from a node. You have to grab the node to memory and recursively build the tree. Building a tree can have a quadratic cost.

    If you are in a stateless environment, you'll have to build the tree for each query you get, and in a conventional program, you build it once. You cannot (in an easy manner) get benefit from previous calculus in a stateless program, the only approaches are sessions.

    And about memory leaks ... for an experienced programmer it's not too difficult to restore a clean environment (maybe it's tedious, but not difficult). But that lends me to another question in PHP ...

    Suppose I have a class with huge memory usage. Will PHP free the memory of the class if I unset ($object) ? Or would mark the "pointer" with null to say that this object is no longer available ?

    I'll try to make some tests for this.
    Thrasher



    'Y se ahogaron los dooos
    No eran duros pa pagar, cuñaaoo !!'
    El vagamundo - El risitas y su cuñao
  8. #20
  9. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    82
    Originally posted by Thrasher

    Suppose you have a tree of categories (the most common thing in forums) and you want to get the list of subcategories from a node. You have to grab the node to memory and recursively build the tree. Building a tree can have a quadratic cost.
    I get your point, but I don't do this either for a tree-like structure.

    I use a cron script to create the data structure that creates the tree every minute or so, then "freeze" that data structure to disk using Storable.pm.

    In my mod_perl CGI scripts, I then just read this pre-created data structure off disk, avoiding all DBI or construction hits. I pass this pre-created data structure directly into HTML::Template.

    The trade off is that your data is a little stale, but the performance gain of avoiding recreating the data structure from DBI queries is enormous.

    In cases where data that is stale by a minute or so is unacceptable, this isn't a good solution. For most sites that manage content, however, this is fine, given that 99.99%+ of accesses are read-only.

    After using this "pre-created" system for a few sites, I've realized how truly expensive it is to create pages strictly from DBI hits. However, for most sites this isn't an issue again, because they don't get enough traffic to hit a performance bottleneck.

    I guess my point is that if you're clever and not afraid to play around, there are solutions for many state problems related to web programming.

    Would it be great if http weren't a stateless protocol? Yup, for developers. For consumers? Not necessarily.
  10. #21
  11. No Profile Picture
    Canta como rafaé
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Barcelona
    Posts
    74
    Rep Power
    14

    I like it !!


    I've done something similar with output control functions in php. I use them for caching intensive parts.

    Well, it's nice to see different methods of improving performance !!
    Thrasher



    'Y se ahogaron los dooos
    No eran duros pa pagar, cuñaaoo !!'
    El vagamundo - El risitas y su cuñao
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo