Real software engineers don’t reinvent libraries that already exist, they build something better on top of them.
It is 2020 and I don’t know a single software engineer who doesn’t use third-party libraries in their work. Which makes sense. Why rewrite and maintain what has already been written and maintained?
But even though libraries are mostly free to use, they are not cost-free. One of the biggest costs, which applies to libraries developed by others and those developed internally by someone in your company, is time needed to learn to use it.
Try new libraries via the Browser Console
The easiest and fastest way I know to get your hands dirty with a new library? The unassuming browser console.
Let’s say that you need a method that will take any given object and reverse the key-value pairs.
invert method in lodash. The example looks like it does exactly what you need.
At this point, you can try it for yourself in several ways before incorporating it into your code. From least to most effective:
- Download the package. Import the library, write some code, and run it via the command line
- Create your own HTML file. Add a
- Use it directly in the browser console. Open the console and use the method via the global variable (eg.
Using the third approach will save you a lot of time especially if, after testing the method, you realise that it doesn’t do exactly what you need. You’d save time from running the package (un)install commands like
npm install and deleting files you’ve created just for testing, to name a few things.
In the examples below I use the Chrome developer tools’ console tab to access the global variable on various libraries’ documentation pages.
Lodash library example
Load Lodash docs, open console, use the `_` global variable for rapid testing!
Moment.js library example
Moment.js is probably the most widely used library for manipulating and formatting date and time on both the front and back end.
Similary for Moment.js, you can rapidly test methods from the global `moment` variable loaded on the console
I sometimes also use the browser console for testing built-in functions like
reduce and Web APIs like
fetch , especially when I’m in a quick and hacky mindset, trying to figure out if something is possible.
I used to do this a lot on something like repl.it, which is also a REPL console like the browser developer tools’ console but with more features like autocompletion and saving. At some point though, it occurred to me that it might be easier for some smaller testing to just do it in the browser console.
(In case you’re wondering what REPL is, you can learn more in this post: What is REPL?)