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?"

5 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 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.

    3. 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.

    4. 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.