Slashdot Mirror


Best Programming Practices For Web Developers

An anonymous reader writes "Web pages have become a major functional component of the daily lives of millions of people. Web developers are in a position to make that part of everyone's lives better. Why not try using traditional computer programming and best practices of software engineering?"

11 of 210 comments (clear)

  1. More than one side to this one... by fyngyrz · · Score: 5, Interesting

    Best programming practice is to do everything server side and not hijack the CPU of the site visitor; not depend on client-side active compatibility (for instance, just tried to pay for an EBay auction today, wouldn't work, don't use Explorer...) if you do server side processing, you can make it work for *everyone*. That alone is enough reason to go for it. Then there's Digg; Digg's pages are such a load on the visitor's CPU that I have to click "script not responding, continue?" three times on a page with 800 or so comments with Firefox and a dual-core 2 GHz CPU just to get the page to completely render. Sure, some of this is junk programming, not junk technology, but even so, if the server was doing the work of formatting (like it traditionally has here on slashdot), then it'd just be a matter of my browser reading HTML, instead of trying to run other people's scripts locally. I'd give up the web 2.0 "candy" in a second just to have a reliable web page.

    Sadly, I know people will typically go for glitz over functionality, so the only thing that will kill web 2.0 is web 3.0, and I have little doubt it'll be even worse. :(

    As for leaning towards good programming practices, my suggestion is to start by taking PHP off your server, learn Python (or Perl if you're feeling feisty) and write something that at least has a chance of being reasonably structured. Keeping in mind I'm a huge fan of Python.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:More than one side to this one... by dkh2 · · Score: 5, Interesting

      You missed one.

      4) Do not use methods that are OS or Browser specific.

      As for #3) - Absolutely true. Too many developers depend on sniffing the User-Agent string to determine browser capabilities. A much better, more reliable and easier to maintain approach is to test the specific capabilities you use, and provide a way for alternative access to the content. Note "alternative" != "100% equivalent."

      --
      My office has been taken over by iPod people.
    2. Re:More than one side to this one... by jsebrech · · Score: 2, Interesting

      As for leaning towards good programming practices, my suggestion is to start by taking PHP off your server, learn Python (or Perl if you're feeling feisty) and write something that at least has a chance of being reasonably structured. Keeping in mind I'm a huge fan of Python.

      You can do any OO design in PHP5 just as easily as in Python. PHP is less constrained. It allows people to use bad designs because this allows hobbyists who haven't learned correct design practices to build things. However, even though PHP allows you to build bad designs, it doesn't require you. It allows you to do everything by the book.

      The best programming practice for web applications architecture is to serve your target market. If the target market want glitz that requires flash, and doesn't care who that cuts out, that's what you deliver. The goal of the architecture is not to instill your own sense of right and wrong onto the user, it is to enable the user to do what they want to do with high performance.

    3. Re:More than one side to this one... by SCHecklerX · · Score: 4, Interesting

      Definitely. And because of this ability to adopt a particular style, Perl is the only language I know that I can walk away from for a year, and still be able to write a simple script without having to look at any reference material. If I ever have to do a comparison test in bash, I always have to dig up sample code to figure it out.

    4. Re:More than one side to this one... by skeeto · · Score: 4, Interesting

      anti-Flash zealots [...] assum[e] that bad use of a tool equals a bad tool

      If 98% of the use of hammers was just to smash random things for no reason in particular, I would avoid being around people who owned hammers. I would probably call it a "bad tool" as well.

    5. Re:More than one side to this one... by MikeFM · · Score: 3, Interesting

      Do anything but use Perl. Perl programs are often a nightmare to maintain because the vast majority of them are written by people who don't really know how to program in Perl and don't know or care enough to keep their programs readable. Perl is just to easy to make a freaking mess from so use it only when you have a specific job it's good for.

      Python works quite well for implementing the logic of an application thanks to it's clean syntax and good object support. It's not always the easiest to get working, and keep working, with your web server though. That's something I think should be improved. It works great but isn't as good a solution for a new developer because of that issue.

      PHP I usually use only for output logic and templating. I make remote calls to my app logic via XML-RPC and then use PHP to make it look nice. PHP is really easy to develop in so long as you don't code like a novice and cram everything into it. If you must program your entire app in PHP then please keep things clean and don't write HTML, CSS, Javascript, SQL, and PHP all inline. Don't mix user interface logic with application logic. If your application logic is going to be simple enough it's fine to write it in PHP so long as you keep it tidy. Sometimes it's easier than messing around with setting up something like Python as a backend.

      As for glitz over function - don't do it! Make sure things work first and then go back and try to make them look and feel nicer where you can - if you think it will really help. Don't make things complex to maintain if it isn't going to benefit the user. With CSS and Javascript behaviors it's easy to write a clean XHTML site and then layer in improved looks and interactivity.

      I was a programmer before the web came into existance and I started make web sites. I think there is a major benefit to learning to be a programmer and sysadmin first because you understand better how things can be done to be more effecient and easier to maintain.

      I've often seen developers spending a lot of time doing even simple tasks like preparing images that'd be much easier if they had programming experience. For example, cutting out product images - my graphic artists tend to hand trim the pictures which takes forever and results in a rough edge. When I do it I create a second layer in which I fill in the parts I don't want using the very quick use of the select tool and sliding the sensitivity back and forth. Then I use a drawing tool to just fill in the individual pixels I need to smooth things out. Mine take about 30 seconds each and look nicer than my graphic artists' 5 minute effort.

      I've seen developers spend a lot of time coding in features that could be configured in a couple minutes of configuring the web server or using a system feature such as cron jobs.

      In principal I agree with the article that it's good to gather requirements before you start and don't repeat yourself but I feel I have to point out that web development is often a rapid application design type of thing where you aren't given significant time to plan or implement your work and requirements will change often. It's best to develop some best practices that work for everything and stick to it. Usually your boss or client isn't going to have any idea what the requirements are so stick to your best practices unless you have something specific that needs changed and update your best practices as you build experience. Do try to keep from duplicating work or repeating yourself but don't spend an exhaustive amount of time avoiding it - instead do your work and refactor now and then as needed. Refactoring is a much better idea than trying to plan every possibly line of code.

      Testing I think is probably the most important thing, after following standards, that most web developers don't do. Get at least IE6, IE7, Firefox, Opera, and Safari and test every page of every site with each of them. As you develop test and re-test because things are going to change without you noticing. At least Firefox, Safari, and Ope

      --
      At what price learning? At what cost wisdom? The price is a man's peace of mind, and the cost is his life.
    6. Re:More than one side to this one... by Lodragandraoidh · · Score: 2, Interesting

      I would say the same thing about Python vs. Perl.

      There are so many different ways to do something in Perl that you end up doing what is expedient - but not maintainable over the long haul. On the other hand there is usually just one way to do a given thing in Python - which makes learning, and retaining the language much easier over time for me.

      I've written production programs in Perl, awk, sed, Java, C(++), Pascal, sh, php, and tcl for many years - and Python is just better in every way imaginable (JIT bytecode compilation, speed of development and debugging, more logical and standardized libraries and easy creation of your own libraries, strong (duck) typing, more of a 'computer science'-ish approach to programming including functional programming constructs, the ability to extend the language via a well defined interface in C, and out of the box GUI development using TK - "batteries included" indeed - when coupled with Zope/ZODB for persistence and web development, even more so).

      I am not saying you *can't* program well in the others - I am just saying it takes more control; control that most programmers do not have - particularly in the learning stages. Some never get it - and thus the abominations we see crawl from the dank cesspool that is the internet on an almost daily basis. Python enforces good programming practices, and minimizes the options for a developer to shoot himself in the foot - while retaining the power needed to get real work done. There are only a few situations I would not use Python (generally programming tasks that depend upon leveraging hardware - drivers and system kernels - where every CPU cycle counts).

      YMMV.

      --

      Lodragan Draoidh
      The more you explain it, the more I don't understand it. - Mark Twain
  2. Re:"Good practice" is an outdated concept by DangerJones · · Score: 2, Interesting

    I'm not a contractor - but I like his style.

    I'm a web developer with a successful SAAS product in the market. It's a cool flashy app that's kept us at the front of technology. Yesterday I could have either built a new ajax graph widget for the front page - so we can win another client - or fixed the log in code so it stopped calling the database twice per log in and save me having to order another server.

    Guess which I did? :)

    There are more types of apps and development practices in heaven and earth, Pike65, than are dreamt of in your advice.

  3. Re:"Good practice" is an outdated concept by Pike65 · · Score: 2, Interesting

    I guess that's what really grates on me.

    You tell a client that they need to pay for a new server and they're fine with that.
    You tell them that they can pay you 30 developer-hours to fix some issues so they won't need the new server in the first place and they act like you're trying to rob them.

    --
    "If being a geek means being passionate about something, then I pity those who aren't geeks." - Pike65
  4. Best Web Practices by curmudgeon99 · · Score: 2, Interesting

    Well, I have an entire website that is devoted to answering this question: Free Java Lectures is about that. Specifically, I have a lecture called "Web App Best Practices."

  5. DRY CSS example... by ItsLenny · · Score: 2, Interesting
    they said

    h1 { font-family: Helvetica, sans-serif; font-size 250% }
    h2 { font-family: Helvetica, sans-serif; font-size 200% }
    h3 { font-family: Helvetica, sans-serif; font-size 150% }
    h4 { font-family: Helvetica, sans-serif; font-size 100% }


    should be replaced with

    h1, h2, h3, h4 { font-family: Helvetica, sans-serif; }
    h1 { font-size 250% }
    h2 { font-size 200% }
    h3 { font-size 150% }
    h4 { font-size 100% }


    Then they go on to say...

    ...while the second isn't much shorter...

    the second one is actually LONGER and more characters and why do you even need that top line...umm are we not using a font tag in our body?

    body, td{ font-family: Helvetica, sans-serif; }

    this topic makes sence for PHP, java, javascript, ASP, etc... but HTML is not a programming language it has no logic... no loops.. it's just data storage really...

    the one thing I will admit (as a web designer who still makes everything in notepad) is the way web design software makes HTML does drive me nuts... but thats just 'cause I started making websites when the size of your file mattered back in the days of 28.8 k/33.6 k ...so I still think that every byte counts... however really in a word where almost everyone has DSL or better the size of an HTML document doesn't matter much at all (within reason)

    </rant>
    --
    ----------
    Trying to fix or change something only guarantees and perpetuates it's existence