I am John and I solved a problem

I am John, I work for a company whose name I can not say and we have this client, but I am not allowed to mention their name, and we had this problem for which I cannot give specifics but I am here to tell you about how we implemented the solution.

Sounds familiar? Maybe, maybe not.

Well, for me this is the thing I hear at almost every conference I attend. Truth be told, I can understand that one can not give specifics, but one should also not start a topic meant to teach others unless you are willing to go into specifics.

I have the feeling that these “Jonhs” want to create the impression that they encountered a million problems and found at least one solution for each.

But how do I know that the problem was not created due to a faulty logic? How do we (the attendees) know if maybe the requirement was stated or understood in the wrong way. Usually that is where the problem stands. And it is best to ask all the questions before starting to work.

Anyhow, there are speakers for whom I would travel half the planet, but there are also others that have fancy job titles and do not have a clue of what’s going on in the dev world.

So, conference organizers: please, please I would rather see the same 3 speakers in all the conferences than having different poorly prepared speakers, just for the sake of not repeating.

And for the speakers: Please speak for the sake of sharing and making the community better not for the money. Remember why you became a programmer! If money is the first answer, you are doing it wrong.

I am John and I solved a problem

Interview questions

I was recently invited to an interview for a frontend developer role. After the interviewer asked me a lot of questions about http, http2, devOps, linking backend with frontend he said: now let’s go to the more unpleasant questions. And he started with: what is this small tag at the beginning of an HTML page <doctype... And he went on about DTD then we moved to local storage, then CSS and pre-processors …

When and why did HTML and CSS became unpleasant? how else would you develop for the web if not using HTML and CSS?

I am now asking you: people of the world that you call yourselves web developers, who are you and what did you do with the web developers?

Interview questions

Web developer definition

This article exists because a tweet is to short and @ppk does not allow comments in his articles (i.e. this article: “What is a web developer?“). And maybe is a good thing that he does not allow comments – this gave me the opportunity to write down my thoughts without using other people’s space.

For about a year I moved from web development to application development (big mistake, will explain in a different post). And the same “developer problem” is present here too.

I believe this is because there are more and more people that call themselves developers [or even worse: web architects] and they don’t know the first  thing about how the web works; they have no idea about what web standards are and why they exist.

Sadly most of them started their developer life – brace yourselves –  programming in jQuery, or React or Elm (that’s the latest..). And I ask you now: how can one “program” in jQuery? When did jQuery become a programming language?

I tried saying these things out loud, but I got hit very hard by the young ones.

Maybe part of the problem is the wrong/too young [please read not enough life/work experienced] people in the high management or in the hiring process on the technical level (I know I saw this one too many times in a big corporation I used to work for).

What happened to people fighting for a better web? Are we just saying it to be trendy? What’s so trendy about not knowing the basics about doing your job? Why did you chose to be a web developer if you do not know what www is?

PS: I am not as old as the article sounds, but I am very sad about what I see around me. And maybe one article is not enough to change something, but I see it as a start. Maybe it will push some button on someone.

Web developer definition

The king is dead, long live the king!

I read this article today: “Saying Goodbye to Firebug” and I remembered how me and Firebug first met. I thought it to be a good idea to write a few lines about it because Firebug was a good friend to say the least.

I remember the first time I saw Firebug. I was 2006, sometime at the beginning of the year (probably Jan or Feb). I was in the second year at the Faculty and it was the first session of a course called “Web techniques”. The first condition to pass the exam was to have Firefox and Firebug installed. No Firebug, no passing! You can not imagine what we all felt. How can a plug-in possibly help us! Little did we know…
And now, 11 years later, I a front end developer still using Firebug. To pass a different exam: the users acceptance.

I would like to thank you Firebug for all the help and support. You were there all the time for all the steps.
For tables and divs, for images and rounded corners, for transparency and animations. You helped a lot of people and brought up a bunch of great developers.

So thank you, friend.

The king is dead, long live the king!

The dark side of frameworks

Some time ago I had a somehow bad experience with a (good) company that I’ve applied to. This is the email conversation with them:

Dear Constantin,

thank you again for your application.

I am sorry to inform you that, despite your interesting CV, your profile does not fully match the requirements for the vacant position.

We truly appreciate your interest in XYZ and we wish you every success for your future career.

Best regards,

XYZ

Then, being just curious, I replied to them:

Hello,

Thanks for the reply but could you please tell me what the mismatch was because I really do like your company and I would really want to work for you.
Thanks again!

They responded:

Dear Constantin,

our Lead Engineer could not find any Symfony experience in your CV which is why he decided to proceed with other candidates.
I hope this helps!
Best regards

But this does not seem right. It looks like they have become dependent on a particular framework so hard that they could not hire many possible good programmers because they lack the experience with a particular (and simple) PHP framework. The DDD in me started to scream so I wrote this to them:

Thank you very much for your time. I have a message to your team lead:

Symfony is a framework like any other. It is very well documented, there are lots of tutorials out there that can get an passionate developer up&running in days. I used Zend framework for Web application as starter but I could replace it with any other framework at almost any time. Any developer can write code that works for just a particular framework but only the best developers write code that are framework agnostic. After years of programming I realized that frameworks are implementation details, they are just noise that draw developers attention from what really matters: the domain! Of corse,  they should be used, we should not reinvent the wheel, but they should be replaceable at any moment without full rewrite.
This comment is specially about general purpose frameworks like Symfony and Zend. They are not Magento. You afford to become dependent to Magento because it offers you all there is about for a six digits ecommerce shop. But general purpose frameworks are just a collection of libraries. You should protect yourself from them. You should not step into framework creator’s trap. If you do you will not be able to hire good programmers because they do not have experience with it.
DDD has help me to separate my pure core domain code from the infrastructure/technology. This is good because technology changes faster than the business. If you do not separate them then you will loose money just to rewrite your code to match the latest, fastest, most secure version of their framework.
What has Symfony and the other framework don’t? PSR-7 Controllers? PSR-11 Dependency injection container? PSR-3 Logger? These are present in any PHP framework. An ORM? No, it is from Doctrine.
About code quality, what does teaches Symfony on its documentation page [1] ? It tells the programmer to use the service-locator anti-pattern in the controllers by making the DIC available as $this->container. What the lazy programmers do then? They use it and thus they make their code less testable, depending on hidden services that only the author will remember.
If you are indeed so dependent to Symfony that you will never change it then probably we won’t match.
Thanks again for your time.
Being, like I said, a good company, they have responded with this:

Hi Constantin,

thank you very much for your effort to write down your thoughts.
You have a point there!
I’ll pass this on.
All the best for now
 My question is this: it’s pretty straight-forward how to help the company that you work for to understand what code quality means: you write clean code that works and they feel the benefits but how to help the companies that you do not yet work for?
It seems that frameworks can be evil in ways that are not easy to spot.
What do you think?
Disclaimer: I don’t consider myself the best programmer in the world. That’s not the idea. The point is that they  didn’t even consider to test my abilities. I was disqualified from the start. I may have been Martin Fowler, Uncle Bob, Eric Evans, Vaughn Vernon  or Greg Young (and many other!), it would have not mattered to them because I did not know Symfony.
To be continued.
The dark side of frameworks

Auto-wiring for Zend Framework router

When you use Zend Framework 2, in particular a router, you have middle-wares that handle requests. These middle-wares take as arguments the $request, the $response and (optionally) the $next middle-ware.

So, your code might look like this:

class SomePagePage
{

    /**
     * @var WidgetRenderer
     */
    private $widgetRenderer;
 
    public function __construct(
        WidgetRenderer $widgetRenderer
    )
    {
        $this->widgetRenderer = $widgetRenderer;
     }

    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
    {
        $someId = Guid::fromString($request->getAttribute('idContract'));
        $someIntegerArgument = (int)$request->getQueryParams()['someParameter'];
        $someFloatArgument = (float)$request->getQueryParams()['someOtherParam'];
        //.. a lot of code for parameter fetching and validation
       
        // ... some logic ...
        return new HtmlResponse($this->widgetRenderer->render('default::some/path/to/template', [
            'someData'   => $someData,
        ]));
    }

}

What if you could simplify and have all request parameter already available and of the correct type, some thing like this:

class SomePagePage
{

    /**
     * @var WidgetRenderer
     */
    private $widgetRenderer;
 
    public function __construct(
        WidgetRenderer $widgetRenderer
    )
    {
        $this->widgetRenderer = $widgetRenderer;
     }

    public function __invoke(Guid $someId, int $someInteger, float $someFloat ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
    {
        // ... ONLY the logic ...
        return new HtmlResponse($this->widgetRenderer->render('default::some/path/to/template', [
            'someData'   => $someData,
        ]));
    }

}

In this way your code would be clear of low-level casting and validation. For this, I’ve made a middle-ware that, using reflection, detects and injects the parameters in the invoke method.

All you need to do is to add it to your configuration root:

'routing' => [
    'middleware' => [
        ApplicationFactory::ROUTING_MIDDLEWARE,
        Helper\UrlHelperMiddleware::class,
        \Web\MiddleWare\AuthenticationMiddleware::class,
        ParameterInjecter::class,
        // Disable the default ZF dispatcher
        //ApplicationFactory::DISPATCH_MIDDLEWARE,
    ],
    'priority'   => 1,
],

This middle-ware works out-ot-the-box with the scalar PHP values. If you want to use custom classes for the parameters your classes must have a static method named fromString or fromPrimitive that is called by the middle-ware.

 

You can install this middle-ware using composer:

composer require xprt64/injectable-router-middleware

You can find it on github at: https://github.com/xprt64/injectable-router-middleware

Auto-wiring for Zend Framework router