News for hackers. Stuff that matters.
Re:Toro - a php micro-router with great examples by mootothemax on Thursday August 23, 2012 @03:37PM (#4424434)
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/b...

https://github.com/anandkunal/ToroPHP/blob/master/examples/b...

Re:Toro - a php micro-router with great examples by lux on Thursday August 23, 2012 @03:53PM (#4424488)
Not 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.
Re:Toro - a php micro-router with great examples by mootothemax on Thursday August 23, 2012 @05:18PM (#4424903)
Not 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.

Re:Toro - a php micro-router with great examples by lux on Thursday August 23, 2012 @07:48PM (#4425496)
I can agree with that. Even just changing it from

include("views/articles.php");

to

return view ('articles');

would be better...

Re:Toro - a php micro-router with great examples by andypants on Thursday August 23, 2012 @03:54PM (#4424492)
Those 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?

Re:Toro - a php micro-router with great examples by mootothemax on Thursday August 23, 2012 @05:20PM (#4424916)
Those are examples, with example page handlers.

Right - and examples are meant to illustrate how to best use a library.

Re:Toro - a php micro-router with great examples by andypants on Thursday August 23, 2012 @05:43PM (#4425017)
And 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.

Re:Toro - a php micro-router with great examples by jasonmoo on Thursday August 23, 2012 @03:51PM (#4424484)
Most 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.
Re:Toro - a php micro-router with great examples by mootothemax on Thursday August 23, 2012 @05:30PM (#4424965)
Most 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.

Re:Toro - a php micro-router with great examples by knieveltech on Thursday August 23, 2012 @04:23PM (#4424614)
Could you offer some form of explanation as to why you find conditional includes so odious?
Re:Toro - a php micro-router with great examples by mootothemax on Thursday August 23, 2012 @05:26PM (#4424943)
Could 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.