Jump to content

Recommended Posts

I'm not here to criticize anybody, I'm just trying to understand why a lot of beginners are using a lot of bad practices, especially obvious ones. BTW, I'm not telling that every beginners use bad practices or all of the bad practices around. 

 

Anyway, I've been helping in a couple of forums and other websites since 3-4 months now and I always see the same bad practices used by beginners, and I don't understand why they use that kind of coding style.

 

I'm talking about:

  • Writing a PHP file of 2000 lines without any functions (so it's like basically like writing a 2000 lines function)
  • Mixing HTML with PHP, PHP with HTML
  • Not using a debugger to debug their code
  • Not knowing how to use the official doc (or not knowing about the official doc at all)
  • SQL Injections

Is it because they don't know about those practices?

Is it because they don't understand it?

Or maybe all the tutorials they used to learn are crap (or just written to provide examples, not good practices)?

Or is it just because they are beginners and it's the "normal" way of learning things?

Is there something we can do about it?

 

Like I said, I'm not trying to discourage anyone or judge anybody, I'm just trying to understand so that I can help those beginners better :)

 

By the way, I probably programmed like this at the beginning, but it was more than a decade ago, so I don't really remember  ;)

 

P.S. I wasn't sure where to post it, thanks for moving it to the right place ;)

Edited by mogosselin

Copy/paste is the easiest fastest method.

Bad code is all over the net.

Some don't want to learn, just get it done and have it.

Being a newbie I'll explain my side:

 

2000 lines of code; as keeping to simplified thigs like else, if, else if is easier than creating and learning custom functions.

 

I use HTML and PHP as I didn't know there was anything wrong with it?

 

<html>

<title>Example</title>

<body>

<h1>Example</h1>

<php

Echo "hello world"

#insert php script

<?

</body>

</html>

 

What is wrong with this other than my bad syntax and bad spelling?

 

The other points are great. Even I don't do that. I guess because lack of knowledge and/or care of their work?

Edited by Check202

Because of PHP's long history, unfortunately the internet is riddled with bad examples of PHP code.

 

If not told otherwise, beginners learn by studying these existing (bad) examples.

 

I always recommend newcomers read this first nowadays: http://www.phptherightway.com

Hi,

 

I think this is caused by a combination of different problems.

 

First of all, PHP itself is a mess. The people who say it's easy to learn either don't know the language or simply lie. It may be easy to produce crap, but writing good code takes a lot of experience and deep knowledge about the hundreds of quirks, pitfalls, brainfarts and bugs of PHP.

 

The next problem is that the people who publish “tutorials” and free code tend to be absolutely clueless. PHP is often described as the blind leading the blind, and this is very true. Enter a random PHP-related keyword into Google, and you'll get page after page of absolute nonsense. 

 

Finally, PHP attracts the wrong people. Too many newbies have absolutely no interest in learning the language and implementing intelligent solutions. They seem to think that “programming” is the act of stealing crap code from some dubious website. As a result, the same stupid code snippets from the 90s are passed from generation to generation and just won't die.

 

Put the three together, and you know why PHP is in such an awful state. A large part of the PHP users is basically stuck in the 90s, but the Internet today is very different from the Internet of the 90s. What may have been acceptable back then will get you into serious trouble today.

 

I think we need to insist much more on security and quality. Yes, it's annoying to repeat the same litany in every single reply. But it's the only chance to spread the word.

My thoughts:

 

Writing a PHP file of 2000 lines without any functions (so it's like basically like writing a 2000 lines function)

Assuming the user does know how to write functions and what they are for, this is probably due to a lack of planning. They know what they want for the end result and just start writing code not knowing "how" they are going to get to the end result and just figure it out as they go. That's why we see so many people who have coded themselves into a corner, so to speak. Either they will have to implement a "hack" to fix their issue or rewrite their code from scratch to fix the issues they created. I have to admit I do this sometimes - especially when I have an idea on how to code some specific process that I want to get working before I forget. But, I will always go back and refactor the code to pull out parts of code that belong in separate functions or classes.

 

 

Mixing HTML with PHP, PHP with HTM

I think this is due to some people not being able to conceptualize the process of separating the logic from the presentation. They think in a linear fashion. It just doesn't make "sense" to them to write the logic to create the output without actually echoin'g the output right then and there.

 

 

Not using a debugger to debug their code

Many of these people probably don't use a full functioning IDE (e.g. Notepad++) and even if they do, don't know how to use 90% of the features. It's much more rewarding to write code to do something new than to read a manual about an IDE on how to use it properly.

 

Not knowing how to use the official doc (or not knowing about the official doc at all)

Echoing Jacques1 comments, I think many of these users are copy/paste programmers that don't know what have of the code they put together even does. They may not even understand simple basics such as parameters (optional vs. required). Heck, I've seen posts where a person passed a value to a function that was completely opposite of what should have been passed. When I asked him why he passed that value he hadn't looked at the manual, but that he thought it made sense.

 
 

SQL Injections

I work with professional developers that don't remember to do this! But, you can group this into lots of different security risks that are not appropriately handled. Without having knowledge of the different risks it's difficult for someone to know how to handle it.

 

And, I also somewhat agree with Jacques1 response that PHP attracts the wrong people. I wound't say they are the wrong people so much as it attracts the completely uninitiated people that have no programming background. My guess is many of these people start with just HTML and then want to add some functionality. They may have some experience with JavaScript which is similar to PHP. But, pretty much every host out there supports PHP and there is a huge support community (such as this site). So, the natural progression is to start with PHP. They don't want to take a few months to learn programming basics let alone learn PHP. It's just easier to find a tutorial around a feature they want to implement and copy/paste it and try to tweak it for their needs.

Being a newbie I'll explain my side:

 

2000 lines of code; as keeping to simplified thigs like else, if, else if is easier than creating and learning custom functions.

 

I use HTML and PHP as I didn't know there was anything wrong with it?

 

<html>

<title>Example</title>

<body>

<h1>Example</h1>

<php

Echo "hello world"

#insert php script

<?

</body>

</html>

 

What is wrong with this other than my bad syntax and bad spelling?

 

The other points are great. Even I don't do that. I guess because lack of knowledge and/or care of their work?

 

What is wrong with this way of doing thing? The thing is that it could be OK if you know when this is good and when this is bad. Most of the beginners seems to think that this is the only way.

 

If you make a small file of 40 lines and that's it, who cares. But if you try to make a real application with a DB behind, a login, users, authentication, etc etc... This is when it will get messy and hard to debug. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.