...

View Full Version : General question about best PHP practices.



bowser1111
03-31-2007, 02:14 PM
There's something that's been driving me crazy about PHP, and for some reason I just can't seem to wrap my mind about it...

When using PHP includes, which of these is better practice:

1. Having things such as a DOCTYPE and title in each PHP file, using multiple includes for common parts of a site, like the header, navigation, footer, etc. In other words dealing with things "as they come".

2. Gathering all your variables up and "passing" them to a single include. I suppose this would be something similar to "templating" like Smarty does.


I'm prepared for a "there's no one set way to do things" answer, but what's been sending my head around in circles is this: Using method number 2 would essentially mean that you would have to "echo" everything, correct? It seems like it might potentially be a headache to have to get everything into variables first. HOWEVER, number 1 somehow seems "wasteful" in that it would require more include calls (how much do these really bog things down?), and things like your DOCTYPE would be unnecessarily repeated.

Can someone just tell me which way they prefer and why? The more I think about it the farther away I seem to get from an answer...

Nightfire
03-31-2007, 02:23 PM
I just make one page then use my own template system to transfer the template to all the other pages. I only really use includes for like db settings, global config settings, functions etc. For html I leave that for the template system

bowser1111
03-31-2007, 02:28 PM
I just make one page then use my own template system to transfer the template to all the other pages. I only really use includes for like db settings, global config settings, functions etc. For html I leave that for the template system

Can you elaborate on this a bit? How exactly are you implementing this (a very simple example is fine).

Nightfire
03-31-2007, 03:10 PM
Simplified version. That'd be one page, the template page is stored in another folder elsewhere and is put onto the page by the template function at the bottom once everything else has been completed


<?php
function sensitiveconfig(){
db details here or any other details not to be seen
grab file from below doc_root
}

function globaluses(){
check, filter, store, clean variables used often, validate form entries, urls, etc
store navigation in an array here
}

function Template($url){
open html file, read it, grab variables and output to page
}
?>

The HTML file will look just like a normal html file, apart from I'd have variables in it for php to replace with things from my functions.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>{{title}}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="style.css" />
<!--[if lte IE 6]>
<link href="ie.css" rel="stylesheet" type="text/css" />
<![endif] -->
</head>
<body>
<div class="banner">
{{banner}}
</div>
<div class="nav">
{{navigation}}
</div>
<div class="content">
{{content}}
</div>
</body>
</html>

bowser1111
03-31-2007, 03:15 PM
And so I gather that your Template() function is parsing the HTML file and replacing the variables inside by searching out "{{" and "}}", correct?

If that's the case then no include() statements will be used whatsoever, no?

Nightfire
03-31-2007, 03:21 PM
I use includes very little. It depends on how I've built the site really. Every site I do I do it differently as I'm trying to find the easiest and best way.

If I have a big site, I store all the info and html that doesn't change on each page in a db, I'd then use includes on a page to get all the info out


<?php
include 'global.php';
// db querys here
// echo out headers
html here for different layouts on the page
// echo out content
more html
// echo out footer and closing html page
?>


global.php will have everything stored, aswell as other include files in there to separate info so it's not a huge include file I'd be working on

iLLin
03-31-2007, 03:23 PM
He just showed you a real generic breakdown. If you think about it, you will be using includes, require (w/e) in your php pages. Your php page will put your page together by including the appropriate template to parse...

bowser1111
03-31-2007, 03:33 PM
I guess what's really throwing me for a loop is the fact that if you use an include it means you get all the included content "as it comes" right? I mean, in a standard site you would at least probably have static headers and footers, with changing content in the middle, right? Then that would by definition mean that you would need at least two includes, correct?

Nightfire
03-31-2007, 03:36 PM
no, in the include files, use functions, then call the functions in the php page where you want them displayed. No need for loads of include files scattered around a page. It'll be messy and hard to update and remember where bits of pages are when you come back to it in 6+ months time

bowser1111
03-31-2007, 03:43 PM
AH! Now it's starting to make more sense! I was (dimly) on the verge of arriving at this conclusion myself, but here's what tripped me up about that: Wouldn't that way of doing it involve a lot of bulky print() or echo statements? Isn't that...ahem..."dirty"?

iLLin
03-31-2007, 03:54 PM
Not at all, but before I starting using templates it was. I had html code mixed in with php code in my functions and I would to this and that and return html. I don't do that anymore with templates. I cheat and use smarty for my engine so my pages look like this:



require_once('modules/'.$module.'/'.$module.'.php');
require_once('classes/navigation.php');

$focus = new $module();

$smarty->assign("fields", $focus->fields);
$smarty->assign("module_name" , $focus->module_name);
... other ones
$smarty->display('modules/'.$module.'/templates/view.tpl');


Then my template looks like this:




<div class="page_header"><img src="images/{$module}.png" class="inlineimg" /> {$module_name}: Home</div>
<div class="bar-blue">&nbsp;</div>
<br />
.....


Then any functions I include I call in my php page and the only html that I return is when I build out my forms. Where the field is marked as text, select, radio... w/e. That way I can just assign fields in my class files with codes and then pull the correct output instead having to type out every damn form I use :).

bowser1111
03-31-2007, 04:13 PM
I see... I was considering using Smarty myself. Before I do, though, I'm interesting if anyone knows how much it affects the server load...? I'm sure it's using a lot of it's own functions in the background...

GJay
03-31-2007, 04:18 PM
Smarty is, as template-systems go, fast. It doesn't do run-time pattern-matching (well, it can be set to do so for development purposes, but can be turned off for production), but instead 'compiles' the templates into PHP code.

iLLin
03-31-2007, 05:32 PM
Yea if I had time I would develop my own but I just don't. With all open source projects it is very bulky and you will probably not use everything they offer. But it is a very good templating system IMO.

bowser1111
03-31-2007, 08:05 PM
With all open source projects it is very bulky and you will probably not use everything they offer.

See, I'm not sure what you mean by this. If I'm not using everything they offer then how is it bulky? Or are you saying that it all has to be imported and it will be wasting resources it doesn't need?

iLLin
04-01-2007, 01:54 AM
Yea i like speed and when you load up 250k files every load when you dont need half that... makes little sense to me. Yea you probably won't notice it but every little bit counts IMO. That is why I'm a firm believer in loading ONLY what you will use in the page you are viewing. Most people develop one functions file and just call it on every page... sure you will have common functions, but the ones that aren't common... why load them?

Thats why when you use an open source program/script w/e... its bulky. They develop it for EVERYONE and EVERY situation. Will you use every situation? Probably not, but when you don't have time to develop something solid for every situation for you, well you take what's next in line. Smarty is fast and I think its works excellent for me. Will I ever develop my own? Your damn skippy! :)

bowser1111
04-01-2007, 02:15 AM
Yeah, I would have to agree with that. I like to write my own functions for the same reason. But is that what Smarty is doing? The basic functionality (Smarty.class. -- whatever that first one is you call) requires 250k? Also, although I'm sure we're all sensitive to these kind of "load times" due to the nature of the internet, somehow it seems that loading a mere 250k server-side is probably negligible.


sure you will have common functions, but the ones that aren't common... why load them? ... Thats why when you use an open source program/script w/e... its bulky. They develop it for EVERYONE and EVERY situation...

I'm not sure what this has to do with an API being open source (I usually find open source applications to be much more robust and lightweight compared to commercial ones), but point well taken.

iLLin
04-01-2007, 03:14 AM
I wasnt comparing to commercial, I was comparing to an app you built for the site your building. And I'm not sure what the actual file size is and yes it happens server side. But as I said yea you prolly won't notice but every little bit helps IMO :)

bowser1111
04-01-2007, 07:30 AM
Yeah I know what you mean.

But for every time I get a sneaking suspicion that something is wasting resources I also have another time when I get a similar sneaking suspicion that I'm being nitpicky about something that doesn't even come close to affecting performance. That's the problem with computers in general... it's hard to even know what scale they're working from.

Mhtml
04-01-2007, 08:43 AM
Just some food for thought here, but why use Smarty? I'm a big advocate for PHP as a template engine.

Smarty compiles your templates into PHP code. So basically you are writing your business logic in one language, your presentation logic in another which is then ultimately converted into the same language as your business logic anyway. Cut out the middleman people, use object oriented PHP right from the get-go and avoid anything unnecessary.

The idea behind Smarty is to separate your business logic from your presentation logic. And this is a great idea, if you want to write something scalable and configurable it is really the only way to go. But the system is just redundant and illogical. We're already presented with a perfectly good template system in PHP itself and there is no need to obfuscate it.

Most people wield the argument that Smarty is safe. It prevents template designers from writing naughty code. Of course the argument against that in-turn is why are you letting someone you don't trust write your templates and why aren't you inspecting your template code? If you run a simple text search over all the template files for things like eval() or mysql_query for example. You can pretty well sniff out if anything suss is going on. Of course it still stands to reason that you should be keeping anyone you don't trust at distance from your code with a 40ft clown pole.

Some people seem to think that the syntax is much easier for non-programming folk to pick up. Again, why are you letting these people anywhere near your site if they can't grasp basic PHP. Given an arbitrary template file you shouldn't really find anything more than output of variable values as well as conditional and iteration constructs. Now I'm pretty sure that if someone can grasp standards compliant XHTML and CSS they can definitely manage to understand if, else, switch and foreach. You may also want to separate your templates even more into individual mini-templates which you will include all over the place. PHP provides a handy construct for that too: include(). Fancy that. And if your template designer can't manage that then we need to bring that clown pole back into the picture because they should be nowhere near your site's code. I don't think Smarty really achieves anything by obfuscating PHP through it's compiling system. It is purely a waste of time and effort.

Additionally Smarty provides all sorts of useful little utilities and functions to help with modifying data to fit into your presentation how you see fit. But as was said it's bloated you probably don't need half the crap, I'll explain a little later on in my post how going straight for PHP allows you to avoid this issue but still have every last one of your helpers at your disposal should you so choose.

On a slightly positive note, Smarty does provide an object oriented interface to dealing with your templates. This is of course fantastic, we love object oriented code don't we? Anyone who is shaking their head needs a wallop with my clown pole, get with the program: procedural code has it's place but we are in the realm of object oriented design in this context and to say otherwise is foolish, you are just making this more difficult for yourself and anyone who has to maintain your code in the future. But even Smarty doesn't go far enough in that respect, you'll see my perspective on template objects further down this post.

Any benefits of Smarty are trivial at best. PHP provides the perfect interface so why obfuscate it? Remembering that funky little Smarty language which eventually gets compiled into PHP anyway is just illogical. Why make things more complicated to make them seem simpler?

In essence for an application all we need to do is separate our presentation logic from our business logic. If you're designing a reasonable sized application, say a blog (as opposed to maybe a contact form), you'll probably end up implementing the Model View Controller pattern (http://en.wikipedia.org/wiki/Model-view-controller) (MVC). So your application handles data requests and whatnot and renders a view which it builds from template files. It's not amazingly complicated and with a reasonable grasp of object oriented PHP you can create a lightning fast no-middleman system to render the view. It's more workable than Smarty.

Right now you might be thinking: "Well duh... but that sounds really complicated"! I say you couldn't be further from the truth.


class View{
public $vars = array();

public function render($filename){
extract($this->vars);
include($filename);
}
}Bam. Instant template class. Of course that is a really dirty example. But from this you can see the basic idea here. We just include() the template file, pretty damn simple. You'll notice extract() in there too. As per the manual, this function imports variables from an associative array into the current symbol table. Or in less words, it takes array('foo' => 'bar') and makes $foo = 'bar'.

The included template file, containing PHP embedded in markup (or perhaps something else other than markup) inherits the variable scope of the render() function. That is to say that the template only has access to those variables that we just extracted, nifty.

But what about on the template side of things? Embedding PHP into your markup can get very overwhelming as your templates grow and if you're not careful then you are likely to end up with soup. I see a lot of code like this:



<?php if($results){?>
<table>
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<?php while($row = mysql_fetch_assoc($result)){?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['age'];?></td>
</tr>
<?php }?>
</table>
<?php }else{?>
<p>There were results to display.</p>
<?php }?>
Now once your templates are full of crap like that it gets so cluttered that you can barely see what the hell is going on, especially when your templates get quite large and you have massive data sets to deal with.

But, we can do better! There are a few nifty little features of PHP that are often overlooked in these sort of scenarios. Most servers will have short_open_tag enabled, combine this with the alternative syntax for the control structure constructs and we can clean this up a little:



<?if($results):?>
<table>
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<?while($row = mysql_fetch_assoc($result)):?>
<tr>
<td><?=$row['name']?></td>
<td><?=$row['age']?></td>
</tr>
<?endwhile?>
</table>
<?else:?>
<p>There were no results to display.</p>
<?endif?>
As you can see it becomes quite obvious what is going on without all those braces everywhere, and by slimming down the PHP delimiters the markup is much easier to read. I think that is perfectly acceptable for a template, and as I said earlier on you can make use of the include() construct to import other template chunks, they'll even inherit the variable scope.



<div>
<?if($user):?>
<h3><?=$user->name?></h3>
<div>
<?include("lastPosts.php")?>
</div>
<?endif?>
</div>
Not too shabby. It's quite obvious what is going on, and it's a pure PHP language construct so it's fast.

Here is a quick, slightly less dirty example view class. This is based on what I actually use in my PHP MVC application framework.

class View{
//global variables (all new View will have these)
private static $_global = array();

//private variables, only visible in this instance
private $_vars = array();

//content buffer for parsed template
private $_buffer = null;

//filename of the template
private $_filename = null;

//constructor. if given a filename it will load() the file. $vars sets the private vars
public function __construct($filename=null, array $vars=null){
if(!empty($filename)){
$this->load($filename);
}
if(!empty($vars)){
$this->_vars = $vars;
}
}

//overload magic __set method to allow setting of private vars as $view->foo = 5;
public function __set($key, $value){
return $this->assign($key, $value);
}

//overload magic __get method to allow getting of private var values as $x = $view->foo;
public function __get($key){
return $this->value($key);
}

//overload magic __isset method to allow isset($view->foo) of private vars
public function __isset($key){
return isset($this->_vars[$key]);
}

//overload magic __unset method to allow unset($view->foo) of private vars
public function __unset($key){
unset($this->_vars[$key]);
}

//checks if a variable has been assign()ed. global as true searches for global vars, private if false
public function assigned($key=null, $global=false){
$a = null;
if($global){
$a = &self::$_global;
}else{
$a = &$this->_vars;
}
return array_key_exists($key, $a);
}

//assign a variable to the template. key = value. if global is true, it is set as a global for all View instances
public function assign($key=null, $value=null, $global=false){
if(empty($key)){
throw new Exception("Expecting key as first argument, received empty() string.");
}
$a = null;
if($global){
$a = &self::$_global;
}else{
$a = &$this->_vars;
}
return $a[$key] = $value;
}

//returns the value of a given key if it exists
public function value($key, $global=false){
if(!array_key_exists($key, $this->_vars)){
throw new Exception("No such key '$key', has been assigned in this view.");
}
$a = null;
if($global){
$a = &self::$_global;
}else{
$a = &$this->_vars;
}
return $a[$key];
}

//*loads* the template (basically just makes certain it exists and sets the internal filename reference)
public function load($filename=null){
if(empty($filename)){
throw new Exception("Expecting filename as first argument, received empty() string.");
}
$filename = "views/$filename";
if(!file_exists($filename)){
return false;
}
$this->_filename = $filename;
return true;
}

//determines is a template has been *loaded*
public function loaded(){
if($this->_filename){
return true;
}
return false;
}

//imports variables into scope and includes the template
private function _import(){
$eOld = error_reporting(error_reporting()^E_NOTICE);
extract(self::$_global);
extract($this->_vars);
include($this->_filename);
error_reporting($eOld);
}

//sets up buffering and parses the template ready for output or saving/sending whatever you want (returns buffer length)
public function render($output=false){
if(empty($this->_filename)){
throw new Exception("No file has been loaded.");
}
ob_start();
$this->_import();
$this->_buffer = ob_get_contents();
ob_end_clean();
if($output && $this->_buffer){
return $this->output();
}
return strlen($this->_buffer);
}

//dumps the buffer (returns buffer length)
public function output(){
if($this->_buffer){
echo $this->_buffer;
}
return strlen($this->_buffer);
}

//returns the buffer
public function contents(){
return $this->_buffer;
}

}
Again this is just quick and dirty example but it should work fine. Have a tinker with it, rewrite it and integrate it into your own framework. That's what, probably about say 3 or 4kb?

In terms of using it, it's quite simple:


//create a view instance using foo.php (views/foo.php)
$view = new View("foo.php");
//set a private/local variable for this instance
$view->foo = "The cat sat on the mat, the mat is now flat.";
//set a global variable (all new View() will have this!)
$view->assign('name', "bob", true);
//render the view
$view->render();
//output to the browser
$view->output();
How you use it in the end is up to you, I automate it. Because I have a really modular MVC framework, my application singleton automatically renders views/$controller/$action.php once execution of $controller->$action has completed (unless told otherwise of course). Site wide $config is set as a global right after the bootstrap so any view instances receive the data.

Then build up little utilities as you need them. I prefer to create static helper classes, like (another dirty example):


class Text{
public static function limitWords($str, $n){
$matches = null;
preg_match("/([^ ]+\s){0,$n}/", $str, $matches);
return $matches[0];
}
}

class Xhtml{
public static function paragraphs($str){
str_replace("\n\n", "\r\n\r\n", $str);
return "<p>".str_replace("\r\n\r\n", "</p>\n<p>", trim($str)."</p>\n";
}
}
And use them in templates like so:


<?foreach($latestEntries as $entry):?>
<div>
<h3><?=$entry['title']?></h3>
<?=Xhtml::paragraphs(Text::limitWords($entry['body']), $config['entries']['previewLimit'])?>
</div>
<?endforeach?>

Thats why when you use an open source program/script w/e... its bulky. They develop it for EVERYONE and EVERY situation. Will you use every situation? Probably not
I don't worry too much about overhead with helpers, but if you want to keep things lean and mean (and avoid the bloat like you would have in Smarty or similar) because you're using PHP as your template system then you have the advantage of either require_once(), __autoload() or even a singleton class to manage loading on request.

Example __autoload()


function __autoload($class){
if(file_exists("helpers/$class.php")){
require_once("helpers/$class.php");
}
}
Or a little manager type thing:


class Helper{
public function __get($helper){
if(!class_exists($helper)){
$helperfile = strtolower($helper);
if(file_exists("helpers/$helperfile.php")){
require_once("helpers/$helperfile.php");
}else{
throw new Exception("Unable to load helper '$helper'.");
}
}
return new $helper;
}
}
Hopefully something in all that rambling and quickly hacked together code made sense.

Nb: All the code is untested and just off the top of my head so forgive me if I made a few errors. So long as you get the general idea.

bowser1111
04-01-2007, 10:00 AM
That was _great_ .

I need to spend a day or two analyzing all that, but you basically managed to answer about 200 questions I had slinking around in the back of my head without me even being able to verbalize them.

I especially love the alternate syntax idea... very readable.
Thanks a bunch!

iLLin
04-01-2007, 03:40 PM
I don't advice using shorthand. Not all servers have this enabled and if you ever build a site on your server and move it to a clients server and they don't have access, refuse, w/e the reason to enable short hand for you... Lots of changes. And then to tell you client, well you have to enable this for my site to work, is just bad business.

But that is my opinion and I'm sure you will have others that disagree.

Also which is easier and looks cleaner?


//shorthand
<?=$row['this_field']?>

//correct php
<?php echo $row['this_field']; ?>

//template engine
{$this_field}

You decide.

firepages
04-01-2007, 04:06 PM
I agreed with your post up to and including this line ...

I'm a big advocate for PHP as a template engine

but then you show templates like ...
.................................
<?foreach($latestEntries as $entry):?>
.....
<?endforeach?>
......................................

..ok my example would be little different on some levels....


{{ITERATE=ENTRIES}
<div class="{CONTEXT}">
<h3>{TITLE}</h3>
<div>
If {DESIGNER_NAME} gets this wrong , It won't break my page<br />
</div>
<div class="{CONTEXT}_sub">{AUTHOR}</div>
</div>
{/ITERATE}}


but using Text::limitWords($entry['body']) in your example negates the point of using templates by bringing your application logic into the equation (what if you change your db structure (or more likely try to reuse this template) where $entry['body'] is invalid ?
the foreach() can be considered presentation logic, the rest less so.

e.g. {DESIGNER_NAME} does not care where its data comes from & its value can be decided (and more importantly changed) in the model, so if we decide to use "$name $surname" as the designer name instead of just "$name" then we alter the model and not the template (and all the other templates that talk about {DESIGNER_NAME})

..................................

I do not see MVC as valid in the stateless web, at least not in the JAVA implementation (see my sig) , but keeping markup out of your classes and functions is (in the long run) 100 times more valuable than I ever imagined it could be and templating is simply the simplest way to do this (and can be quite efficient depending on the implementation Smarty for instance has excellent caching features)

...but.... keeping markup out of your business logic is pointless if you then move your business logic into your markup... its a tightrope walk ;)

firepages
04-01-2007, 04:11 PM
Also which is easier and looks cleaner?
honestly .. ? to me shorthand looks and feels cleaner (of the 2 pure PHP examples)

I have also yet to find a host with short tags disabled (though I am sure someone can find me one somewhere) nor do I see the point of disabling them... nor do I understand why PHP keeps recommending they should be disabled yet still shipping with them turned on ?

Mhtml
04-01-2007, 06:04 PM
but using Text::limitWords($entry['body']) in your example negates the point of using templates by bringing your application logic into the equation (what if you change your db structure (or more likely try to reuse this template) where $entry['body'] is invalid ?Oh of course, I wrote those just as pure examples of using the language constructs. More like nonsense code just for an easy demonstration not a adequate depiction of perfect structure and scheme. My models are all derived from a dynamic base class, they support field-member mapping (to as many members as you want even) and this is what my templates expect.

I didn't mean those dirty little examples to be taken as gosphel. The main substance of my post is the view class and my anti-smarty argument.

Also, I was really hung-over: Had to go chuck twice before I finished writing that... I'll never drink again. :rolleyes:


I don't advice using shorthand. Not all servers have this enabled and if you ever build a site on your server and move it to a clients server and they don't have access, refuse, w/e the reason to enable short hand for you... Lots of changes. And then to tell you client, well you have to enable this for my site to work, is just bad business.And of course I disagree, I am yet to find a host that doesn't have short_open_tag enabled
and it's enabled by default. Even less servers support PHP5 than servers that have short_open_tag enabled, so I should probably not use that either? ;)


I do not see MVC as valid in the stateless webThat's a pretty common argument. Also one that I just ignore lol. I like the way my framework is set out and works. A lot of people also don't like mod_rewrite, I say to hell with them I think being able to create an entire section of my application using a single class and mapping that to a section and subsection members through a nicely formatted URI is awesome.


I agreed with your post up to and including this line ...


I'm a big advocate for PHP as a template engineAre you saying that's all you agreed with? 2am in the morning I just didn't get it :o.

ralph l mayo
04-02-2007, 09:23 AM
If you really feel compelled to take architecture advice from the guy responsible for inflicting the "Personal Home Page" layer on Perl:



I don't have much of a problem with MVC itself. It's the framework baggage that usually comes along with it that I avoid. Parts of frameworks can be useful as long as you can separate the parts out that you need. As for MVC, if you use it carefully, it can be useful in a web application. Just make sure you avoid the temptation of creating a single monolithic controller.


Although personally I can't testify to the strength of that temptation b/c it's a prima facie stupid idea.

Quote, and some example code I wouldn't want to have to maintain here (http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html).

aedrin
04-02-2007, 05:16 PM
Everyone seems to be searching for the holy grail.

It is right there sitting under their nose.

For you see, as the topic starter mentioned, there is not one best way. This is a pretty cliche answer. But it happens to be true.

Smarty is quite useful to some people. I'm pretty sure it is bloated and trying to fix a problem inside there is hopeless. But it is still useful to some people because they're not at a level where they can build their own system. And it is a common interface. One thing many forget is that when everyone tries to create their own language, you are reducing the maintainability of the code.

Other people like to build their own, which is fine. It's actually a great learning experience, and you can get quite advanced while staying lean. Not to mention that it is much easier finding an issue in there, because you wrote it. And if you need that feature Y, you can add it in. No playing around with special codes and tricks to get it to work.

As you can see, to each his own. I do prefer my own template system, although it needs a lot of work. Code always needs a lot of work. Smarty is a great system (the idea of converting to PHP is pretty neat), but you are introducing yet another language. Another set of codes to learn. Some people already work with too many languages, so having another one is just not helpful.

I don't work with template designers, I have never come across one. I built a framework. I upgrade it every time I create a new site. And this works for me. As was pointed out before, if someone can grasp XHTML and CSS, they won't have a problem using PHP.

But if you want a proper template language, look at XSL. It's a standard and once you understand how it works, it can be quite powerful. PHP even provides methods for you to hook it into your own code.

Take a look some time at a PEAR class. You will see some really clean code (formatting, naming, etc.). But, then you notice how big the files are, how much lines of code are used to do something simple. And you realize that trying to create the holy grail is not worth it.

At least not until PHP6. Because with caching, bloat becomes less of a problem. And then you can really use PHP to do object oriented programming. Which right now is not possible (at least not for anything high performance). The most you can manage at the moment is a mix of procedural and object oriented.


If you really feel compelled to take architecture advice from the guy responsible for inflicting the "Personal Home Page" layer on Perl:

Isn't this a bad thing to say in a PHP forum? (insulting the creator of PHP)

bowser1111
04-02-2007, 07:15 PM
As was pointed out before, if someone can grasp XHTML and CSS, they won't have a problem using PHP.

Geez, only a natural born coder would ever say this... XHTML and CSS aren't even REMOTELY like PHP. Not to mention that if you're going to even try to tackle a programming language, let alone an object oriented one, PHP leans more to the "confusing as all holy hell" side, syntax-wise.

aedrin
04-02-2007, 08:57 PM
XHTML and CSS aren't even REMOTELY like PHP. Not to mention that if you're going to even try to tackle a programming language, let alone an object oriented one, PHP leans more to the "confusing as all holy hell" side, syntax-wise.

1. I didn't imply that they are similar. Merely the fact that the difficulty in grasping XHTML/CSS properly indicates a certain amount of intelligence. Something that would allow you to easily pick up a simple language like PHP.
2. PHP isn't Object Oriented.
3. PHP is actually quite flexible and lenient, so I'd hardly call it confusing.

jmitch18
04-02-2007, 11:58 PM
PHP isn't confusing :P

But I would like to see it support objects more.

firepages
04-03-2007, 12:42 AM
Are you saying that's all you agreed with?

:) not at all, its just that the example you gave (or the example as I understood it) seemed little different from a templating engine as an argument against templating engines.

Smarty is far more clever than it looks... but for me also, far too complex for a PHP templating system., and I would agree with most of what Aedrin said about smarty (which I think is what Mhtml was saying minus the hangover;)) ...though I do not think it is 'bloated' in the traditional sense.


..blasphemy removed ;)
as for Rasmus ... I think you have to look at more than one snippet of his train of thought to get to grips with where he is at, & he is at a place that accepts the limitations of an interpreted language.

As noted given most tasks he might prefer to write them procedurally .. something I stray away from now but I still sometimes think to myself ... `I could have finished this yesterday if I had just written some procedural code` ... unmaintainable code perhaps but just as fast to rewrite it if required (and for many projects thats rarely the case)


But I would like to see it support objects more
I think PHP5 has all the object support it really needs ? only JAVA heads are really bothered about Namespacing and Multiple Inheritance, again remember this is an Interpreted language we really do not need to load a giant class hierarchy & I for one do not need MI, in fact all I really needed in PHP5 was the internals sorted out (copies and references) dereferencing + I do like interfaces and abstract classes and static variables

bowser1111
04-03-2007, 02:31 AM
1. I didn't imply that they are similar. Merely the fact that the difficulty in grasping XHTML/CSS properly indicates a certain amount of intelligence. Something that would allow you to easily pick up a simple language like PHP.

Yeah but here's the thing: Markup language is just "tagging" stuff and css is just telling the tags what to look like. That's a very simple concept to grasp, no matter how many tags there are or how complicated the attributes get. Programming, whether it is PHP, Javascript, or any other language, is about telling the computer to do stuff, which is on very fundamental level much more complicated. It's like trying to learn Swahili when all your friends know Spanish. Sure it's a simple language in retrospect, but not when you're trying to pick up a grammar system and word order that's completely new to you.



2. PHP isn't Object Oriented.

Um, which PHP are you referring to? The one I use is very much object oriented.


3. PHP is actually quite flexible and lenient, so I'd hardly call it confusing.

Maybe, but nevertheless PHP's syntax looks like someone chewed up an ASCII table and coughed it out all over the screen.

firepages
04-03-2007, 03:00 AM
Maybe, but nevertheless PHP's syntax looks like someone chewed up an ASCII table and coughed it out all over the screen.

no , I think you are thinking of PERL ;)

bowser1111
04-03-2007, 05:10 AM
ahaha... that's why I didn't go all out and say that PHP was the MOST confusing ... at least not compared to PERL (a.k.a. "Sea of Hash Marks").

aedrin
04-03-2007, 03:37 PM
again remember this is an Interpreted language

Java is an interpreted language.


Um, which PHP are you referring to? The one I use is very much object oriented.

PHP has some object oriented programming features (admittedly getting stronger), but is still a procedural language. The execution starts at the top of the script, and finishes at the bottom.

And in its current state, this is what it is most effective at. A short script that does what it needs to. In Java you can build a giant framework, and it'll run pretty decent. But that's because the code resides in memory between requests. It's an object handling requests, instead of a request handling objects.

I even saw Rasmus say it somewhere (thought it was the topic mentioned earlier by ralph | mayo).

firepages
04-03-2007, 04:52 PM
Java is an interpreted language.

Personally I would agree, in that `compiled` java byte code is run by the JVM (after initial interpretation) but most JAVA heads will tell you its compiled (as will .NET heads of .NET) , of course you can put a bytecode cache on PHP for essentially the same deal.


The execution starts at the top of the script, and finishes at the bottom. that does not really mean anything, all code is written that way, it is how it is interpreted that makes it one or the other (or both ;))
<?php
include 'everything'
main();
?>
PHP can be used procedurally or in an OO fashion (perhaps not OO enough for many but OO non the less)

JohnDubya
04-03-2007, 04:58 PM
<-- head explodes

:D

You guys are smart.

iLLin
04-03-2007, 05:03 PM
Yea makes for good reading :)

bowser1111
04-03-2007, 06:46 PM
You guys are smart.

Yeah, a little too smart, I think. Let me see if I can put this into terms that you two knuckleheads will understand.

You guys are like two private static functions that exist inside a class called "Object Oriented Languages" (and don't even give me bs about the spaces). You're continually calling each other and re-assigning each others' variables: PHP is object-oriented, PHP isn't object-oriented...Java is, Java isn't... tomatos...tomatoes....

However, for everyone else out there who still thinks "object-oriented" refers to some kind of odd sexual fetish, you guys don't even exist within the same scope. They can't see the variables you're assigning, they can't even see the public functions...access denied. All they see is some big wrapper called a "class" (class?? I used to have those before I dropped out). They don't know what it's for, don't know what it is...can't call the functions...can't use the variables. To them, whether or not PHP is truly object-oriented just amounts to another variable whose value they can't see in the first place. The only way they'll be able to see it is to go in through the constructor so they can become an instance, or I dunno, something like that...whatever, this metaphor is already stretched pretty thin.

The point is that even if PHP really can't be called object-oriented, it won't help anyone trying to learn it one whit. They'll still go through the code, see something called a "class" and be baffled (if they weren't already by the procedural code). If anything, it'll make it all the more confusing when one of you goofballs comes along, slaps them over the head with a wet noodle and tells them NO, the language you just spent all this time learning isn't actually object-oriented.

aedrin
04-03-2007, 06:49 PM
as will .NET heads of .NET

Actually, I'm an ardent fan of .NET and I will tell you that .NET is interpreted too. As long as the executable is not machine code, it is interpreted. Because another process at run time has to translate 1 format to machine code. The key words being 'at run time'.


that does not really mean anything, all code is written that way, it is how it is interpreted that makes it one or the other (or both )

Tell a 'java head' or '.net head' that their code starts at line 1 and they will explode ;) Truth being that indeed, all applications are procedural/linear. As machine code is that way. So the seperation lies in the implementation of the language.

The base for each .NET/Java application starts in an object, with an entry method. The base is an object, hence it being object oriented.

PHP - although offering objects - uses them as a tool. It can use them to describe data, but itself is still a procedural language.

For instance, JSP can be considered object oriented. Even though you write a linear page, it is then compiled into a class with one or more methods to handle the request.

The only debatable fact here is how much OO is enough to call something object oriented. ;) In my opinion it's all about how the language handles its base application. Whether objects are the origin of everything in the language, or whether they are helpers.

PHP - Object Assisted Programming? ;)

aedrin
04-03-2007, 06:52 PM
bowser1111:

You poked the sleeping bear. Be prepared for its wrath :P

All discussions aside. You are correct, it doesn't help anyone.

As always, we return to the most basic rule of programming: KISS.

Apply that, and you will prosper.

iLLin
04-03-2007, 06:54 PM
bowser1111:

You poked the sleeping bear. Be prepared for its wrath :P

All discussions aside. You are correct, it doesn't help anyone.

As always, we return to the most basic rule of programming: KISS.

Apply that, and you will prosper.

I agree with that me being a simple person and all :)

firepages
04-04-2007, 02:27 AM
Whether objects are the origin of everything in the language, or whether they are helpers and thats why I love PHP its anything you want it to be

knuckleheads I have been called all sorts of things in my life & most of them won't get past the filter here ... but thats a first :)

bowser1111
04-04-2007, 03:19 AM
I have been called all sorts of things in my life & most of them won't get past the filter here ... but thats a first

I know... I didn't even mean it... I just thought it would be funny. :)

I actually just wrote my first PHP class the other day (yay!!!.............gay) and I have to agree, PHP is pretty simple... Combined with the things you can do, I'm starting to get into it, although I still say the syntax is ugly, not to mention the makers have the worst sense for naming since the parents of Bonnie Butt, a girl I knew in high school (yes, that's real).

I just wanted to point out that any programming language is so fundamentally different from XHTML/CSS in what it does, and how it goes about doing it, that I can envision a lot of people giving up on the spot. And I can certainly relate. The first time I heard about "private static" variables in my first CS class in college, I threw up my hands and said "that's it... I'm outta here". Of course at the time I basically thought the extent of Java was for making tic-tac-toe games like the one they had me working on all semester. But that's just the point... for a web designer there's so little return for how complicated it is. Why go to all that trouble when I can just slap a few HTML pages together in Dreamweaver?

I mean, quantum physics is probably pretty simple to a quantum physicist, but that doesn't mean I'm gonna run out there and grab a "for dummies" book anytime soon.

aedrin
04-04-2007, 04:08 PM
tic-tac-toe games like the one they had me working on all semester

I still don't understand why they don't come up with more interesting things to work on. They must assume that everyone wants to play tic tac toe.

When I had a class that had something similar (four in a row) we quickly made it and then started adding AI. Then squared them off against each other, now that was fun :P


Why go to all that trouble when I can just slap a few HTML pages together in Dreamweaver?

To me, all I have to do is look at the source code of what Dreamweaver produces. That's enough for me.

JohnDubya
04-04-2007, 04:19 PM
Just do what I do...don't take classes for stuff. Just teach yourself. Then, you can make whatever the crap you want! lol I taught myself HTML, a little Javascript, and now PHP/MySQL. When we got the internet at my house back in about 1996, I immediately started wondering how web pages were made. I found some simple HTML tutorials and started pounding away at the keys. And at the end of last year, I heard about a job in my area to be a PHP/MySQL programmer, so I taught myself how to interact with databases, and started doing it. Anyway, all that to say, if you teach yourself, you can practice on whatever project you want...so you don't have to build a tic-tac-toe game! :D

iLLin
04-04-2007, 04:25 PM
To me, all I have to do is look at the source code of what Dreamweaver produces. That's enough for me.

Yea I use cuteftp for my client and it as a text editor in there. Thats all I use. I couldn't stand dreamweaver or frontpage to do anything right. They surround every word with font tags it seems LOL. I take over lots of websites that they want upgraded. I clear more code out then I put in. Its ridiculous...

aedrin
04-04-2007, 04:25 PM
Just do what I do...don't take classes for stuff. Just teach yourself.

All programming classes I have been in, I was already way past the level of teaching. This is a problem with fixed format classes.

I don't even buy books, because there is enough free information out there to figure it out yourself.

But this seperates those who enjoy programming, and those who do it for a job.

Only those who enjoy it would go out and find something more to learn.

NancyJ
04-04-2007, 04:32 PM
Wow, this thread really took off - what amuses me most is that no matter which side of the argument you're on, you all seem to view procedural and OO as mutual exclusive concepts. Procedural and OO are not opposing forces. Just because code runs from line 1 til it gets to the end does not mean that it cant do so using objects.
C++ is an object oriented language, I doubt there are many that would debate that, it is at least in part - procedural, in fact you could write a c++ program that was entirely procedural, that wouldnt make the language any less OO.

PHP can never (at least with current web technology) be event driven but that doesnt make it any less object oriented - if the programmer chooses to build an program that is entirely object based. The only real difference is that PHP doesn t have a built in 'event listener'

iLLin
04-04-2007, 04:36 PM
All programming classes I have been in, I was already way past the level of teaching. This is a problem with fixed format classes.

I don't even buy books, because there is enough free information out there to figure it out yourself.

But this seperates those who enjoy programming, and those who do it for a job.

Only those who enjoy it would go out and find something more to learn.

No books eh? Well I am self taught so I sometimes make things more complicated than they need be because I never knew of a simple solution. I picked up the SAM's "teach yourself" book for php,mysql, and apache and finally learned arrays LOL. I never understood the foreach for the longest time... I just used it. THEN I didn't even know about the whole $array as $key => $value till I got that book. Thats just one simple thing I never grasped until I got that book. I don't use it anymore now but it filled a lot of simple holes I missed while taking others work destroying it and making it my own. Now I can build my own apps. But I never took a class, I just can't stand school, but I enjoy learning :confused:

JohnDubya
04-04-2007, 04:46 PM
Illin, very true. That is also a problem I have run into with being a self-taught programmer: there are a lot of basics that I don't learn until much later because I didn't know they were important. Many things confuse me that should be basic, and that I would probably learn in a formal training course. I actually took my first formal training course for HTML and CSS last year, and I learned a ton and got a really good foundation to build off of even more, even though I knew 75% of the stuff already. That's what's good about classes is that they give you the complete basics, and THEN you can build off of those.

NancyJ
04-04-2007, 04:48 PM
I buy books, I buy books all the time - never read them. I just dont have the patience they all go too slow and I get bored. The best way to learn is to do. The only book I've really found useful is my RoR book because theres sod all out there in terms of decent web resources for RoR - especially if you dont know ruby but I'm really enjoying it. Its really a liberating programming experience, shame it has little practical value.

aedrin
04-04-2007, 06:01 PM
For PHP, all the information you would ever need is in the documentation.

Every now and then I come across a new topic, I look it up in the documentation and read that.

The biggest benefit from being self taught is that your creativity is much higher. In a class you are taught - Problem X can be solved by Solution Y.

While as you're struggling by yourself, you'll figure out Solution Z.

Programming is about being able to solve a problem. Not knowing this little trick that reduces the time to code something doesn't make it easier to solve. It just makes it quicker.

So although basics are important, you need to be able to go past them.

I do too come across things that seem relatively basic that I didn't know. But did it make it harder for me to create what I had made before? Not really. I just did it differently.

iLLin
04-04-2007, 06:08 PM
Yea I hear ya on that as I like to call myself "resourceful". But when I create a function to do what another php function already does...

For example look at this post
http://www.codingforums.com/showpost.php?p=553548&postcount=7

I think I have made that exact same function when I needed to convert single digits for months because I didn't know about the str_pos function. Simple stuff like that I run a crossed from time to time. And I'm sure every coder comes across this. I doubt someone can build a web app from ground up and never have to update it cause it was wrote perfectly. Did it slow me down? Maybe a little as I try to find the best methods. Did it prevent me from accomplishing my goal? No way. Will it happen again? YOU BET! But I love what I do and I strive on different and better ways all the time. I read just about every post you put up aedrin (and a few others) as I think you know what the hell your talking about :p. I love to learn

JohnDubya
04-04-2007, 06:14 PM
There actually haven't been a ton of things I've done "wrong" while coding...like you guys said, it's more that I've been finding easier and more efficient ways to do things. I used to always use if() for everything, but now, I try to use switch() whenever I can. I've been learning how to use arrays more effectively, which is helping make my programming more well-rounded. One thing I'm really struggling through is making my scripts and programs more secure. I want to make sure my users are safe when they use my site, and it's hard to cover every base.

iLLin
04-04-2007, 06:33 PM
Yea someone should start a thread about best php security practices. That would be real good info!

aedrin
04-04-2007, 07:51 PM
I think I have made that exact same function when I needed to convert single digits for months because I didn't know about the str_pos function

When I started learning PHP I already knew Basic, C, Pascal and some assembly.

So I whenever I was trying something I would just look for the equivalent. One you know your first programming language, the next one becomes twice as easy to learn.

This is why they should emphasize on programming basics, not languages, in classes. Which is why some of the more advanced classes don't use any of the newer languages, but instead use something such as Lisp. So when a programming class uses Java, PHP, Ruby or [insert new language], beware. ;)

aedrin
04-04-2007, 07:53 PM
I read just about every post you put up aedrin (and a few others) as I think you know what the hell your talking about . I love to learn

That's what makes a great programmer. Loving to learn.

One of the reasons I post here is to stretch my knowledge past what I use.

I've picked up quite a few things already by helping others and figuring out their problem.

And thanks :P I don't always feel very competent, mainly because I know I can always improve on what I do.

JohnDubya
04-04-2007, 07:54 PM
So when a programming class uses Java, PHP, Ruby or [insert new language], beware. ;)

You mean when a beginner programming class uses one of those, right? If the class started with one language only, it wouldn't be wise.

JohnDubya
04-04-2007, 07:57 PM
And thanks :P I don't always feel very competent, mainly because I know I can always improve on what I do.

FWIW, I've noticed how competent you are and enjoy your posts. Very informative and helpful. Thanks for your insight! :thumbsup:

aedrin
04-04-2007, 07:58 PM
That's right, I forgot to include beginner's, or introductory might have worked too.

Yeah, a class aimed at learning a specific language should obviously be fine. ;)

But if you're learning the basics of programming, you're best off with the simplest of programming languages.

JohnDubya
04-04-2007, 08:01 PM
But if you're learning the basics of programming, you're best off with the simplest of programming languages.

Agreed. I started off learning the basics of syntax by learning from two different languages at the same time. I went through some basic tutorials on Javascript and Perl, and that gave me a really good start on the basics of programming. When I came to PHP, it was cake to learn. Other than multi-dimensional arrays...AHHHHH!! lol

aedrin
04-04-2007, 08:03 PM
I remember when I had to go through 2 beginner's programming classes. The first one taught Pascal, then the semester after that they taught C++. That was quite a waste of time for most people there.

I was fortunate enough to already know everything they were trying to teach, so I was able to play around with pet projects. ;)

iLLin
04-04-2007, 08:06 PM
I learned by hacking up the shopping cart oscommerce. Now I can honestly say I can probably develop a shopping cart better than what they provide. :)

but as JohnDubya said, still need to get "solid" with security. Start that thread John!

JohnDubya
04-04-2007, 08:10 PM
Will do. :)

ralph l mayo
04-05-2007, 04:46 AM
I buy books, I buy books all the time - never read them. I just dont have the patience they all go too slow and I get bored. The best way to learn is to do. The only book I've really found useful is my RoR book because theres sod all out there in terms of decent web resources for RoR - especially if you dont know ruby but I'm really enjoying it. Its really a liberating programming experience, shame it has little practical value.

I hope you're referring to Rails in that last part and not Ruby. I maintain a production web app in Ruby and am finishing up a second and so far it's outperformed PHP and Perl in development time and proved more versatile and scalable. (Distributed Ruby and the elegant inline C mechanism++)

Mhtml
04-05-2007, 03:29 PM
Alrighty I'm back, and seeing as I have a real problem with keeping my mouth shut I'd better throw in my $0.02.


Although personally I can't testify to the strength of that temptation b/c it's a prima facie stupid idea.Cracked me up, classic line. :thumbsup:


Everyone seems to be searching for the holy grail.

It is right there sitting under their nose.

For you see, as the topic starter mentioned, there is not one best way. This is a pretty cliche answer. But it happens to be true.
So very true, it all comes down to the project at hand. Your desired goals, your time and budget and of course experience all play a part in how the code comes together.
iLLin even said it earlier!

They develop it for EVERYONE and EVERY situation.Everyone will always tell you something different when it comes to the "best" way of doing things. But as I said it will depend on your particular project, the best way to do anything will be an amalgam of different approaches tailored with some new ones possibly.


Geez, only a natural born coder would ever say this... XHTML and CSS aren't even REMOTELY like PHP. Not to mention that if you're going to even try to tackle a programming language, let alone an object oriented one, PHP leans more to the "confusing as all holy hell" side, syntax-wise.
My point is just as aedrin's. It is not that they are anything alike, it is that an understanding of one constitutes the ability to handle the other - specifically I was regarding this to basic language constructs. If you can read and comprehend English and have a general understanding of algebra (hopefully everyone here can) then you should have no problem using the very little required to perform logic based data presentation by embedding such PHP into your markup.

Honestly, is it that hard to understand:


$x = 2;
if($x == 2){
//...do something
}else{
//...do something else
}It is just so basic that anyone should realistically be able to pick that up, especially if they understand a meta-language.



Programming, whether it is PHP, Javascript, or any other language, is about telling the computer to do stuff, which is on very fundamental level much more complicated. It's like trying to learn Swahili when all your friends know Spanish. Sure it's a simple language in retrospect, but not when you're trying to pick up a grammar system and word order that's completely new to you.
PHP syntax is simple, I think people who are frustrated trying to learn to program are probably looking at it the wrong way. At the basic level it is hardly anything different to what you would have done in algebra class.
There is very little new to the "grammar system and word order" for anyone who can competently understand English and algebraic expressions. I think the issue is one of paradigms.



The execution starts at the top of the script, and finishes at the bottom.So, C++ isn't object oriented?


int main(int argc, char* argv[]){
return 0;
}Perfect little C++ program. main() of course the procedural entry point for your executable which would then pass off control to perhaps your event driven OO framework for all the world cares and eventually slip out of that to end your program.


Yeah, a little too smart, I think. Let me see if I can put this into terms that you two knuckleheads will understand.

You guys are like two private static functions that exist inside a class called "Object Oriented Languages" (and don't even give me bs about the spaces). You're continually calling each other and re-assigning each others' variables: PHP is object-oriented, PHP isn't object-oriented...Java is, Java isn't... tomatos...tomatoes....

However... [post too long to just spit out entirely]

First thing that came to mind after reading that post...


Barlow: Mayor Quimby, you're well-known, sir, for your lenient stance on
crime. But suppose for a second that your house was ransacked
by thugs, your family tied up in the basement with socks in
their mouths, you try to open the door but there's too much
blood on the knob

Quimby: What is your question?

Barlow: My question is about the budget, sir.
:rolleyes:


Just do what I do...don't take classes for stuff. Just teach yourself.Damn straight, I started way back in '93 and I've never touched a book. As far as I'm concerned self taught programmers are more valuable than textbook educated dummies who've never really been in a realistic development situation. Just because something is supposed to work one way doesn't mean that it always will or even does at all, practical experience in learning to program gives you so much more on so many levels.



PHP can never (at least with current web technology) be event driven
Assuming of course you're using PHP for web development at all ;), it's not limited to only the Internet as a platform...

There's probably more I'd want to comment on but I'm tired, just drove over 5 hours back from University (yay for my 10 day break!) so this probably isn't any better than hungover - hopefully I made some sense.

bowser1111
04-05-2007, 04:22 PM
My point is just as aedrin's. It is not that they are anything alike, it is that an understanding of one constitutes the ability to handle the other

I'd say a basic understanding of math would be a lot more helpful...

You're right of course... if/else statements and basic syntax are simple... it's just that from there it adds up and builds complexity quickly. An if/else statement is one thing, but what about an array? Slightly more complicated (you mean I gotta count from zero?)... and so on and so forth. No one gives up at the first step, it's the little complexities that pile up. That weighed against the return for whoever is involved and it isn't hard at all to picture people getting frustrated with it.

iLLin
04-05-2007, 04:30 PM
Slightly more complicated (you mean I gotta count from zero?)...

I use alphabetical keys :p

Mhtml
04-05-2007, 04:51 PM
Well assuming this is still in the context of the template designer (which is what my original post context was) then if you have a collection of data is is highly likely that you will be repeating over it in a particular place in which case they'd be using foreach instead of vanilla loops. Using objects for other cases to separate several collections of data for abstract use would also ease this, also using objects for individual representations of sets instead of associative arrays makes for only 1 type to really deal with.

JohnDubya
04-05-2007, 06:32 PM
Another thing about being self-taught is that these people seem to be a lot more resourceful in actually going and looking for information on how to do stuff instead of depending on teachers and such to spoon-feed them information. Self-taught people are more likely to go out and find tutorials on how to do something and read the documentation and actually DO the examples and mess around with the code...and, heaven forbid...make changes to the code to see what it does. I've learned the most I've ever learned by taking code snippets I find and changing stuff around just to see what happens.

NancyJ
04-05-2007, 07:17 PM
I hope you're referring to Rails in that last part and not Ruby. I maintain a production web app in Ruby and am finishing up a second and so far it's outperformed PHP and Perl in development time and proved more versatile and scalable. (Distributed Ruby and the elegant inline C mechanism++)

Both! Lets face it, we've got to be at least 3-5 years from Ruby, with or without rails is widely supported by hosting companies. *grumble*
I just wrote a cms for one of my clients and it took days :( and the whole time I was thinking, this would have taken a few hours in rails *sob*
But I'm working on a little project that will hopefully solve all my woes and I can just sit on my own server and play with my RoR projects and leave stinky clients behind muahaha

Mhtml
04-06-2007, 03:30 AM
But I'm working on a little project that will hopefully solve all my woes and I can just sit on my own server and play with my RoR projects and leave stinky clients behind muahaha
Sounds like heaven.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum