FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


What is a good or bad php code?





ronaldallan.mojica
I'm Ronald Allan Mojica a Typo3/PHP Programmer here in Makati. This is my answer regarding the question above. In almost 3 years of programming using php and mysql I'm glad that I learned alot in my previous and present company and I'm still learning and unlearning things in my chosen career.

This answer is just my own perspective and I cant say that this is the perfect answer for this question . I consisder a good php code if its, consistent and simple.

A good php code is "simple". You can accomplish a much simpler code by using functions or maybe classes(depends on the situation). A long chunks of code(some consider it bad) can be broken into pieces by the use of functions. One of the best practices of good php programming is separating your php code with your template or html.

A good php code is "Consistent". Consistency makes your code easier for others to read. Even your out of the office someone can breakin to your code. One practice is when you are using a function, function oftenly used on fetching some variables and return a process content like(string, integer, etc.). To be consistent if a function is designed to accept on strings, that said function must only accept strings if not an error will be displayed.
infobankr
You hit the nail on the head. Consistency is so important in so many different ways - not only for programming, but also data storage and organization.

Don't you love it when you are looking at someone's files and you notice that they've named them in a consistent manner? So good.

And simplicity too - great post overall, thanks for sharing.
Fire Boar
Agreed with you on every count there. I love it when you've got it consistant all the way through, and when people make mods for existing applications you often find they're completely different to the format of the application itself - this is particularly annoying for things where mods are encouraged.

Simple code is also very nice, but I'd say that if you need something to be complicated then go for it. Don't let ideals of simplicity hold you back. Although it's obviously better if it is simple, if you can be more efficient with complicated code, do it. What I think is more important is well-documented code. Make sure that you've commented every section of the code to tell the reader what it's going to do.
snowboardalliance
I agree, but I think Speed and Security are also very important for php/MySQL. Because php is run over a server, many people will be accessing the same script so it needs to be fast and not create a load for the server (although you said it should be simple which could mean fast). Also because it is run over the internet, you need to be prepared for hackers and bad data, so security is pretty important.
Related topics
Show PHP Code
PHP CODE INCLUSION
mySQL Query/PHP code - get the highest value...
my PHP code benchmark script that got some problems
PHP code snippit?
CSS for making images go through a php code.
Gradient Fill Cell
I want PHP Code to ......
Help With Simple PHP Code Snipit
removing DirectAdmin part of URL makes php code work
Highlight PHP-code in a HTML-document
Preventing bad PHP script calls
I need help with a very simple php code :(
Php Code Trouble Set-up
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.