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)

    Via Twitter. From the book The Gray Lady Winked, photographed by Michael Shermer: Here's the tweet that the paragraph references (took a while…

  • (no subject)

    To unscramble an egg, by the way, would be a closer idiomatic parallel to ungrinding ground meat, and in spite of Julia Ioffe, is just as dark, blunt…

  • (no subject)

    Thought of this phrase today for some reason, then thought whether it exists in English (putting toothpaste back into the tube came to mind), then…

  • 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.