News for hackers. Stuff that matters.
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by shawabawa3 on Monday January 27, 2014 @12:20PM (#7131596)
While it's a good idea, I feel like it should rename with real words, or not rename at all. From the example:

  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,c
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by anorwell on Monday January 27, 2014 @01:39PM (#7132165)
I forked the original to address this [1]. Here's a sample:

    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-words
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by michaelmior on Monday January 27, 2014 @06:25PM (#7134124)
While I find this humorous (which I assume was the goal), I think using common development terminology could be worse than complete jibberish since you start to apply irrelevant meaning when reading the beautified code.
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by angersock on Monday January 27, 2014 @06:11PM (#7134063)
Wow, it's like an EnterpriseBridgeAdaptor for JavaScript!
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by zertosh on Monday January 27, 2014 @12:27PM (#7131648)
I'm the author. Since "a", "b", "c" get recycled by different scopes, it makes it really hard to figure out which "a" you're looking that. By having unique names, you can easily spot where one variable is used exclusively. I was going to use a dictionary but I didn't want the tool to be language specific or run into unsavory words.
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by nathan_long on Monday January 27, 2014 @01:10PM (#7131963)
>> I didn't want the tool to be language specific or run into unsavory words

Good 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".

Re:Show HN: Beautify-with-words unminifies JS with unique wo... by billyhoffman on Monday January 27, 2014 @01:21PM (#7132036)
Why don't you prefix variables based on their usage in the code?

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.

Re:Show HN: Beautify-with-words unminifies JS with unique wo... by joshklein on Monday January 27, 2014 @01:25PM (#7132063)
Or perhaps a consistent "namespace", e.g. with a standard prefix prepended to a simple noun.
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by cynwoody on Monday January 27, 2014 @07:25PM (#7134362)
You could use first names as your dictionary. The US Census Bureau has lists† (in the form of frequency tables) of male and female given names.

†http://www.census.gov/genealogy/www/data/1990surnames/names_...

Re:Show HN: Beautify-with-words unminifies JS with unique wo... by prezjordan on Monday January 27, 2014 @12:28PM (#7131655)
I'm going to have to disagree. Fake words are still better than single letters. It's much easier to scan for "vublu" in a segment of code than it is to scan for "v"
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by zellyn on Monday January 27, 2014 @12:29PM (#7131671)
The problem with a,b,c is that the minifiers aggressively re-use the same identifiers when scoping rules allow them to.
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by lanna on Monday January 27, 2014 @05:42PM (#7133913)
It is a lot easier once you've figured out what a particular variable stands for to do a global search and replace for "vublu" than "a".
Re:Show HN: Beautify-with-words unminifies JS with unique wo... by thatthatis on Monday January 27, 2014 @06:13PM (#7134069)
That actually makes sense, it is more "grepable" even if it is less easy to reason about. I find it a lot easier to reason about "a" because my brain doesn't try to reason by association -- what could vublu mean, why would they name it vublu?