Monday, September 11, 2006

Good practice

There is a lot said about good practice when programming and there are a few things i use.

- Produce reusable code

Even if you are sure the code you write is never going to used on another site write it as it will be used for other sites. Reusable code is a lot cleaner and more flexible than improv code. This makes your site faster.

- Only the code that displays html must maintain html.

Get as much html out off php classes and javascript functions. If there is no way to remove the html out of the code keep it as simple as possible. If a css class is needed or another attribute make it an argument so it can be adjusted without crawling through the function code.

- Javascript interfaces need server language script

When you are coding in javascript sometimes you can forget it can be turned off. You can make nice things but when users can't do anything on your site without javascript you never reach all the people that want to use your site. If there is html that has no purpose without javascript it's site fat.

- Use html wisely

Because div and span tags are the most generic tags you can use them to replace all tags. Use html tags according to their purpose. You can bend their purpose a bit like using a list to build a menu that looks like a table. Use an id attribute only once per page.

- Make css readable and cascading

When you create css based on html you are going to get into trouble sooner or later. If you put everything in a class or an id your css file is going to be lengthy and you are going to have to use multiple classes if you want to add javascript functionality to an element. Use an id to style included elements. Split your css file into sections using comment lines.

These are a few tips. I hope they work out for you too.

No comments: