Jump to content

Why Does My Code Look Like Crap...


omgRawr
 Share

Recommended Posts

I have a little more than one year's of experience with web development and about one year of experience with PHP. But I've been programming for much longer than that. I've been programming for three years now and it still doesn't seem like I'm getting very far. I'll get to the main point now. Today, I downloaded some PHP software from the web and took a look at their code. Among them were Joomla, Wordpress, and Drupal. I compared my PHP code to the code I found in the PHP software that I downloaded. Compared to them, my PHP code looked like crap... like it was terribly coded... now I feel terrible about myself. :)I really can't gauge my own programming skill though, does anyone want to help do it for me? I just want to make sure that I'm on the right track and not producing terrible code. I am self-teaching myself but also learning from numerous books and online articles. I am in no way interested in paying for web development classes, so please don't bring that up. So, what should I do? Would anyone be interested in reviewing my code?

Link to comment
Share on other sites

There's technically a difference between looking good i.e. clean, organized, and well structured, versus actually performing worse, acting less efficient or adhering to bad practices. I would suggest that of course your code is going to visually look different from the examples you looked at. Those are full fledged projects or products of some sort, I wouldn't doubt that at least some of the code was written by someone who has a professional background or has at least paid for a class or two. Your code probably just has a different style to it, everyone's does. I could "View Page Source" on this page right now, and just because it doesn't look like what I would do for HTML and CSS, that doesn't mean I have terrible skills, I've just developed a different way of applying those skills. No one can really judge your level or where you are without seeing code, so perhaps an example page would help us help you to see if there's anything you're not getting right. If you've been programming for 3 years already, it's probably just minor details that you need to shape up on when it comes to PHP.A good way to observe where you are with your skills is just to keep trying projects that you think are difficult. Accomplishing something is part of having good skills, not just knowing how to string together good looking or well formed code (though that is an important part too, they go hand in hand).

Link to comment
Share on other sites

Good programming practices are really language-independent. You should always do things like error checking, validation, etc regardless of which language you're programming in. I see a lot of PHP code being produced where people don't bother to initialize variables or do any decent error checking or anything that you would learn how to do in a class taught by a professional programmer. If you aren't doing those things already, it's difficult for you to understand how and why you need to do that if I just tell you that you need to do that. You say that you aren't interested in paying for programming classes, but keep in mind that the code you're reading was most likely written by someone who did pay for programming classes. It would be naive to say the least to think that you can learn the programming practices that are taught in classes without taking the classes. It's hard to pick that stuff up from a book, you need someone who you can take your code to whose job it is to go through your code and tell you what to do differently. It doesn't really help that PHP in particular lets you get away with a lot of things that other languages don't, so people write PHP code that runs and doesn't report errors with the level of error reporting that they use for development and just assume that they're doing things the right way simply because they don't know any better.Here's one tip: always develop with maximum error reporting. A notice is still an error.error_reporting(E_ALL);ini_set('display_errors', 1);

Edited by justsomeguy
Link to comment
Share on other sites

There's more to programming than just the code. Behind all the code is how data is structured, stored, retrieved and manipulated. This is independent from which language you're using.In order to produce optimal code, you must understand how a computer works from the base up.

Link to comment
Share on other sites

For heaven's sake just post something that looks like crap to you. Put that in code tags. Below the code tags, explain what parts worry you and why. (I'm emphasizing what should go in and out of the code tags so we can see exactly what things look like.)We could go on and on talking about format, structure, efficiency, comments -- but till we see and find out what's on your mind, it's all just guess work.One note in advance. Pros tend to comment a lot, especially if they work for an organization. They may have a very specific format for introducing a function, explaining what it does, what the arguments and return values are, maybe some editing history, and all that may get wrapped up in asterisks or something. That alone can give "corporate" code a very different look than yours might have. But you may decide that's too much for a 30-line script, and no one's going to shed a tear over that.

Link to comment
Share on other sites

Here's one tip: always develop with maximum error reporting. A notice is still an error.error_reporting(E_ALL);ini_set('display_errors', 1);
Thank you for that good piece of code. I acutally didn't know that. I will be implementing that code in my PHP scripts from now on. I was looking for a way to validate it anyways!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...