I also shared about Rails Assets, and asked how the guys handle pulling libraries into Rails app. JB says he’s given up on using gems for that, and just puts the files into the project. I’ll probably try that, too.

I talked about my struggles integrating AngularJS templates into a Rails app, which boiled down to me skipping a step or two following instructions on how to use the Angular-Rails-Templates gem.

I mentioned Postach.io, which is a blogging platform that allows us to maintain a blog by writing the posts as notes in Evernote. This is what I’m using for my musical blog, Sanctuary of Nevermore.

For my professional blog, www.lassala.net, which is hosted on WordPress, I’ve been using a blogging tool called Blogo, which allows me to write my drafts in Evernote, and then edit the posts and publish it using this tool.

Chocolatey https://chocolatey.org/George’s recommendation of a Machine Package Manager. Since I still do some work on Windows, I’ll check out this tool.

VimiumVimium is a Chrome plugin that adds VIM commands to your web navigation. I’ve been using it for several years now, mostly for the following feature: I hit the F-key, and then Vimium assigns a combination of letters to anything clickable on the page, so I can do all of my web navigation without using the mouse.

ConEmuGeorge mentioned this tool as a etter console for Windows: https://conemu.github.io/I’ll definitely check it out. I’ve been using Console2 for a long time, but ConEmu seems to be a lot better.

Emergent Task PlannerJB’s recommendation for a paper task planner. As much as I like doing everything electronically, I have started using paper for a couple of notes here and there (which I keep syncing it back into Evernote), just in order to try doing things differently. I may try out this task planner and see if it works with my flow.

ElixirJB shared a little of the awesomeness of Elixir’s pattern matching and how you can write some expressive code with it.

Together with good buddies JB and George (the duo who were with me at almost every meeting), we’ve held the Virtual Brown Bag for over two years. And now we’re back!

Back then we used to hold the meetings using Live Meeting, which was a problem for Mac users. It was also painful to turn the Live Meeting recordings into YouTube-compatible videos. Now we’re using Google Hangouts, which works for everyone, and automatically makes the recordings available on YouTube just a couple of minutes after the meeting is over.

You can check out the Virtual Brown Bag category on my blog to see what kind of things we’ve shared at our meetings. Lots of goodness, I can tell you that much!

Last week we’ve had our comeback meeting, just to see how Hangouts would work, and we took the chance to catch up and share a couple of things as well. Check it out! We’ll be meeting every Tuesday, at 12:30pm Central Time.

At this week’sVirtual Brown Bag, we’ve tackled mocks, stubs, Rhino mocks, and related things, since that was one of most voted suggestions from our folks VBBers. Mark Wilkinson had mentioned he could do a quick intro to Rhino since he had just presented on that topic, so that was great: the more people sharing, the better. Make sure to check out the notes and video.

I’ve also written an article on this topic for CODE Magazine a couple of issues ago, and here’s a video out of a presentation on the same topic that I did at Houston TechFest last year.

Please keep your suggestions coming, and vote for the ones that are out there. We won’t have a Virtual Brown Bag this Thursday, since it’s Thanksgiving and most people are going to be taking the day off, but we’ll back next week! Happy “oversized bird celebrations” for all of you.

It’s usually not easy to find good examples that explain the Liskov Substitution Principle (LSP) to developers. But really, how hard could it be? The definition is so simple:

“What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.”

Say what? I don’t know about you, but that kind of definition usually flies way over my head. Some people use the Rectangle versus Square example to explain the principle, which is a good one, but that doesn’t necessarily relate to things we normally do.

“Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.”

Recently we’ve run across a violation to that principle in a project. We have an interface defined like so:

It’s a very small interface that represents resources that can be loaded in memory, and persisted afterwards in case there were changes to it.

Let’s pretend we have the following implementations of that interface:

The actual implementation of those methods doesn’t matter here; just assume that the real implementation loads and persists application and user settings.

Somewhere in the application we have some way to retrieve a list of instances of implementations of that interface, kind of like this:

Some place else, we have a method that takes in a list of those objects, and call Persist on them:

And somewhere else we may use those methods, like so:

Everything works great, until a new class is added to the system in order to handle, let’s say, some “special settings”:

It looks like the Load method does whatever stuff it’s supposed to do in order to handle loading these special settings. The Persist method, on the other hand, throws a NotImplementedException. As it turns out, those settings are meant to be read-only, therefore, the Persist method can’t really do anything.

The system is told to load the new class along with the other ones that implement that same interface:

Now when we run the app everything should still work fine, until we hit the code that tries to persist all of those loaded resources, at which point we get a big and fat “NotImplementedException”.

One (horrible) way to address this would be to change the SaveAll method:

If the specific resource being processed is of type SpecialSettings, we skip that one. Brilliant! Well, maybe not. Let’s look back at a simplified definition of the Liskov Substitution Principle:

“An object should be substitutable by its base class (or interface).”

Looking at the SaveAll method it should be clear that “SpecialSettings” is NOT substitutable by its “IPersistedResource” interface; if we call Persist on it, the app blows up, so we need change the method to take that one problem into consideration. One could say “well, let’s change the Persist method on that class so it won’t throw an exception anymore”. Hmm, having a method on a class that when called won’t do what its name implies is just bad… really, really bad.

Write this down: anytime you see code that takes in some sort of baseclass or interface and then performs a check such as “if (someObject is SomeType)”, there’s a very good chance that that’s an LSP violation. I’ve done that, and I know so have you, let’s be honest.

Another great definition for LSP comes from this motivational poster that the folks at Los Techies put together:

So what’s the fix?

The fix here is to tailor the interface based on what each client needs (Interface Segregation Principle, or ISP). The LoadAll method (which is one client of those classes) is really only concerned about the “Load” capability, whereas the “SaveAll” method (another client) is only concerned about the “Persist” capability. In other words, these is what those clients need:

The SaveAll takes in something tailored to its needs, IPersistResource’s, and the same goes for LoadAll, which only cares about ILoadResource’s (in the real app, the actual instantiation of these classes happen somewhere else). This is what the granular new interfaces look like:

Yup, it’s pretty much the former “IPersistedResource” split up into two separate interfaces, tailored to their client needs. Both the UserSettings and ApplicationSettings classes can implement these two interfaces, whereas the SpecialSettings class would only implement ILoadResource; this way, it isn’t forced to implement interface members it can’t handle.

Very often people ask what’s the most appropriate number of members in an interface. In the real world example I gave here, the original interface had only 2 members; one could say that was small enough, but as it turns out, it wasn’t. The IPersistedResource interface was doing too much (both loading *and* persisting stuff) based on the clients that use its implementers. In the end, two interfaces with a single method on them fit the bill a lot better. Interfaces with single responsibility? Yup, Single Responsibility Principle (SRP); as with design patterns, sometimes SOLID principles go hand in hand together.