I hate MVC.
I mean, don’t get me wrong, it works great for game programming and large scale deployments, but for something like a website, it’s bloated and overkill.
Here’s my coding style when using PHP/MYSQL as my programming language:
- Inputs and input variable sanitization – GET, POST, SESSION and COOKIE variables are sanitized and assigned to PHP variables.
- Variables – Any standard and constant variables I’ll be using througout the code are assigned here.
- Output preparation – Setting of OUTPUT variables here to blanks with names like outheader and outfooter etc. This helps later recall.
- Main processing – The work horse part of your code goes here. Do the things you do best with what you have. Assign output to the appropriate output variables you set earlier.
- Output in one large echo, surrounded by double quotes, with your output variables contained inside.
I call this INPUT, PROCESSING, OUTPUT. IPO is better than MVC for web and PHP programming.
It works, it’s efficient and it makes super clean, easy to read code.
My PHP code has about 1 line of comments per 200 lines of code. That’s because the variable names, structure and obvious steps when using IPO make comments unnecessary.
Last tip – Variable names – Don’t use caps within variable names. Keep variable names relevant and if you pull things from a MYSQL table, name the variable after the column.
What do you think?