2014.08.05

Type check is a code smell

Will try to be brief, so it might not be clear unless you are experienced, will add more references at the end to make things clearer and maybe revise this subject later… - Time is a very limited resource nowadays.

How I got into this conclusion?

JavaScript is a dynamic (and confusing), language, the way inheritance and typeof and instanceof works is not clear to most developers:

// JSWTF
typeof [1, 2] // 'object'
typeof null // 'object'
typeof 'foo' // 'string'
typeof new String('foo') // 'object'
'foo' instanceof String // false
new String('foo') instanceof String // true
new String('foo') instanceof Object // true

And things gets way more complicated when you have objects that come from different documents/frames (they are created using different constructors, so instanceof doesn’t work)… So because of that I started to avoid typeof and instanceof and ended up realizing how cleaner the code becomes when you avoid type checking.

PS: I know that we can use Object.prototype.toString.call() for type checking, I’m mainly saying that most type checks are a bad idea, doesn’t matter what is the implementation.

Read more…


2014.04.13

Constructors should not cause side effects

Going to talk about something simple that took me a while to figure out I was doing it wrong. Don’t know when I realized it was a big mistake, I just know that it is something I’ve been trying to avoid for a while.

To begin, I’m not the first one to get into this conclusion. Many people before thought about the same thing, it is even one of the JSLint rules (“Do not use ‘new’ for side effects”). The thing is, I don’t think most people know the reason why this should be avoided; so let me explain why.

Constructors are not verbs

I believe that methods should be named as verbs, to make it clear that they perform actions.

new XMLHttpRequest doesn’t fire the request, new HTMLDivElement() shouldn’t append it to the document, … – Elliott Sprehn

Read more…


2014.01.12

Callbacks, Promises, Signals and Events

Sometimes I get involved in discussions on twitter and Facebook related to development. This week I ended up sending a link to an old(ish) twitter thread explaining when to favor Promises/Callbacks and when to use Signals/Events for asynchronous operations. I think this topic deserves further explanation.

Read more…


2013.12.22

Death of RSS and rise of sensationalist headlines

I have no data to backup my theory; it’s just a trend that I observed in the past years. The amount of headlines like “10 places you should visit before you die”, “15 best jQuery plugins of the year”, “best video you will watch today” keeps increasing; I blame the rise of social media and the death of RSS readers.

It’s sad to admit it; but if a headline isn’t sensationalist, the likelihood of someone reading it and sharing it, is not as high.

Read more…


2013.12.11

Being a noob

I have no idea what I am doing

I was reading some of my old blog posts, and also some code that I wrote during the past few years, and it’s really hard to not notice that I was a total noob.

Don’t call it Impostor Syndrome, I’m talking about a different feeling. It’s more a realization that over the past few years I improved A LOT, both my writing and coding skills. Nowadays I can spot mistakes and misconceptions that I couldn’t see before. It’s also important to remind that being a noob is totally subjective and that there are different levels of noobness.

Read more…


  1. 1
  2. 2
  3. 3
  4. ...
  5. 15