Archive for the ‘PHP’ Category
PHP Memcached Manager
We’ve been using memcached on both our sites for a while now to help alleviate database load and speed things up in general.
However, we’ve been lacking a good web-based manager to see the cache status and manually clear the cache. (I’ve been doing this via telnet on the command line and have been to busy to write my own script…..)
Today, I stumbled accross this gem: http://livebookmark.net/journal/2008/05/21/memcachephp-stats-like-apcphp/
It’s a simple GUI for memcached that is written in PHP and was exactly what I was looking for!
PHP Alternative Syntax
So, I was having a discussion with a fellow developer at work today about the advantages of using PHP’s alternative syntax (details here).
Just so we know where everyone’s coming from, I come from a programming background and my colleage comes from a design background.
Anyway, he came to me asking my opinion on using the alternative syntax in scripts where we have a lot of HTML markup mixed in with the PHP code. His reasons for wanting to do this? The same as most proponents for using the alternative syntax…….it’s shorter and is easier to read.
Now I try to be impartial when making coding decisions because, let’s face it, our opinions do not affect how the machines execute our code. It’s a travesty, but it’s true. However, I just don’t agree that alternative syntax makes code shorter or easier to read.
Wait, wait. Give me a chance to demonstrate my reasoning before you condem me.
Let’s look at some example code using the alternative syntax:
<p>What a niffty paragraph</p>
<?php if($a == $b): ?>
<p>Only the cool people see this!</p>
<?php endif; ?>
<p>Wow, aren't paragraphs great?</p>
Now, you might say, “this is super awesome. it’s so easy to see where the if block ends and there’s no separate lines for the PHP start and stop tags.”
However, you can do the same thing with less typing in the normal syntax.
Here’s the same code using the normal syntax:
<p>What a niffty paragraph</p>
<?php if($a == $b){ ?>
<p>Only the cool people see this!</p>
<?php } ?>
<p>Wow, aren't paragraphs great?</p>
As you can see, the normal syntax is shorter than the alternative syntax. The number of lines are the same, but the number of characters is less. Multiply this character difference by the number of times you use if, while, for, and switch in your script and you have a noticeably larger script file when using alternative syntax. Which means? Yep, it takes longer to execute scripts that use the alternative syntax than scripts that use the normal syntax. Is this execution time difference big enough to matter? Well, that’s a personal question that each script owner must answer for themselves.
And as for the readability aspect, any developer that is worth their salt uses an editor that highlights or otherwise shows matching braces. Want to know where the other one is? Just click on the one your curious about and the editor will show you the other one.
It is my experience that code is hard to read because the person who wrote it did not format it properly.
Anyway, that’s just my opinion. I’m sure everyone else has their own. Please feel free to discuss. Who knows, maybe you’ll change my mind
Comments (2)
Leave a Comment