Digital Web Magazine

The web professional's online magazine of choice.

PHPitfalls: Five Beginner Mistakes to Avoid : Comments

By Daryl L. L. Houston

October 6, 2004

Comments

Steve Johnston

October 7, 2004 12:31 AM

This is a pretty lame article. First I find your code messy and ill commented. Second, how on earth is this a must read for anyone but a complete novice?

Michael Ward

October 7, 2004 2:50 AM

Steve, the title of this article is

Daryl

October 7, 2004 4:10 AM

I’m sorry you feel that way, Steve. I understand Digital Web’s looking for more PHP articles. Perhaps you’d be kind enough to submit a better piece?

Mike Randrup

October 7, 2004 4:35 AM

Michael,

This is a useful article. I wish I could have asked my assistant to take a look at this about two weeks ago. He had written quite a few if() statements that were accidentally assigning variables instead of comparing them and he had been spinning his wheels excessively to fix it.

Thanks for your article.

Aaron Wormus

October 7, 2004 6:14 AM

A good solution to the very common (it happens to all of us) comparison vs. assignment problem is to use:

if (‘Aaron’ == $name){...}

instead of:

if ($name == ‘Aaron’){...}

The first example will throw an error if you use = instead of ==, the second one will continue quietly on its way.

I’m a proficient programmer, but I read the article just out of interest, knowing that it was focused at beginners. The formatting of the code does need help, but it’s pretty lame to complain about an article that is focused at beginners.

Jules

October 7, 2004 8:07 AM

I am one of those for whom the article was written and it makes a lot of sense. However, I disagree with the laziness part. For me, I don’t understand the OO features of PHP (or any OO language for that matter) and therefore, I am distrustful of rolled code that uses OO. For that matter, I don’t like to use rolled code unless I can understand what every part of it does and to that end, I am willing to put laziness aside and spend the time combing through the code in an attempt to understand it. I also am leary of the PEAR archive for the same purpose: what does it do? how does it work? does it do what I want it to do? I only need part of module XXX, how do I use just that part?

Where I have failed as a beginner is to understand how to properly use error trapping and I am a bit surprised that this wasn’t covered in the article. I do some basic error trapping but I don’t use the buildin error functions which may or may not be better. I would appreciate some info on that.

Looking forward to more PHP articles.

Daryl

October 7, 2004 9:08 AM

Jules, I was really proposing not so much that you use other people’s code, but that you make sure PHP doesn’t natively offer the functionality you’re jumping through hoops to provide, as in my $_GET array example. If I had done just a little more research before rolling my own, I would have seen that a better method for extracting query string variables already existed native to PHP.

Regarding error trapping, that’s a topic I’d like to write an article on (it’s the next one I’m thinking of writing, in fact — whether Digital Web will accept it for publication or not is a different matter). If you’ve got specific questions or issues, I hope you’ll post them here or email me. Thanks for your feedback.

Ross Olson

October 7, 2004 9:26 AM

Maybe it’s just me, but looking through the article, the code samples were really hard to read. I’m on a laptop so the angle matters, but in any event it was really difficult to follow along with the article. Hey Nick, how’s about lowering the brightness to up the contrast on the [code] [/code] sections?

Nick Finck

October 7, 2004 12:26 PM

Ross: So it’s a brightness thing, not a text size or font face thing? I’ll take a stab at it tonight.

Luke Scammell

October 7, 2004 12:56 PM

Thanks for the article. I’m just starting to look at learning PHP and this will be most useful.

Regarding the code display, on top of it being a bit low contrast I also think it could do with being a touch larger relative to the normal text. I find serif fonts to be quite hard to read on screen when they are that small and I would prefer not to have to have the main text cartoon sized to read the code easily.

Aaron Wormus

October 8, 2004 2:21 AM

Jules, if you have questions about PEAR, drop by #pear on efnet, and I’ll answer any questions you might have.

Using OO packages, especially from a repository as reputable as PEAR saves a whole lot of time. They are not that difficult to use or understand. All code in PEAR is peer reviewed and most of it is pretty high quality, and the PEAR team is dedicated to maintaining all of its packages. So if something exists in PEAR, you would be much better off using that version than trying to roll your own :)

Bryan T

October 8, 2004 3:09 PM

The comparison operator info actually shed some light on a recent stumbling block.
Thanks!

Victor

October 18, 2004 8:23 AM

I found it to be a pretty neat article; as a student of computer science, we get to deal with these error at a very early stage haha.

PS: there is nothing wrong with the formatting, it’s only 3-4 lines of code!!!

Chris Hunt

October 20, 2004 5:33 AM

I think you’ve rather missed the point about Laziness, Impatience and Hubris. Wall was not saying that good programmers tend to be, for example, too lazy to read manuals before starting to code (however true that statement may be :) ). He’s saying that good programmers will want to write one reusable piece of code, rather than the same thing over and over. That’s “laziness” as a good thing. There’s a good explanation in this Wiki, a little Googling will turn up more.

Good article though.

Daryl

November 24, 2004 7:57 AM

Chris, I understand what Wall’s saying. What I’m pointing out is that while mature programmers know the sorts of code that tend to already exist for a given languages, novices often go to great lengths to write code that’s already handled natively. In order to become a mature programmer, in other words, you have to be willing to put some time into learning the core language. Then you’re better equipped to be lazy in the good way Wall proposes.

Sorry, comments are closed.

Media Temple

via Ad Packs