6 ms·
Is this a parody of how not to do things? I was prepared to take it on face value of being rather misguided, but thinking about it... It's a glorified mess of g
by mootothemax 14y ago
Is this a parody of how not to do things? I was prepared to take it on face value of being rather misguided, but thinking about it... It's a glorified mess of goto statements and objects being misused.
I confess that I stopped digging further after I saw files being included in methods, absolutely one of the biggest sins in PHP:
https://github.com/anandkunal/ToroPHP/blob/master/examples/blog/handlers/article_handler.php https://github.com/anandkunal/ToroPHP/blob/master/examples/b...
https://github.com/anandkunal/ToroPHP/blob/master/examples/blog/handlers/articles_handler.php https://github.com/anandkunal/ToroPHP/blob/master/examples/b...
- jasonmoo 14y agoMost frameworks hide including views by way of extract() and output buffering. There's no real benefit to doing that on a small app. And no benefit on an api.
- mootothemax 14y agoMost frameworks hide including views by way of extract() and output buffering. There's no real benefit to doing that on a small app. And no benefit on an api. There's always a benefit to not copying and pasting code, which is what writing an include in each of your handlers boils down to.
- lux 14y agoNot that I've looked at it in much depth, but those just look like simplistic examples to show how the routing works. If it's just a router, then how you render views is beyond the scope of the library, and cutting corners in examples for the sake of expediency doesn't seem so bad.
- mootothemax 14y agoNot that I've looked at it in much depth, but those just look like simplistic examples to show how the routing works. If it's just a router, then how you render views is beyond the scope of the library, and cutting corners in examples for the sake of expediency doesn't seem so bad. I'm fine with the idea of a router simply being a router; I really take exception to yet more PHP examples illustrating bad coding habits being on the web though.
- lux 14y agoI can agree with that. Even just changing it from include("views/articles.php"); to return view ('articles'); would be better...
- andypants 14y agoThose are examples, with example page handlers. The actual library code is just the 91 line file in the root directory. I don't understand why people are being so negative about 91 lines of code. It's very simple and most of it is quite well written. How is this project 'misguided', just from face value?
- mootothemax 14y agoThose are examples, with example page handlers. Right - and examples are meant to illustrate how to best use a library.
- andypants 14y agoAnd they do show the best way to use the router. Rendering content is not related to the library at all. How you write your handlers and display your views is completely up to you. Why should a simple router dictate how you write the rest of your code? I agree that it could negatively influence code that more novice programmers might write with it. They should replace the code inside the page handlers with a comment indicating that the user should render output there.
- knieveltech 14y agoCould you offer some form of explanation as to why you find conditional includes so odious?
- mootothemax 14y agoCould you offer some form of explanation as to why you find conditional includes so odious? It boils down to sloppy thinking; your objects should be well defined enough that you're not having to include extra pieces of code in the middle of execution. You could argue code reuse - but why isn't that code either part of the object in the first place, or an object in its own right? If you know some examples of elegant code written with includes scattered throughout it, conditionally or otherwise, I'd love to see it. I will make exceptions for some parts of page rendering; it can sometimes be a good idea to put page elements into their own files and pull together when necessary. But for including code? No. Just no. Edit: I took exception in this case, as it's non-obvious what happens once the view file has been included, not to mention the lack of a base example handler class implies and encourages people to write code like this.