I am working on a php web application, it handles a lot of things from collecting votes to registering new users. Traditionally I have done things like this using 20+ pages, but as a challenge to myself I set out to see how much I could get done with a single page. Everything appears to be working well and that got me thinking what are the pros and cons of this type of approach? Thanks for your input!
-
How big is your single page? – Niet the Dark Absol Jul 10 '14 at 16:52
-
4And how long does it take you to find something you need to edit? – Niet the Dark Absol Jul 10 '14 at 16:53
-
CTRL-F is my friend, I can say that. – user2464339 Jul 10 '14 at 16:56
-
Right. And that's how I get around in some of my larger (~500 line) files. And it's a pain. Having individual files makes it much easier to organise your code, even if you then just have one `index.php` file that does `foreach(glob("*.php") as $f) require_once($f);` or something. – Niet the Dark Absol Jul 10 '14 at 16:59
-
1Sorry, but this type of open questions do not belong to stackoverflow. Maybe you should move it to [programmers](http://programmers.stackexchange.com)? – RobertT Jul 10 '14 at 17:01
-
1Single page or single source file? Those are quite different things. – GolezTrol Jul 10 '14 at 17:02
2 Answers
You're describing the basic arguments between procedural and objects/methodization.
Can you make one giant page that will do EVERYTHING? Sure.
Will it run super fast? Probably. Functions have some overhead to them.
Will you be able to maintain the codebase? Maybe... Or maybe people rue the day you learned to code
Writing methodized takes more time up front but you rarely ever have to repeat yourself and you can better digest what your code is actually doing, instead of trying to dig out where a variable was set, discovering it was actually set 4 times, and trying to figure out what it's doing on lines 2478 and 5492. Not that this has happened to me or anything.
I think the big pro is user experience. But to get that to the top, you should not reload the page, but communicate with the server using ajax.
Single page does not mean single file. The best for maintainability is to have a file for each class. Also think MVC, this will help you to structure the code and avoid spaghetti code.

- 19,166
- 22
- 75
- 121