-
Notifications
You must be signed in to change notification settings - Fork 290
Intro to Version 2
After being asked a few times about Klein's history, how v2 came about and why some of its design decisions were made, I thought it made sense to write a little about it in a central and visible spot. Here goes...
One of the best ways to see how most of the rewrite was done and why some of the design decisions were made is to simply look through the original PR for Klein v2. In it you'll find discussions between @chriso and I (@rican7) on some of the back and forth on certain features.
Here it is: PR #92
The original Klein library was a much more functionally-styled library that followed a similar style to Sinatra. Unfortunately, it meant that Klein was hard to test in the PHP world. V2 was made in a more object oriented style, for a number of reasons, with the objective of keeping some of the functional abilities of v1.
The older idea of defining mix-ins or functions at runtime was scrapped in favor of a more performance oriented classical inheritance method overriding and injecting style. A discussion and explanation of these choices is in issue #97
The first version of Klein was very fast compared to similar libraries, and it was even its original tag-line/bragging right. Unfortunately, in order to perform at such a high rate version 1 had to make some significant tradeoffs. Version 2 is also very fast, as the logic of actually matching urls hasn't changed much at all, but some of the tradeoffs were balanced. For more information on how and why this happened, there is a discussion and post in issue #152.