These slides are from a short talk I gave at work for my coworkers and especially for our junior developers.

Overall, the slides are probably more of a conversation starter than they are useful in themselves.

Choosing code and evaluating libraries

How do you choose between using an existing library and coding it yourself? How do you evaluate whether someone else's code is good or not?

We live in a golden age of open source libraries and components

There has never been more options for open source and other ready made components

There's a gem or plugin or library or whatever for almost anything you might want

Whether it's RubyGems or React components or whatever, it seems like there's an existing solution to almost every problem.

How do you choose what to use?

This makes it ever mnore important to exercise good judgement in choosing wisely.

Choosing well is important because most likely switching later will be painful

Switching costs are very real and the bigger the surface area of the added dependency the greater the cost will be.

Should you use a 3rd party library or code it yourself?

The first question to ask is whether to code it yourself or to add a 3rd party dependency.

Doing the work yourself will usually take more time but at the same time you maintain full control.

What are the options?

Secondly, what are the ready-made options out there? How well do they match your requirements?

Evaluate the options

Once your know what's out there, you can evaluate the options…

  • Is there good test coverage?
  • Is the documentation good?
  • Is it being used by others?
  • Is it actively maintained?
  • How much code is there?
  • Read the code: does it look good?

Maybe just vendor it?

If there's very little code, it might be better to just vendor or copy it into your project. Make sure to include the license and attribution details with the code.

The fastest code is no code

Remember that the fastest and most reliable code is no code. No code also has the fewest bugs and security issues.

Obviously we need some amount of code to accomplish what we want to do, but the less code we use to reach our goals the better.

There's a cost to code beyond the mere bytes

Added code exacts a cost beyond the mere bytes transferred over the network or on disk.

Adding code always has a cost

Bytes code added can, arguably, be the most expensive bytes you can add to your project.

For example for JS in the browser

For an in-depth example, see The Cost Of JavaScript by Addy Osmani.

tl;dr: less code = less parse/compile + less transfer + less to decompress

As a general rule, the less code you have the faster and more reliable it will be.

You may decide that the cost is worth it, but be aware of it

This doesn't mean that you should just give up on writing code or using libraries. It just means that you should be cognizant of the cost.

Summary

Above all, be aware of the cost of adding code.

When adding 3rd party code, evaluate its quality. Is the library production quality? Is it being used by other people? Is it being maintained?

Tools

Find out what libraries other people are using… Check on Stack Overflow, Google, in tutorials, etc.

Tools continued

Also, Ruby Toolbox has recently been revitalized. And of couse searching on GitHub is a good tool as well.

And that's it for these slides.