SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Importance of clean source code - Possibly silly and pointless question

    Hi guys....

    This may seem really stupid, and I think I already know the answer...

    I have been building a PHP CMS, and have made sure that all of the dynamically generated output code is standards compliant, and validates to XHTML Strict.

    Now, when I view the source code, it is relatively messy, ie: no code indents etc...

    Now, even though the code maybe 100% valid, what do people think of, and what is the importance of having clean, indented source code, is it purely for easy readability? And should I be fretting over this?

    My answer would be, besides readability, that it doesnt matter.... ???

    D

  2. #2
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need to pretty-print the source code. Computers couldn't care less if the source code is pretty-printed or not, it's only useful for humans reading the source code.
    Simon Pieters

  3. #3
    Carpe Diem = Fish of the Day fisherboy's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dashman
    Hi guys....

    I have been building a PHP CMS, and have made sure that all of the dynamically generated output code is standards compliant, and validates to XHTML Strict.

    My answer would be, besides readability, that it doesnt matter.... ???

    D
    You have successfully answered your own question (IMO). Sounds like you've done a great job!
    fisherboy
    Web Site Design

  4. #4
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    guys, thanks for the replies.... that has eased my mind a tad....

    D

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2006
    Location
    Ohio USA
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On the other side

    I agree that it doesn't matter in the big scheme of things. But it is something that other designers might appreciate if your CMS is for public consumption.

    It can help in trouble shooting to easily read the source code.
    It shows that the dev put forth extra effort and cares for the the end product.

    I'm a bit anal about my code indents. I know it's not really important, but I've spent many hours going through several CMSs (blogs, shopping carts, photo gallerys) getting the generated source looking pretty / matching my templates.

    If it's for yourself, don't worry about it. If it'll be publicly available, consider it if you have the extra time.

  6. #6
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, thanks for that, but I was referring to the source code output to the borwser, in other words, what the user will see when viewing the source of a web page.

    As for clean formatting of my actual code within the cms, I always make sure that it is well formatted and easy to read... I wouldnt have it any other way

    D

  7. #7
    SitePoint Zealot
    Join Date
    Apr 2006
    Location
    Ohio USA
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As was I.

  8. #8
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, get ya....

  9. #9
    Non-Member deathshadow's Avatar
    Join Date
    Jul 2006
    Location
    Dublin, NH
    Posts
    901
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I write my original code, I usually try to make the output pretty to be able to see and verify that what I coded - and what I outputted is what I want...

    BUT, I maintain two codebases at all times on my projects - development and production...

    The biggest difference between the two, is the production, aka the copy that's going to go on a server, strips out all unneccessary characters like leading spaces and tabs and/or comments (I have a little pascal proggy I wrote a decade ago to do this to my source code) to reduce the size and shave a hair off the bandwidth use.

    In interpreted scripts like perl, this can often have the same effect as deleting comments in a old-school basic program - speeds up execution by making the parser not have to waste time on code that does nothing.

    Even in php this has it's advantages - like speeding up the parsing time (although if you are using a caching precompiler like eaccellerator this isn't as much of an issue)... The less data you feed the parser, the less time it takes to parse. It may only save ten to twenty clock cycles per character deleted, for a total of 2-5% cpu time during your peak hours, but that can often be the difference between processes backing up to overload the CPU on IOWAITS, and just chugging along at 98% cpu.

    On the HTML side this can be even more advantageous... because every unneccessary character you don't send to the user, is a byte of bandwidth saved... one byte might not sound like a lot, but let's say you have a 200 line CSS with everything nice and tabbed... You cut out 180 tabs and say 20 comment lines averaging 30 characters each, that's 780 bytes... or about a ninth of a second at 56K dailup for the user.... Times 100,000 hits in a month that 780 bytes is now 78 megs... Times fifty different sites on a server that's a few GIGS... it adds up.

  10. #10
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the insight, deathshadow

  11. #11
    Non-Member deathshadow's Avatar
    Join Date
    Jul 2006
    Location
    Dublin, NH
    Posts
    901
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, I'd also point out that smaller files = less disk read/write time, both on your server and in the clients cache... and for all the talk of cpu and RAM, disk access and bandwidth are the two REAL bottlenecks in a modern computer... Why do you think so much effort is put towards caching data in RAM?

  12. #12
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deathshadow
    but let's say you have a 200 line CSS with everything nice and tabbed... You cut out 180 tabs and say 20 comment lines averaging 30 characters each, that's 780 bytes.
    Just make sure you don't need to ask anyone on a forum to help debug your CSS then because I know I won't be looking at any stylesheets without any spaces!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •