[nycphp-talk] PHP is not just for professionals
Gary Mort
garyamort at gmail.com
Fri May 23 13:40:26 EDT 2014
On 05/23/2014 11:14 AM, GLENN POWELL wrote:
> One thing (among many) that I find makes it hard to work on these
> systems is the use of default
> behavior.
Ooo, I completely forgot about that.
In Joomla! for my own sake I've been avoiding default actions.
For example, in their MVC framework, if you don't specify the layout
template, it will load the template file "default.php".
My default.php file is:
<?php
trigger_error("Default view layout used", E_USER_DEPRECATED);
?>
That way at least I can review the log files and discover when I have
defaults being executed - and they don't break the application. IE the
web page might have a blank spot displayed on it but there are no blank
screens and no leaking of information.
> So far, the plan is to use an MVC pattern with controllers that read
> top down like an actual program.
>
One thing I tend to do nowadays is to use a modified drupal design
pattern for views. For example:
https://github.com/drupal/drupal/blob/7.x/modules/user/user-profile.tpl.php
From top to bottom, the view starts with describing what it used for.
Then it lists every variable it is expecting.
What I don't use is the bottom section, I try to use mostly self
contained views and I format them for my IDE:
----
<?php
// PHP setup code, do no change
/**
* @var $app \JApplication
* Joomla application object that has already been set externally
*/
/**
* @var $username String
* The user's name which be calculated locally
*/
// If the user is not logged on, use the default string 'World'
$username = ($app->user->isGuest()) ? 'World' : $app->user->username;
// html markup is below, change it as much as you need to
?>
...lots of html markup...
<p> Hello <?= $username; ?></p>
<?php
//leave php open to avoid extraneous chars
-----
By documenting the variables at the top of the page in PHPDoc format, my
IDE handles can provide type ahead for me and I can use it's "jump to"
functionality to jump to the class definition file.
I use locally scoped variables for anything that will be displayed in
html and php's shorthand echo notation to make it compact. IE instead
of the above I could have had:
<p> Hello <?php echo ($app->user->isGuest()) ? 'World' :
$app->user->username; ?></p>
However that means the html code is tightly coupled to the framework.
By creating local variables for any string values I am going to display,
I can easily change frameworks by changing the top section. And by
using shorthand notation in the html section, it makes the html readable
by the secretary who took a high school course in html - so she is free
to go in and modify the html for those minor changes that should not
require a PHP programmer to make.
> I have a top down controller that is readable and as self documenting
> as possible.
>
> No default behavior and nothing obfuscated.
>
> I don't think this is a very popular approach these days but I do
> think that it will serve well.
>
It doesn't bother me that it is not a popular style these days - what
bothers me is that I often hear people refer to it as "bad code style"
or "unprofessional".
It's not an "enterprise" code style - that doesn't make it bad or
unprofessional - it means it is not built to be maintained by an
international team of hundreds of programmers. It's written to be
maintained by a handful of programmers - which is exactly what a small
business needs.
To me it's unprofessional to implement a system where the cost is out of
proportion to the business to maintain and modify. But then, I started
programming back in the 1990's in an IBM town. I observed all the
businesses that were pushed into adopting the SAP platform because it
was "iso 9000" certified - only to end up conducting 80% of their
business 'off the books' because it didn't fit into the default SAP
configuration and SAP consultants charge 500+ an hour to customize it.
I'm my own worse enemy when it comes to doing freelance because I don't
try to push clients into implementing big expensive systems, and I don't
make promises about it 'solving all your problems'. I often don't get
the job in favor of someone who sells better... but in the end, I have
to live with myself.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20140523/600a8bb9/attachment.html>
More information about the talk
mailing list