This is a quick tip that helped me save a lot of time – this is the reason why I love LINUX because of it’s simplicity.
I was working on a legacy code (referred as old-age code – a simple procedural coding style) for a client. In general, coding standard suggests you to have spaces instead of tabs to make it look better in all kinds of IDE, we (generally every developer) uses tab key a lot (to make our life easier) thinking it gives us the space but it inserts an actual tab (which usually jobs off from one end to the other). This legacy code was filled with tabs which looked pretty ugly in our code-review tool, though it looks perfect in the IDE, when you try to open it in Linux the favorite VI editor it looks ugly YUCK it is.
HUH, initially when my folks reported me I was like yeah go ahead and change it – what’s a big deal. But then when I came to know it not just one file but a lot (yes a lot) – it was almost more than 100 files, which had tabs instead of spaces (not GOOD – yeah I know).
In my company most of our projects we have been using custom-zend framework and I love their routing concepts. It gives you various options of handling many different routes to get the data based on your needs – just amazing.
Let me get straight with the topic. With Zend Framework, it is easy to route your URL in a nice way without having an head-ache of working with .HTACCESS file. Thanks a bunch.
Most of us know how to route an URL with routes.ini, for example:
What’s the big deal? We know this, yes I agree, have you tried routing a domain?.. 😉 Most of us may not, definitely I have not it does not stop there yet, Zend Framework also gives you an option to route an URL based on host/domain name and that is cool!.
Recently we had to get rid of this strange problem in one of our project due to some security concern. It was a nightmare that we had used a funny method to overcome this problem (by-passing real login session & allowing SWFUpload to upload any image), strange!. But, now we have a solution to this problem thanks to my mind & the time.
The problem is….
When you submit a form (here it’s uploading an image) everything seems to be fine (session data) till the control reaches session_start(), right-after that call $_SESSION array becomes empty and it assigns a new session_id, gotcha!. The problem is with the new session being created each time when SWFUpload try to upload an image, but WHY?
As you know SWFUpload uses flash to do it’s magic in uploading an image asynchronously and flash has an user-agent of “Shockwave Flash”, hence apache thinks it’s a new request from a new browser and it assigns a new session, means it doesn’t really destroys the old session but creates a new session.
Well, we all know the features of OOPS – it serves a lot of advantages for a complex system – Code reuse, Security, and many more…
But does just writing/implementing the module with OOPS complete your job? No. It should also be meaningful when you define a variable/method for the Class.
Keep the following points very clear when you write a code in OOPS.
Make use of the real features of OOPS – Method Overloading, Data Encapsulation and Inheritance.
Understand OOPS principle here – Code Reuse Principle.
Give meaningful name for any variables/methods used in the class.
Make sure that when anyone looks at your code they should not have any doubts/questions except for the business requirements.
A good naming convention is more than a nicety. It lets you write program that don’t need to be told about the relationship among variables and methods. Talking about coding convention reminds me one thing which helps understand the purpose of the script, called File/Method Description.
It is best explained here about coding-standard. It also have few examples which will help you to improvise the way your program should look like.
Give brief introduction about the script/method.
Add any example which will help the reader to understand the syntax (if any) better.
Add the date of the script when it is created.
Give author name along with EMail ID – this helps if the reader/developers needs to clarify any doubts.