Re: 10 Dirty Little Web Development Tricks
patrick — Thu, 2008-12-04 04:37
This post is in response to my friend who pointed this out to me via Facebook/StumbleUpon - 10 Dirty Little Web Development Tricks by Yongfook. I may come back later and add the header names for each item, until then each of mine relate directly to the items in the article.
- I finally got work to switch from CVS to SVN o.O I finally got us to use
for staging, but not yet for production... We're usingsvn up
for production, which I guess is kind of nice, but afaik it doesn't delete any files that were deleted in the repository... or if it does, then it also probably ends up deleting any uploaded/cached files as well.svn export --force - I like using the CSS reset from Eric Meyer, but certain people at certain places I've worked at are doing well if they can remember an id is supposed to be unique on a page & that the class attribute is a space separated list (not a single value!) that can be used for more than CSS >.< ... Granted, a particular brand of browser is doing good if it can figure out how to apply multiply classed CSS definitions to an element (i.e.
.class1.class2 { color: #00f; }should be applied to<element class="class1 class2">). - Kind of have system & static stuff separated at my current place of employment - templates, css, etc go into a templates directory under htdocs & people are too scared to use a framework or an index router >.< My preference is a framework that can handle this (see Symfony or ZF)
- I don't drink coffee, but it's a nice idea - I've been drinking caffeine (in the form of pop) before going to bed for years... It helps me go to sleep. I have been drinking XS (no, it doesn't use sugar - it uses Ace-K as a sweetener, uses B vitamins for the boost [similar to that 5 hour energy drink], and has lots of yummy flavors) to prolong the time before I need to get to sleep. Drinking 1 right before bed can also help give a boost in the morning.
- Underscores are nifty, but I think he's missing the boat - generally speaking, come up with a useful convention for letting the file system organize files in general... underscores are great, but other things deserve organization as well - i.e. date based data output should be done in YYYY-MM-DD format for automatic sorting as another example :)
- I learned this trick of leaving off the ending
?>a couple of years ago - it's especially useful when dealing with windows users + svn as the average windows user doesn't know how to make their editor use unix line endings. Other nifty features:
- You also don't need the semi-colon on the end of the last line of php in certain instances like so:
<?php echo $blah ?>
However I'm still anal about the semi-colons, plus putting in the semi-colons prevents possible bugs if you ever need to come back and modify it. - Personal preferences and attempts at
benchmarking
the differences betweenechoandprintin PHP aside - there's a nifty difference that most people don't realize.printonly accepts 1 argument and therefore requires string parts to be concatenated prior to using it:
<?php print( $blah . ' ' . $blah2 ); ?>
Whereasechoaccepts multiple arguments and outputs each as given with no string concatenation:
<?php echo( $blah, ' ', $blah2 ); ?>
Makingechoslightly faster when needing to output multiple parameters. (note: paranthesis were added simply to show the similarity to typical function calls and are strictly optional - print and echo will work with or without them.)
- I think I was subconsciously aware of this, but hadn't consciously discovered this - now that this has been pointed out I'll remember it. Yay for pointed out ideas.
- I've been wanting to mess with jQuery for a while, but some of the parts are a bit overkill (do I really need full CSS element selection all the time? I'm usually just trying to set based off an id or a class.) & I'm not sure what that does to the process time. On 1 of these last projects I worked on, since we're just blindly including jQuery and several other js files I figured I'd check out the selector and used it to grab the element "#someid>.someclass" and it seems to work fine even in IE (for non-CSS gurus that's an html element with an id of "someid" with a direct child [does not include grandchildren elements] having a class of "someclass")
- For web development, MVC ftw. Although I stick Ajax functionality in the associated Controller... i.e. the User login ajaxy stuff is an extension of the User controller's login action - why rewrite code that's already there?
- I'm particularly fond of both Symfony and ZF as a framework base for MVC, but ZF requires you to put together your own index.php router and bootstrapping code. However, I'm also fond of utilizing ZF as just a library extension to whatever else I'm using as it has so many classes for handling all sorts of things you never thought of until you need it for a project.
And for the comment stating:
Here's another tip: use asp.net instead of php. You won't need so many lists of tips like this one any more.
I have to say that person really knows his stuff... I mean come on, join everybody else and leave your brain at the door, let Microsoft do everything for you... Only stupid people would want to do something other than bask in the glory that is... I'll stop here.
Before I get started (any further?) on this. Asp.net is simply a framework with an API that works in C#, Visual Basic, & many other languages. The friend of mine who pointed this out (and gave this post a 4 star rating on StumbleUpon) uses C#.net via mono (an open source version of .net so it can be used on unixes) and to my knowledge doesn't use PHP.
- SVN checkout as the production site - Using asp.net instead of PHP has no relation to this... unless he's simply inferring that when using asp.net you no longer need version control tools? I hope he's not this naive. Maybe he just means you don't need to use SVN update with asp.net and that FTP is better?
- CSS Reset - Um... I'm not sure what using asp.net over PHP has to do with CSS... other than from what I've seen asp.net follows web standards about as much as IE5 which using this train of thought might mean that when using asp.net who gives a flying rip about web standards?
- Separate Static and System Files - I think this should apply to all web based programming no matter what language/script (as well as frameworks) you use. Using asp.net afaik doesn't automatically make this so.
- Drink a coffee and take a 15 minute nap - What does using asp.net over PHP have to do with drinking a coffee & a 15 minute nap? Considering my dealings with Microsoft languages like Classic ASP, Visual Basic, and VBscript... If I continued to use those instead of having switched to PHP I think I'd need a lot more than just a coffee and a 15 minute nap... I'd need lots and lots of therapy.
- Use underscores to control your file lists - and using asp.net makes this so irrelevant because...? Oh, right, because you don't care about having organized files... Or am I missing something?
- Leave off the last
?>in php-only files - Hey, finally something that's strictly PHP related and we're already halfway through! This is true... afaik asp.net (or more specifically the individual languages utilizing asp.net) require the closing tag in spaghetti code... And if you're lucky to be using some sort of MVC or separating code from templates, you're probably also required to use the language's closing tags within the templates... Afaik, other than code specific files (like .js includes, etc), PHP is the only language where you can do without the final closing tag - anybody know of any other languages where this is possible? - Wrap floats in a float, to clear! - Oops, we're back to server side language neutral stuff again... unless of course you utilize tables for page design (eww! so 1990s!) It does seem like a lot of asp.net sites use tables for page designs (not to say there aren't a lot of crap PHP sites using tables either, but they wouldn't know what MVC was if it bit them)... is the table based page design a built in part of just using the asp.net tools?
- Use jquery and the Form plugin for Ajax interactions - I don't think this is PHP specific, but ok, I can see where asp.net (a framework, not a language) might out do PHP (a language, not a framework)... However, as soon as you drop asp.net and look at the specific language being utilized (i.e. C#, Visual Basic, etc), I'm pretty sure you'll have to revert to actually writing your own jQuery code. Of course if you want something to allow you to just
code behind
and the PHP framework you're utilizing doesn't already have something built in you could look at xajax for PHP which allows you to easily do that. - Controllers to handle input types - Another non-PHP specific list item, but applicable to PHP specific programming. I've not done anything with asp.net to know whether this is forcibly built in as a requirement or not, but I'm guessing it will let you write spaghetti code and completely circumvent the MVC... If it has an MVC? However, remove the asp.net portion and revert back to just the language being used (C#, Visual Basic, etc) and I'm positively sure that you can completely & happily ignore the thought of Controllers... But why would you want to?
- Install the Zend Framework - Aha! Here's the 2nd PHP specific
trick
in this list that... only applies to PHP and no other programming language (unless of course #6 actually does apply to some other language in which case this is the 1st PHP specifictrick
). Of course after installing and utilizing Zend Framework you're leaps and bounds ahead of asp.net from what I've seen... who's brilliant idea was it to limit you to 1 form object per page in asp.net? Oh yeah, the all knowing, all intelligent Microsoft... Of course as my friend pointed out you're not limited to 1 form object per page if you flush asp.net framework and use the base language, but weren't we comparing a framework (asp.net) to a language (PHP) to begin with?
Please lead us into enlightenment with thine ignorance so that we too might refute your ignorance with our ignorance or lead others to your ignorant enlightenment with that which you have bestowed upon us.
"I see!" said the blind man leading the deaf man.