Forum Moderators: coopster
Basically, you learn it with practice. At beginner level I should not expect someone to do the best-programming-practice. Also I believe there are no hard and fast rules for code optimization. But there are certain criteria that you should keep in mind while coding.
1 - less code more work: you should try to perform tasks with such logics where you write less code but take out maximum functionality from it.
2 - Execution time is critical: Do not be contended with one coding solution, try alternatives and pick the one which take less time to perform task.
3 - save your server: avoid writing code which bamboozles your servers i.e web and database servers. Especially, while making big applications keep it in mind that hit-rate of the application and optimize your site for fast browsing and less load on the server resources.
4 - OOP is the best policy: my very personal choice is OOP when I have to make huge applications. You can reuse your classes, you do not have to do the same stuff again and again, you can organize your work properly and easily. There are certain issues with OOP e.g one function for one purpose etc you can google to find out the best OOP practice
5 - Software Engineering: do not jump to the coding. Practice software engineering principles. It will help you control your development pace and organize your plans.
There are many other things like coding style, commenting your work, using a version software like subversion or cvs etc etc I hope some other fellows will add much more to this thread.