write less do more | andi setiawan's blog

How to save the resource in our project code? Should we repeat writing the same code in every page/file? We can save a lot of our time and resource by putting the same code or lines into a function or procedure.

In some programming language, such as Pascal, Batch, C, PHP, etc., we can make a single special file where we can store our functions and procedure, also some constant.

Files which stored functions and procedures generally called “library“. The reason? coz it store many functions… I don’t know the other reasons.. 😀

For some constant (variables that store fixed value), we can put it on a editable file, like “config.php” in PHP or “config.tpu” in Pascal. So if we need some constant, we only need to call that file.

For example, we have some web pages that require same coding and data, but in different web design, should we write the same codes in every page? and how if there’s a minor change in the codes? it will make us work on those page again.

We can solve that problem by creating a single file that contain the function, and call the function from every page. So, if there’s any change on the code, we have to modify the file that contain the function only. In PHP, you can also include the file with “include()” function rather than calling for the function.

There a lot of free library out there, so you can use them to decrease your time in coding. For example jQuery, it is a free javascript library that store many function. There’s also Mootools, it’s has same function with jQuery.

Posted in programming, Tips n Trik | Tagged , , , , , |

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: