Why I'm a bad programmer...

Well actually I don’t consider myself a bad programmer, but it caught your attention didn’t it? ;D

Well I have been thinking what are the best practices of PHP Programming and decided to do an internet search on it. I came across this http://code.tutsplus.com/tutorials/why-youre-a-bad-php-programmer–net-18384

As I was reading this I thought to myself that I have been guilty in the past in doing some of those bad habits. I still from time to time find me still falling into some bad habits. For example I’m always trying to find a way in doing something clever, but it would be faster and better if I just did it the practical old fashion way.

This is why I like coming to PHP forums to try to help others out and to even get help from time to time. I have found other forums outside this one that have to put it nicely an “bad attitude problem”. What I mean by this is that certain people will reply to your question(s), but do so in a smug way. Now, I hopefully don’t come across that way to others here and at times I feel that I might for sometimes telling the truth right from the get go is the best option. I know what it’s like to spend hours tackling a certain piece of code and posting a question on a forum for help, only to get the response that you should throw away the script for it’s a pile of junk. That’s why when a beginner who wants to learn php starts off by showing obsolete code that I try to head them off at the pass and tell him/her there are newer better techniques that will accomplish the same thing.

I realize that some people have acquired the code that is a nightmare and are told they need to fix it right now. I feel bad for those people, but for someone who is doing as a hobby or to further the programming skills then learning the right way from the start is the best approach in my opinion. For those with the nightmare code fortunately there are experts in PHP that will be able to help you out on legacy code. Though sometimes it’s hard to tell when someone posts a new thread for the very first time and I immediately jump the gun in stating that it’s obsolete code and that you should start over speech. I apologize if I have done that in the past and I have been trying to be more tolerant recently.

Sorry about my rambling, but I felt I to have written bad code in the past and that some future script might not be worthy (hopefully not though).

Haven’t read the full post yet (though I think I’ve read it before). But this quote struck me:

I, [state your name], hereby swear to make comments in any situation where the purpose of the code I've written isn't immediately apparent.

With proper code it’s is unbelievably rare to come in the situation that you can not make it obvious what you’re trying to do.

Is there really any reason to comment anything in the code below?

[php]<?php

class ArticleController extends BaseController {

public function listAll() {
$articles = $this->articleModel->findAll();
$this->view->render(‘articles/list’, $articles);
}

public function single($id) {
$article = $this->articleModel->findOne($id);

if (!$article) {
  throw new NotFoundException('Article with id ' . $id . ' could not be found :(');
}

$this->view->render('articles/single', $article);

}

public function delete($id) {
$article = $this->articleModel->findOne($id);

if (!$article) {
  throw new NotFoundException('Article with id ' . $id . ' could not be found :(');
}

if (!$this->acl->canDeleteArticle($article)) {
  throw new AccessDeniedException('You are not allowed to delete article with id ' . $id);
}

$this->flash->add(‘success’, ‘Article with id ’ . $id . ’ was successfully deleted’);

$this->location(‘articles/list.html’);
}

}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service