Lint only touched files with Webpack

Recently I had to add a linter on a project in which the codebase was never linted before. I am talking about a big codebase in which a team have worked on it for years already.

Obviously, the amount of errors thrown from the linter, was such a big number to become an useless information.

With my team mates, we agreed on run the linter only on the “touched” files: the behaviour we wanted was to get the linter parsing every file that gets changes.

Continue reading

Posted in Javascript | Tagged , , , , , | Leave a comment

Be careful with your fix!

I think many times the code grows wrong (also) because of some wrong solutions… Little example: yesterday I was sending an email by Gmail, an attachment was included to the mail.

Correctly, I wasn’t able to send the mail (clicking the “send” button) until the attachment wasn’t completely uploaded.

Continue reading

Posted in Uncategorized | Tagged , , | Leave a comment

Code readibility: little zoom on Implements from MooTools

I would like to spend a few lines about the Implements feature, from MooTools.

Like many other frameworks / toolkits, MooTools provides utilities for DOM manupulation, effects, etc… but what i really enjoy is the way it provides writing code, by its Class function. From Wikipedia:

Every JavaScript framework has its philosophy, and MooTools is interested in taking full advantage of the flexibility and power of JavaScript in a way that emphasizes greater modularity and code reuse.MooTools accomplishes these goals in a way that is intuitive to a developer coming from a class-based inheritance language like Java with the MooTools Class object.

It is not the goal of this post to write about how i see the code readibility improved by using Class; just click here for my own Class clone to know more.

What i would like to talk about here is the Class’s feature called Implements: it is a tool to reuse code, many times confused with Extends, and it is considered confusing from many sources.

Continue reading

Posted in Code readibility, Javascript, MooTools | Tagged , , , , , , , | Leave a comment

Vim hot stuff: marks

In the (new) “vim hot stuff” section, i would like to post about those Vim’s features that, when you meet them the first time, you think: “UAO! That is cool! How did i survive without it so far?”. The best example, for me, is the option “:set relativenumber” (from the 7.3); i think i was waiting for it from my beginning with Vim and i have realized how much i was waiting for it the first time that i have met it!

About the feature i am going to introduce here, i was googling for “how to select multi line in visual mode quicker” and i was led to this solution:

… I know that some people use marks extensively to make visual selections. For example, if I’m on line 5 and I want to select to line 35, I might press ma to place mark a on line 5, then :35 to move to line 35. Shift + v to enter linewise visual mode, and finally `a to select back to mark a.

Continue reading

Posted in Tips, vim hot stuff | Tagged , , , , , , , , | Leave a comment

Git: how to rewrite the branch history

Quick tip for those git users that, like me, make a lots of commits in their working branch and want to keep only the last one, before send the branch to production. Yes, the idea is to use this method before send the branch to production: it is not a good idea, to change the history of a project that has many persons working on it!

It is true that, by this method, I resetted the GitHub history of some personal projects, when they were already pushed: i didn’t get any problems, because i was the only person to commit on those projects!.

Continue reading

Posted in Programming, Tips | Tagged , , , , , | Leave a comment

Coding tips: accessing the data structure

I think it is really important keep the code more general and flexible as possible; one rule, that i would like to introduce here, is to use the right level of abstraction when accessing the data structure elements, trying to centralize the read / write operations on them.

Many times i saw pieces of code that work directly on the data structure: that is a problem when that data structure, at some point, gets changed and then the developers are forced to manually update every line of code involved with it.

Continue reading

Posted in Javascript, jQuery, Programming, Tips | Tagged , , , , , , , | Leave a comment

A “Class” function to define classes in Javascript with MooTools like syntax

Updated the 08/02/2013

I really enjoy to organize my Javascript code as objects and get profit by using inheritance.

“Approaching Javascript as Javascript and not as Java”, i read that so many times; Javascript is / can be OOP and i always thought about OOP as something good for code reusing.

I think the OOP nature of Javascript is all around the prototypal chain; a constructor function is the only way to define objects that achives these two points:

  1. members on the prototypal chain
  2. the constructor property and the instance of operator working as intended

What i am going to introduce here is a function Class that uses another syntax to achieve the same, native result than the constructor functions; i am avoiding closures as class pattern because they don’t store members on the prototype (but they are a good way to define private members).

I think that the Class function makes the syntax less redundant and verbose, moving the focus from the function to the prototype. Also, it provides tools for code reusing: Javascript has native inheritance but not native tools to use it.
A more expressive syntax to write objects in OOP approach, as Class function tries to provide, is in my opinion a good way to help the development.

Continue reading

Posted in Javascript, jQuery, My code, Programming | Tagged , , , , , , | 7 Comments