0

I wonder why pepole use letters for names of arguments of function (i see that mostly in JS). For example that function:

function showMessage(e, t, i) {
    var n = e.find(".admin-message");
    n.empty().removeClass("error success").addClass(i ? "success" : "error");
    if ($.isArray(t)) {
        $.each(t, function(i,item) {
            n.append(item+"<br>");
        });
    } else {
        n.html(t + "</br>");
    }
    n.fadeIn("fast")
}

This is short example and it's easy to remember, but i see much longer fuctions with e.g. six arguments (a, b, c, d, e, f, g). Why people use letters, not for example camelCase name?

5
  • 2
    This looks like minified code, it wasn't written by a person. Commented Jun 30, 2015 at 21:43
  • …though a machine would have properly indented the code. Commented Jun 30, 2015 at 21:45
  • well, coders are lazy, and one letter is all that's required. aside: they're "parameters", not "arguments". Commented Jun 30, 2015 at 21:45
  • This is just poorly written code. Variable names should be meaningful to humans, and there's no reason for parameters to be different. Exceptions can be made for common, simple parameters like e for event, i for index, etc. Commented Jun 30, 2015 at 21:52
  • @Bergi ... though minified code would be all on one line. Commented Jun 30, 2015 at 21:53

2 Answers 2

3

They minify the code, so it takes less time to load when the User enters to the website.

You can write a normal function and try to minify it with this simple online tool:

http://jscompress.com/

It will turn this:

function fact(num){
   if(num<0)
      return "Undefined";
   var fact=1;
   for(var i=num;i>1;i--)
     fact*=i;
    return fact;
}

Into this:

function fact(n){if(0>n)return"Undefined";for(var r=1,f=n;f>1;f--)r*=f;return r}
Sign up to request clarification or add additional context in comments.

Comments

1

Javascript is usually (or should be) concantenated, uglified and minified before being deployed to production.

Concantenated - All source files are merged into a single code file. Uglified - Variables, parameters and function names are rewritten so they are shorter and more difficult to read. Minified - All redundant space characters are removed.

All 3 actions above are performed to make the source smaller and thus faster to load (sometimes also paired with IoC). Uglification is also done for the purpose of 'encoding' proprietary algorithms, making it more difficult to reverse engineer.

What you posted is probably code that was uglified for the purpose of shrinking the size of the code file and was very likely not done manually, but rather as part of the build/distribution process.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.