We're going to carve away a high-performance service from a very simple node app. We'll do load testing to verify our bottleneck, create a protobuf file to clearly communicate the service boundary, and then integrate a golang server implemented with an RPC library called Twirp.

Throughout October 2017, we ran the first season of Productivity Quest — our Slack-based series of challenges tailored to improve the way we work. It turned out to be a huge success and kept the community wanting more. This year, we decided to take a different spin.

Reddcoin was designed to be a social currency to credit creators and others that might be losing to the ever-changing advertisement industry. We're going to see how to work with RDD coins in the sense of sending, managing, and maintaining these coins with Node.js and JavaScript.

Many articles have been written about refactoring. What I'm trying to do here is to bring to light real life's example of how together with my team we approached the problem and how do we plan to deal with it.

CakePHP with Symfony’s2 router

A couple of months ago I have started my adventure with CakePhp and as every Symfony’s developer I thought that any other framework except Symfony is a piece of crap. Day by day and step by step I began to realize that’s not so bad as it seemed to be in the beginning. Well, the second version of CakePhp still has a lot old-fashioned patterns, singletons or lack of tests, but I can live with that. I saw a lot of better or worse frameworks in my life. However, one module remains a bitter aftertaste – the router.

Let’s just look at the very basic things. Let’s start with new route declaration.

It looks quite natural and shouldn’t make any unpredictable problems… well, shouldn’t. When I wanted to display an URL to the blog/:slug page in a View file I was struggling with additionals parameters and not found paths. As every developer I opened the declaration of connect method and tried to figure out what exactly happens inside. First impression was quite good – `public static function connect($route, $defaults = array(), $options = array()); `.

The author of Clean Code – Robert C. Martin emphasizes on the right naming. All methods, functions, classes or variables should tell you, literally, what responsibility they have. So, when I saw three parameters in connect method they seemed obvious – $route was for the URL, $defaults – filled the missing arguments by default values and $options – about additional information for my route.

Everything was clear and I couldn’t find out why my code cannot compose a proper URL until I caught the condition which was commented:

// keys that exist in the defaults and have different values is a match failure.

I was so wrong. In the result I’m pretty sure and, of course, I confirmed that, the code `Html->link($postName, array(‘controller’ => ‘blog’, ‘action’ => ‘post’, ‘slug’ => $slug)); ?>` will break, because we didn’t pass the argument template.

I believe that the second parameter in connect method should be called $requires. One confusing name took me 4 hours of my live and caused a lot of problems.

So, what can I do with this?

Extend! Extend the original routing by something what you really like. I’m huge fan of YML routing implemented in Symfony 2. It’s really simple, transparent and easy to read. Moreover, and what is the most important thing for me, each route has a name. So I can build every single URL without passing all defaults parameters, but focus only on mandatory as slug.

Conclusion

I really like the wise spectrum of available open source frameworks and platforms on the market. I learned Symfony, Zend, Kohana, CakePhp or even Drupal or WordPress. However, besides of the naming convention, used architecture or design patterns which can be more or less comfortable for me, sometimes I have to face a really huge problem which stops me for a couple of hours and I feel that I need to change that because every time I use it I will suffer (mentally).

Because the open source world emphasizes how the decoupling is important, it’s really easy to get my favourite component from one framework and put it into another. If I connect the framework with external module in a plugin – bridge, this should be easy to use for others. And I hope I did this.

Good to see integration of componenents on other frameworks.
Like symfony, zend, aura do provide a few components.

http://kadur-arnaud.fr rudak

Totally agree with that !

http://jedistirfry.co.uk David

Great idea to bridge the two components. I’m confused by your example route though. What is it actually supposed to do? Why is slug defined if it’s a routing token?

If I assumed that it was to view a blog post I would create a route like:
`Router::connect(‘/blog/:slug’, [‘controller’ => ‘blogs’, ‘action’ => ‘post’], [‘slug’ => ‘[a-z0-9-]+’, ‘pass’ => [‘slug’]);`

Then in your `BlogsController::post($slug)` method you would get the slug as a passed parameter. To create a link to view this post I would create a link as `echo $this->Html->link(‘View post’, [‘controller’ => ‘blogs’, ‘action’ => ‘post’, ‘slug’ => $blog[‘Post’][‘id’]]);`

http://piotrpasich.com Piotr Pasich

David,
your example is good. I cannot fight with that. My point was not to pass all parameters (as in your example) to every single link – ‘echo $this->Html->link(‘View post’, [‘controller’ => ‘blogs’, ‘action’ => ‘post’, ‘slug’ => $blog[‘Post’][‘id’]]);’ should be called without controller, action and template. I want to pass there really, really mandatory “slug”.

So if the CakePHP has an option to create an url and call it by echo `$this->Html->link(‘View post’, ‘blog_post’, [‘slug’=>$blog[‘Post’][‘slug’]]);` then I’m ok.

Nice work on the plugin, seemed interesting (I added a question about caching to your issue tracker).

One question, unrelated to your plugin: Where is CakePHP lacking in tests? You mentioned in your post that we’re lacking in tests, yet the core tests are pretty comprehensive [1]. What gives you the idea that this is the case?