Andrey (azangru) wrote,

Trying another programming language is a good way to highlight what one has always taken for granted in the language they are most familiar with. Same goes for frameworks in other languages. It’s both annoying and instructive.

Today I scrambled together a very simple php server in Silex to make an api that would use the Syllable package for hyphenating texts. I did that, because I didn’t like hypher, the closest Node alternative. (I still don’t like it, but at least I have since realized that I’ve been using hypher wrong, so it can probably do the job too).

I spent several hours trying to set up a simplest routing in Silex. All because I assumed that it would behave like Node’s Express — that is, when you have a router handling /foo, you could mount onto it a child router that would handle /foo/bar, like so (in pseudocode):

app.mount(`/foo`, fooRouter)

fooRouter.mount(`/bar`, barRouter)

barRouter.match(`/`, function() { do some stuff} )

Which is how Express would work. And Silex works similarly, except you can’t make barRouter.match(`/`) match the /foo/bar route. Because, wouldn’t you know, barRouter.match(`/`) means that there needs to be a trailing slash in the path. So it would match /foo/bar/ with a slash in the end, but not /foo/bar without the slash. The /foo/bar route will still be handled by the fooRouter.

For those who come to Silex after Express, this is insane! Meanwhile, the developer of Silex says: of today, it is not possible to define a callback for /foo when mounting a route collection under /foo. I can see the limitation of the current behavior but I can't think of a possible solution that does not feel hackish.

So a pattern that "feels hackish" to a php developer is natural for Node developers (and I guess for Ruby developers as well). I wouldn’t have even imagined that there could be another opinion on how a router should behave!

  • (no subject)

    Sanjay Gupta on Joe Rogan: yes, I agree, they shouldn't have said horse dewormer; no, I don't know why they did; no, they shouldn't have done that;…

  • (no subject)

    To the future me: I keep returning in my mind to the simple idea in this talk about containing React component's logic in a custom hook and having a…

  • (no subject)

    I've been listening to The Boys produced by the Graphic Audio. Better than the film; more irreverent; the Butcher character is even more profane and…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.