Category:PHP code: Difference between revisions

From Robupixipedia
Jump to navigationJump to search
(made this a subcategory of programming)
(added example code reason I disliked PHP code)
Line 3: Line 3:
At my job, I was basically required to use PHP, and...  I have come to realize it is not actually all that bad.  In fact, in several ways, it's pretty awesome.
At my job, I was basically required to use PHP, and...  I have come to realize it is not actually all that bad.  In fact, in several ways, it's pretty awesome.


I actually still believe that, and so here is what happened:
Basically, I think this type of coding is crap:
<source lang="php">
<?php
//***********************************************//
//
// this code is crap and formatted as such
//
//
//    fantastic description of great program
//
//
/***********************************************/
<html>
<head>
</head>
<body>
<h1>title</h1>
<p>Here is the thing for today: <?php $thing = $DB->getThing(date("Y.m.d")); echo $thing; ?> I love it!</p>
</body>
</html>
</source>
I would see all types of things written inline, and I couldn't grok the overview of the code for anything.
I finally decided on this type of rule.  For simple echo statements, such as
<source lang="php"><?php echo "echo statements"; ?></source>
I would happily code them inline.  But if there was actual programming logic, I want that pulled "out"
<source lang="php">
<?php
//***********************************************//
//
// this code is crap, but formatted nicely
//
//
//    fantastic description of great program
//
//
/***********************************************/
<html>
<head>
</head>
<body>
<h1>title</h1>
<p>Here is the thing for today:
<?php
    $thing = $DB->getThing(date("Y.m.d"));
    echo $thing;
?>
I love it!</p>
</body>
</html>
</source>
For me, this makes all the difference in the readability of the code.


[[Category:Programming]]
[[Category:Programming]]

Revision as of 22:58, 12 December 2007

Not so long ago, I didn't like PHP because I didn't like having "code inside HTML." I preferred Perl, where the code was first, and the HTML was produced by the code. "HTML inside code"

At my job, I was basically required to use PHP, and... I have come to realize it is not actually all that bad. In fact, in several ways, it's pretty awesome.

I actually still believe that, and so here is what happened:

Basically, I think this type of coding is crap:

<source lang="php"> <?php //***********************************************// // // this code is crap and formatted as such // // // fantastic description of great program // // /***********************************************/

<html> <head> </head> <body>

title

Here is the thing for today: <?php $thing = $DB->getThing(date("Y.m.d")); echo $thing; ?> I love it!

</body> </html> </source>

I would see all types of things written inline, and I couldn't grok the overview of the code for anything.

I finally decided on this type of rule. For simple echo statements, such as

<source lang="php"><?php echo "echo statements"; ?></source>

I would happily code them inline. But if there was actual programming logic, I want that pulled "out"

<source lang="php"> <?php //***********************************************// // // this code is crap, but formatted nicely // // // fantastic description of great program // // /***********************************************/

<html> <head> </head> <body>

title

Here is the thing for today: <?php $thing = $DB->getThing(date("Y.m.d")); echo $thing; ?> I love it!

</body> </html> </source>

For me, this makes all the difference in the readability of the code.

Subcategories

This category has only the following subcategory.

Pages in category "PHP code"

The following 2 pages are in this category, out of 2 total.