June 11th, 2017

(no subject)

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:

...as 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)

Но ведь это чудовищная пошлоинтеллигентская хня, которой обычно автор, выступаючи на эхе, например, не предается:


(no subject)

Tagged template literals!

They have been around for several years, yet I’ve never had an occasion to actually use them, and thus had no idea what that syntax meant. Apparently they are pretty mainstream in certain communities (e.g. ones that use graphql or styled components).

Example from Relay:

Relay.QL`
  fragment on Greetings {
    hello,
  }
`;


Example from styled components:

styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;


Article on MDN.io

(no subject)

Random quote:

I had not blogged for 3 years. Many plausible excuses, but the big reason is that it is easier to dash a tweet or a short incidental social media post than to structure a complex argument, which uses mental resources that I need full time at work.

It’s interesting how the word "blog" ("to blog") has narrowed its meaning in English to somewhat lengthy and well-thought-out pieces of writing, quite different from the etymological meaning of "web log". That’s something that doesn’t seem to have happened for the Russian borrowing. Yet.