Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you know a good book/website about structuring your codes (PHP/ Web programming) [closed]

i mainly use PHP and I have been coding using it for a while. My main problem with PHP is that I think as your program gets bigger, it gets harder to maintain your code (probably applies for other things). I want to reduce this complexity in maintaining/modifying my codes. I want to make things modular and have rules when to start a new class or just append to an existing class (for example). I know that there are frameworks out there (CakePHP, Symfony, Rails) but what if I just want to use my PHP and use a hybrid of my own style and an existing style for good code management?

like image 472
denniss Avatar asked Jul 30 '10 15:07

denniss


People also ask

How can I create a website using PHP?

To create a website using PHP, you'll need to construct three web pages. These are based upon the basic structure of header, body, and footer. As you might guess, the header includes title information. However, information for the browser is also included, such as the HTML standard in use, along with CSS references.

What is PHP and example?

PHP is a server-side scripting language created in 1995 by Rasmus Lerdorf. PHP is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.


2 Answers

This is not just pertaining to php, this applies to coding in general. Frameworks will only help you organize your mess but if you are new to programming a framework will only organize your messy code.

Some basic ideas to keep in mind aside from undertaking a undergraduate in computer science (which i recommend if you are serious about coding) is to make your code modular.

For example, and this is a simply example to demonstrate the point. If you have a site that generates an html table containing financial data.

(Here are a few scenarios of how to go about coding this ...)

  1. You open up a new screen, financialdata.php, you code from line 1 to line N the code needed to get the financial data from a data source (database perhaps) and then iterate over the financial data to construct an html table.

  2. You open up a new screen, financialData2.php, you code a function at the top which pulls data from yuor data source and returns an object (array maybe) containing the items. You take this return value and generate your table on this financialData2.php page.

  3. You open up yet another new screen, financialData3.php, you take your database function from financialData2.php and use it to get your financial Data from yoru source. You code another function to generate an html table based on some arguments passed in as parameters. And lastly in your financialData3.php page you display do the following and your page now has a table containing financial data from your data source.

The lesson here: the more modular your code is the better in a lot of ways. You now have a data base function that can get data, and you have a function that will render a table based on a list of items passed in.

You can now create another page and use these functions in different ways, perhaps your data source function has parameters like table and selection criteria. This way you can use the same data function to get data from different tables based on criteria. You now have a VERY basic data abstraction. (Dont let abstraction scare you aware). An abstraction is nothing more then a simplification of something. In this case we have abstracted away the details of how we get data and let our function getData take care of those details.

Please comment/ask questions and we can discuss further but honestly, I do not think one book or web site can teach programming practice like a BS in CSE can through classroom discussion and hands on practice.

like image 83
Chris Avatar answered Oct 10 '22 15:10

Chris


Learn Design Patterns:

  • http://sourcemaking.com/design_patterns (covers the GOF patterns)
  • http://martinfowler.com/eaaCatalog/index.html (covers POEAA obviously)

Also helpful to increase code quality:

  • http://phpqatools.org/

A sidenote on frameworks: while frameworks often do tell you how you should layout your code and folders and stuff, they rarely tell you how to code properly. A framework offers solutions to common problems and that's cool, but if you try to step outside of what the framework already offers in terms of functionality, you are on your own again. That is because frameworks are concrete implementations, while you want to learn about design principles.

like image 2
Gordon Avatar answered Oct 10 '22 17:10

Gordon