So here's the thing... you write code so it is readable and easy to debug. Recently I have taken on projects where I wanted to adapt libraries. I was able to find the source code online and thing about what needed to be done to adapt to my own purposes.
React-Image-Map being one. Really cool library and useful tool when you want to create a map. But there is a deprecated library that had some other functions that we thought were cool and wanted to implement.
So after having a few projects where Ruby Gems needed some sprucing up, I decided "Hey, we can just looked in the node modules and adjust from that, it's easier since it's already there". For those of you playing along at home, if you do
bundle install --deployment you can get the same thing as node_modules. You can edit as needed there.
Boy was I wrong. So never really thinking twice about running across gems or modules that were called prettifier or uglifier or minifier. I never really thought twice about what they were doing. Prettifying JSON data made sense to me because it would read the different levels of a hash. So make sense of traversing data from something that was a string parsed into something the computer understands is convenient for the machine as well. Quick note that I will get back to... the guy who started minifying was also the guy who made JSON popular. After venting my frustration and then reading about him, I have decided to stop worrying and love the minifier.
So what just happened? As I mentioned earlier it gets rid of the white space. But it also renames the variables to single letters. This makes sense because a variable can be anything, it's just a representation of a place in memory. 26 letters is perfectly fine because the process of minimization deals with scope and closure so it can make sense of it. It also gets rid of comments, because everyone knows it's a terrible idea to read the comment section (sorry PEP 8).
So two things that came up from my research in this. Douglas Crockford may be my new hero. He is the guy who started minification back in 2001 with JSMin. He also started JSON, which makes sense that these two things can be related. You usually have to run a function to make JSON readable, so the creator was well versed in how to make things neat and tidy and then later on extrapolate the ideas. I can't decide whether his house would look like the Container Store™ or a department store on Black Friday. So why is he my hero? Other than the fact I personally love finding nested data. For so many reasons actually. Growing up I played the game Maniac Mansion it was hilarious and fun, the follow up Day of the Tentacle was equally as amazing. He was responsible for the game getting to nintendo. The game was originally made for computer (that's where I played it) and it was a little risque, so he was in charge of censorship. You can read about some objections Nintendo had here.
The second thing I learned is that he made his JSMin open-source..... ish. He added a clause that it is required to be "The Software shall be used for Good, not Evil". Something you would normally gloss over, but the lawyers of Google made him find another hosting service in 2009... conveniently at the same time Google came up with their Closure Toolkit which is similar in function, also for a company whose slogan is Don't be Evil, it is kind of amusing.
He has also had that requirement in other programs he has written, JSLint being a hilarious one of note. The story goes that IBM wrote to him asking if they could get a special license because they were sure they weren't going to be evil but couldn't really say anything about their customers. Very ominous lawyering considering the companies past. But they were doing their due diligence as lawyers tend to do. He however wrote back to them saying “I give permission for IBM, its customers, partners, and minions, to use JSLint for evil.”. So I really appreciate him taking a stand and having a sense of humor about the world.
However, the evil clause may have some real possible litigation uses. In the past couple of months there have been several node packages that had malicious software in them. Which, as someone who just went through a one line uglified piece of code, I can understand how you could easily hide something and not have anyone notice. But if they used JSMin or any of Mr. Crockford's work, that would be a violation of agreement open to legal interpretation. So from me struggling to add a hover effect to a library, this became a history lesson and creating a fanboy moment for me...