The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 17, 2019, 12:02:20 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: A Concession to Nutballs aka Why PHP Sucks  (Read 6417 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« on: September 26, 2007, 11:13:07 AM »

Well, it doesn’t, but people can really make it suck.

I’m writing this because I just tackled my first blog – I have many clients that want a deeply-customized blog and I needed to know the methods behind this. So, I grabbed WordPress, got familiar with it then started looking at how to build custom themes from the ground up. You can find my efforts here:

http://www.perkiset.org/politics/

But now, back to WordPress:

IT SUCKS.

Why, you may ask?

Because the WP people used the oldest and least-strong form of PHP programmatic structure there is, and the very thing that Nutballs doesn’t care for: a complete blending of the presentation and actuary code.

Now we all know that PHP came from the days when a page was 98% HTML and you wanted to add a little tag for the counter, or the date or something. The format for that was simple: in the middle of an HTML page, you’d just add a little PHP tag:

Code:
<font size="3"><b><?php echo date('m/d/Y'time()); ?></b></font>

This was a clever “add” to the language of the then-newfangled World Wide Web. But it's shit on a biscuit now. There are two essential ways of programming with PHP: HTML with PHP tags interspersed – I’ll call things HTML+PHP for the rest of this post, and PHP outputting HTML chunks – which I’ll call TRWTC from now. (The Right Way To Code).

Consider this snippet:

Code:
<?php get_header(); ?>

<div id="middle">

<div id="content">

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>
<div class="title">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
                   
                </div>
<div class="post" id="post-<?php the_ID(); ?>">
<p class="small">posted by <?php the_author() ?> on <?php the_time('M'?> <?php the_time('j'?></p>
                    <div class="clear"></div>
                    <div class="entry">
<?php the_content('Read the rest of this entry &raquo;'); ?>
</div>
</div>
<div class="postfooter">
<p class="postmetadata alignleft">Posted in <?php the_category(', '?></p>
<p class="alignright"><?php edit_post_link('Edit'''' | '); ?>  <?php comments_popup_link('No Comments &#38;#187;''1 Comment &#38;#187;''% Comments &#38;#187;'); ?></p>
<div class="clear"></div>
</div>
<?php endwhile; ?>

<div class="navigation">
<div class="alignleft"><?php next_posts_link('&laquo; Previous Entries'?></div>
<div class="alignright"><?php previous_posts_link('Next Entries &raquo;'?></div>
<div class="clear"></div>
</div>

<?php else : ?>

<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH "/searchform.php"); ?>

<?php endif; ?>

</div>

<?php get_sidebar(); ?>

<div class="clear"></div>

</div>
<?php get_footer(); ?>

Notice how they have actually created loops with inserted PHP tags! It’s HORRIBLE! There are 3 fundamental problems with this sort of programming – particularly when you’re building some big and nasty like WordPress:

•   HTML looks alright, but your programming language is chunked up and difficult to follow. There is no flow and the language is interspersed with non-actuary code. It’s terribly difficult to follow, particularly if it hasn't been nicely indented as it is here.
•   There is no going back: once you’ve output something, it’s streamed to the user. Without getting deeply into output control functions, in the immortal words of Sally, “It’s out there. You can’t take it back once it’s out there.” This is a problem with the PHP mechanism in general if you’re not careful: any text characters outside of the <? ?> tags are output IMMEDIATELY to the surfer. This means that if you have a space or CR/LF in the front or back of a pure-php file, that will go out EVEN BEFORE YOUR CODE, meaning that if you call header() to do something special it wont work, because it’s already out there. The notion of flow control is right out. This is just entirely bad form, because what if, during the course of constructing your page, you decide that the TITLE tag must be different – well, you can.t It’s gone.
•   Lastly, there is no simply way to “blend” the two styles of PHP programming (HTML+PHP or TRWTC) – once you’re on the track of HTML+PHP you’re done.

In a system like WordPress, particularly since they’re at version 2.2.3 or something like that now, you’d expect that they’d moved beyond the ancient and antiquated HTML+PHP model, but the truth about coders wins: Ugly coders write ugly code, regardless of language. And the WordPress folks wrote some DAMN ugly code. SMF is the opposite. Completely TRWTC, even though it is pretty unattractive. But the difference could not be more stark.

In WordPress they even do profoundly stupid things like echoing the return value of a function rather than returning it – this means that you are FORCED into the HTML+PHP model even if you want to modify it, because the functions you’re calling are streaming to the surfer RIGHT NOW. And worse, some function assume that the <current PHP tag> is inside of a <ul><li> arrangement and add LI tags around the output and some don’t - the inconsistency and lack of flexibility is just amazingly poor.

So: I’ll be completely rewriting WordPress from the ground up this afternoon  ROFLMAO - how I wish I had the time.

In any case, take heed: Friends don’t let friends code HTML+PHP.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
jairez
Expert
****
Offline Offline

Posts: 164


JTFC


View Profile
« Reply #1 on: September 26, 2007, 12:45:19 PM »

HTML+PHP ... please don't take away my editor?!?!

Kind of funny ... I've typically seeded my sites this way with the intention of fleshing them out, but typically only "functional" pages get the TRWTC treatment.  But ... guilty as charged

/me
Logged

Spontaneity has it's time and place.  [Sluggo, 1990-ish]
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: September 26, 2007, 12:51:11 PM »

Wasn't a shot at you at all J, just a thought in general. The WordPress folks should *really* not be doing this... it's a different way of thinking, particularly for someone who came from HTML into PHP rather than a coder that came to the web.

Doesn't take anything from you at all, just a restructuring of the way that you build a site. As SMSd, a good place to see the difference is to download and look at the entire Dynamic Site Example I posted here a bit ago.

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: September 26, 2007, 04:06:47 PM »

I agree! lol
actually, I do think you can intermingle, i just don't think you should. The only time it is appropriate is for a self contained drop-in. Such as the same way you drop in an Adsense block, or any other remotely hosted JS file that handles some completely compartmentalized display object.

i too have been considering the shortcomings of wordpress and have been thinking of writing my own blog solution. In some respects WP is great, all the plugins, and templates. In other respects, it sucks, trying to be everything to everyone. I have considered making a system that is bare bones.
write to draft
publish
users
comments
tags/categories
and an easy as shit template system.

the reason I haven't is because there is WP. It already exists, and frankly does what I want, though with more fat that I would ever want or need. Also, the day is not long enough.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #4 on: September 26, 2007, 04:23:29 PM »

While grumbling about it a while ago, I thought that, rather than rewrite, perhaps an addition would work - here's my thought:

WP does a fine job of managing a user, and the back-office component is good enough. It's the front-end stuff that pisses me off.

So I was thinking about building a WP API that essentially wraps the same code into an object or functional structure so that I could write what and how I wanted to. (Of course, there's another VASTLY more important API in front of that one Wink ) In this way you could have all the benefits but get past the crappy code.

I dunno, I agree - the day is just not long enough.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
arms
Expert
****
Offline Offline

Posts: 235



View Profile
« Reply #5 on: September 26, 2007, 05:02:25 PM »

thank you for saying it.
i was looking at using drupal as a cms and i was impressed until i looked into making a theme. wordpress too.
fucking html+php diarrhea.
in the time it would take me to learn how to theme either one i (mostly) wrote my own blog in python+django.

ffs what the hell do they have against using some kind of templating?

for me TRWTC would be MVCish with the logic completely seperate from the view, using some kind of templating engine.

i was about to disagree with your TRWTC, then i read it before ran my mouth off. almost the same thing.
 
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #6 on: September 26, 2007, 05:09:34 PM »

fucking html+php diarrhea.
in the time it would take me to learn how to theme either one i (mostly) wrote my own blog in python+django.

I totally get it... every frigging keystroke I made working through my blog on WP just made me itch to do it all myself... however, I have clients that want it done in WP so I must learn it.

Worse: the templates I downloaded that were all tricky CSS had MAJOR discrepancies between IE, FF and Safari. Predominantely, if they worked on FF and Saf then they looked nasty on IE and vice versa. So I stepped way back to a table structure and it looks nice no matter what. And the completely bullshit way that WP was written certainly made that an interesting exercise...

Shittah, the more cool and tricky things get the more they are unmanageable.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
jairez
Expert
****
Offline Offline

Posts: 164


JTFC


View Profile
« Reply #7 on: September 26, 2007, 10:41:46 PM »

This has been a very enlightening thread, as I downloaded WP about 6 months ago and just left the printed intro dox rotting on my nightstand.

I guess unconscious decisions may have value as well.

Then again, I'll probably have to learn it at some point, then I can join you blokes at the bar crying in our bloggers' beer ... all because you guys couldn't find enough time in the day.     ROFLMAO
Logged

Spontaneity has it's time and place.  [Sluggo, 1990-ish]
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #8 on: September 27, 2007, 08:59:39 AM »

This has been a very enlightening thread, as I downloaded WP about 6 months ago and just left the printed intro dox rotting on my nightstand.
ROFLMAO ROFLMAO ROFLMAO
I did the same, like 3 times. It was like pulling teeth to finally get my butt into gear on it.


Then again, I'll probably have to learn it at some point, then I can join you blokes at the bar crying in our bloggers' beer ... all because you guys couldn't find enough time in the day.     ROFLMAO
Given what you're currently up to, I think you'd do well simply to understand how to use and set it up for others... there are so many themes out there that you could get a *long* way on "stock" stuff and then begin to learn to tweak as you go. My suggestion: learn WordPress config/setup, SMF config/setup and phpCollab config/setup and you'll have a quite healthy rack of new tools for clients. Read, fantastically high-return looking but low-time-investment billable hours... Wink kaCHING!


/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
jairez
Expert
****
Offline Offline

Posts: 164


JTFC


View Profile
« Reply #9 on: September 27, 2007, 11:41:56 AM »

Great idea.  Maybe I'll dust it off and see if I can get that dog to hunt.  After all,

Quote
fantastically high-return looking but low-time-investment billable hours... Wink kaCHING!

... me likey-likey the sound of the cache register  Grin
Logged

Spontaneity has it's time and place.  [Sluggo, 1990-ish]
freedom1972
Rookie
**
Offline Offline

Posts: 17


View Profile
« Reply #10 on: October 02, 2007, 06:39:22 AM »

I admit it - I am guilty. I used to write DB/Applications in Perl, and there was really on TRWTC options for integrating the two. When I first came acorss PHP, it "Seemed" to make building out web apps so much easier because of allowing HTML and PHP to be mixed. And yes, for quick DB insertions or passing variables ot my pages for simplistic dynamic page creation I love PHP. Like you clearly pointed out, the challenge comes when people take "Duct Tape" methods and try to build a whole system around it. Thats is what the wordpress code looks like, and hence it is ugly.

That has always been the double edged sword for me with scripting languages. I can crank out some down and dirty code to get something done. Pretty soon, thats all you do, and your 50% into taping an application together when the idea strikes you: "Perhaps this needs a better design!"
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #11 on: October 02, 2007, 09:39:47 AM »

I REALLY understand the hatred of "refactoring" and starting from scratch... I've done things like that so many times it's just not even funny.

But I've also been one to really benefit from taking the time (and enduring the headache) of stepping back and saying, you know - I'm gonna type the fingerprints off my hands to do this, but it is the right thing to do... and rewrite.

The WordPress folks should take the time to see just how craqppy their codebase is and give it an update. They would *really* dominate then.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
MangoPirate
n00b
*
Offline Offline

Posts: 9


View Profile
« Reply #12 on: October 02, 2007, 01:16:02 PM »

Would be a nice idea to mail this thread to the people at WP, would especially love it if sits posted on matt's blog.

Shoot a mail out prof..


I really need to learn php...
Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!