Show HN: Beautify-with-words unminifies JS with unique words for variable names
github.com
github.com
function(bedad, latay, vublu) {
if (!adag(this, "on", bedad, [ latay, vublu ]) || !latay) return this;
this._events || (this._events = {});
var cyem = this._events[bedad] || (this._events[bedad] = []);
bedad, latay and vublu don't make it much easier to remember which variable is which than just using a,b,cGood thoughts. However, "beedip" is foreign to everyone, whereas if you pick a language, it's at least native to some people.
Also, you could have maybe 50 known inoffensive words; there probably aren't more than that many unique variables in a scope. Things like "hat" and "bread".
function(a,b,c) -> function(arg1_cat, arg2_tree, arg3_carrot)
for(i=0; i< 10; i++) -> for(counter1=0; counter1 < 10; counter1++)
var a -> var global_pants;
You could do this reasonably well with regular expressions/find+replace.
To be more sophisticated you would use a a tokenizer/parser and rename based on the identifiers location in the AST nodes. I did something similar a few years ago for a commercial product that included a JavaScript beautifier and our customers loved it.
†http://www.census.gov/genealogy/www/data/1990surnames/names_...
var strategy = moduleInterfaceFactory.Events = {
on: function(strategyFacade, strategyFactoryDecorator, interfaceFacade) {
if (!flyweight(this, "on", strategyFacade, [ strategyFactoryDecorator, interfaceFacade ]) || !strategyFactoryDecorator) return this;
this._events || (this._events = {});
var strategyPattern = this._events[strategyFacade] || (this._events[strategyFacade] = []);
strategyPattern.push({
callback: strategyFactoryDecorator,
context: interfaceFacade,
ctx: interfaceFacade || this
});
return this;
}
[1] https://github.com/ANorwell/beautify-with-wordsMy specific question would be whether using longer gibberish variable names is any more helpful than using short names. I don't know if 'quinis' is better than 'h' or 'tenmiey' is better than 'a'? I guess at the very least it should provide a much easier find and replace once you figure out what the variable should actually be named.
Alternatively, an option to pass in a partial mapping for variable names you've already figured out.
I think it would be even cooler as a Firefox extension -- open up a .min.js file in one tab, hit your button, and get a new tab with the beautified js. I don't know anything about FF extensions, but since this is written in JS in the first place, it seems doable.
(Or alternatively, it would also be cool as a standalone site, just paste the URL or uglified JavaScript in a box, and get the pretty version.)
Edit: If you want to use your own bookmarklet, feel free to start off with this: void(open("http://beautifywithwords.com?url=" + location,'_self',''))
Edit2: http://jsbeautifier.org/ has some similarities to this (and integrates with various browsers, editors, etc.) but I don't think it replaces variable names. Perhaps it would make sense to integrate your code into it as an extra feature?
Almost every codebase is filled with english verbs and nouns. They are one of the primary tools for making source code readable by humans, not just machines.
Very cool tool.
It wasn't that difficult. I remember not knowing how things would translate to my own language, but from the code, I'd know what they meant.
Now that I think back, my first steps in English were probably made in programming and cartoons; before my mum realised I enjoy languages and signed me up for advanced lessons.
So, it's nothing weird. I'd like to think programmers have a higher-than-average IQ, which makes understanding and learning easier. Maybe I'm just biased! :-)
The biggest benefit of being an english native speaker is that most resources on the web are in English(docs,articles,videos). And since being a developper is about learning new things all the time, it's easier to learn about new technologies or tools when one can read english articles or documentations.
My english (writing and speaking) is horrible but i force myself to read english docs on a regular basis,because it's just mandatory today.
Here's the output for ga.js: https://gist.github.com/yahelc/00299f2e4a3c07cafa1a