Page 1 of 1

continued best-practices for newbies

Posted: Thu Apr 08, 2004 12:05 pm
by cmitcham
i think i lost my original audience on my "best resources to learn php" thread, but i still welcome continuing comments... i forgot to mention in my original list of bad practices how non-seperated my logic is from my presentation. heck, in places, i can go into and out of php four times in one line

so...

let's say a guy realizes he has learned many bad programming practices, like the ones at http://www.calvinmitcham.com/golf.

he signs up for free hosting space at dotgeek, just to re-do his application (golf league records / membership), and open it up for others to have/help. he hopes to discipline himself to learn and use at least:

db abstraction;
seperate logic from presentation;
security / user login authentication;
threaded comments/news on home page;
templates;

well first, he tries to read about db abstraction. he starts to see alot about pear, and that really sounds good, like a standard one set of libraries he can grab and learn. but it's not long before he sees several other abstraction classes with large followings. maybe pear is not the best way... but he decides to ignore others, and focus on pear.

quickly, he finds ther are two abstaraction classes; db, and mdb. how does he decide which one to use? he notices an authentication section, and checks there. again, two classes to choose from.

he turns his studies (i hated school and swore i'd never go back, this is hell) to the template engine. again several choices, but decides to plow on with smartie. this opens up a whale of an argument just on whether to use a template class or not!

he thinks (for the billionth time) about writing classes himself; not to re-invent pear stuff, but to handle the application specific stuff. although i understand that all bicycles have handlebars and wheels (the typical example), the whole oop thing hasn't clicked for me yet. i do put functions in included files for anything i find myself needing more than a couple of times, but i don't see how to make that leap to oop programming.

this re-learning exercise seems not so easy.

Posted: Thu Apr 08, 2004 7:15 pm
by phait
fwiw dude, I am in almost exactly the same position and going through the same angsts that you are (except I like to study and tinker)... ever feel like a pinball in a php coderight machine? :)

I even caught the thread on this board where the heavyweights were discussing the lesser points of PEAR, just as I was starting to learn it... bummer for my enthusiasm!

[rant starting]
does this sound like I'm easily swayed... well yes and no. How many times have I seen articles / tutorials / debates about good coding styles, bad practices etc... you try and follow those recommendations to improve yourself and in the process come across other articles that oppose your current line of study.. :roll:

I also came up from the dirty world of learning html and javascript so I'm not used to the Computer Studies courses way of learning, I guess in part that's why I can find OOP sometimes hard to comprehend and other times a really simply concept. I also struggle on discussing the finer nuances of pointers in C as opposed to Php etc...


from it all, I guess I can say that obviously php's strength is that you can do things in so many ways and because it is being improved all the time there are always better ways to do things each time. The consequence of this is that the docs are often way behind - no ones fault really, who wants to write docs when you can code? so it really any wonder bad practices creep in gradually.

To me, learning php and doing away with bad practices is like growing up - you wanna do everything as fast as possible when you're young and you're not so bothered with the where and whys as long as you're having fun. But as you get older you begin to look for more subtsance to things, quality and satisfaction. Finally, you are able to complete things in an elegant manner (not always fastest but gracefully) and can look back and see how far you truly have developed.
..
..
then you die. ;)

[/rant]

for the record I have done just about every bad practice there is for php and physically cringed everytime I have read about it or seen it discussed in a chat room somewhere at a later date, but hey the world keeps turning. You're not alone mate. :wink:

New line

Posted: Thu Apr 08, 2004 10:59 pm
by mcsteve
I made a super-newbie script that just saves peoples names to a file so that i can check to make sure that theyve gone to the site.(dont ask)
But I have another script that is dependant on the fact that I get new lines in between each username. Here's my code:

$LOGIN = $_REQUEST['log'];
$CHECK = fopen("check.txt", "a+");
$NAME = fwrite($CHECK, "$LOGIN/n");
fclose($CHECK);
I know its not very good but when I check the file, all I get is:
Login1 /n login2 /n login3 /n etc...
Can someone please tell me what im doing wrong?

Posted: Fri Apr 09, 2004 3:26 am
by feyd
\n

Posted: Fri Apr 09, 2004 5:03 am
by patrikG
It seems very much that simply because PHP's roots are very "grassrooty" (i.e. open source and, in addition, usually running on Apache, MySQL) PHP developers do go through the steps you've outlined:
cmitcham wrote:db abstraction;
seperate logic from presentation;
security / user login authentication;
threaded comments/news on home page;
templates;
It's pretty much the learning curve I went through - and something I observe in the PHP programmers I know whose first, 'real' programming language (if you, for the sake of the argument, discount Javascript) was PHP (like me).

Add regular expressions, CMS, shopping cart, CRM, Object Oriented Programming, Design Patterns, other databases, XML, XLS etc. to your list - and it seems very much like this is the way PHP is developing as well.

I've written my own classes for this that and the other while there were perfectly good solutions out there. Why? Because I didn't know how it worked. And I wanted to be able to say: "Mine. I did this. 100%!" It seemed a bit like an apprenticeship to me at the time, but the learning curve is steep.

If you want to learn about object oriented programming with hands-on, real world examples: I can't recommend "The PHP Anthology" by Harry Fuecks too highly. He has the gift of being able to break quite complex and abstract concepts into small, understandable units - and is driven by a real passion for PHP.

P.S.: Moved to General Discussion.