Loading ...
Sorry, an error occurred while loading the content.

Enhancement Request: Identifier length restriction

Expand Messages
  • abyssoft@ymail.com
    Reasoning Identifiers of only 1 or 2 Characters can lead to errors in thought and poor readability of code. I have a preference for identifiers that consist of
    Message 1 of 11 , Jul 2, 2010
    • 0 Attachment
      Reasoning

      Identifiers of only 1 or 2 Characters can lead to errors in thought and poor readability of code. I have a preference for identifiers that consist of 3 or more characters and they are rarely that short.

      An alternate enhancement is for support of single and double letter identifiers when listed in /*global*/.
    • abyssoft@ymail.com
      Just noticed that the highlighted is partially supported at least at the global level. But does not catch nested vars. So having the Identifier length limits
      Message 2 of 11 , Jul 2, 2010
      • 0 Attachment
        Just noticed that the highlighted is partially supported at least at the
        global level. But does not catch nested vars.
        So having the Identifier length limits would be good to hunt for those
        left in code by peers.

        --- In jslint_com@yahoogroups.com, "abyssoft@..." <abyssoft@...> wrote:
        >
        > Reasoning
        >
        > Identifiers of only 1 or 2 Characters can lead to errors in thought
        and poor readability of code. I have a preference for identifiers that
        consist of 3 or more characters and they are rarely that short.
        >
        > An alternate enhancement is for support of single and double letter
        identifiers when listed in /*global*/.
        >



        [Non-text portions of this message have been removed]
      • pauanyu
        What about this (very) common construct: for (var i = 0; i
        Message 3 of 11 , Jul 3, 2010
        • 0 Attachment
          What about this (very) common construct:

          for (var i = 0; i < foo.length; i += 1) {}

          I agree that very short identifiers are generally a bad idea, but I also think there are a couple exceptions (like the above).

          --- In jslint_com@yahoogroups.com, "abyssoft@..." <abyssoft@...> wrote:
          >
          > Reasoning
          >
          > Identifiers of only 1 or 2 Characters can lead to errors in thought and poor readability of code. I have a preference for identifiers that consist of 3 or more characters and they are rarely that short.
          >
          > An alternate enhancement is for support of single and double letter identifiers when listed in /*global*/.
          >
        • abyssoft@ymail.com
          That is why I would like it as a switch/option not a requirement. I would write for (var i = 0; i
          Message 4 of 11 , Jul 4, 2010
          • 0 Attachment
            That is why I would like it as a switch/option not a requirement.

            I would write

            for (var i = 0; i < foo.length; i += 1) {}

            as

            var fooIndex;
            for (fooIndex = foo.length -1 ; fooIndex + 1 ; fooIndex -= 1) {
            //Loop Content even if only a one liner.
            }

            I never declare vars in loops, or in the setup of a loop.

            --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
            >
            >
            >
            > What about this (very) common construct:
            >
            > for (var i = 0; i < foo.length; i += 1) {}
            >
            > I agree that very short identifiers are generally a bad idea, but I also think there are a couple exceptions (like the above).
            >
            > --- In jslint_com@yahoogroups.com, "abyssoft@" <abyssoft@> wrote:
            > >
            > > Reasoning
            > >
            > > Identifiers of only 1 or 2 Characters can lead to errors in thought and poor readability of code. I have a preference for identifiers that consist of 3 or more characters and they are rarely that short.
            > >
            > > An alternate enhancement is for support of single and double letter identifiers when listed in /*global*/.
            > >
            >
          • Michael Mikowski
            Hi All: On a bit of a tangent, there are no sigils in javascript, so therefore we use RPN to indicate data types. So my implementation would look something
            Message 5 of 11 , Jul 4, 2010
            • 0 Attachment
              Hi All:

              On a bit of a tangent, there are no sigils in javascript, so therefore we use RPN to indicate data types. So my implementation would look something like this:

              var
              ary_foo = [ 'bing','bang','boom'],
              idx_foo
              ;

              for ( idx_foo = 0; idx_foo < ary_foo.length; idx_foo++ ){ }

              We have a comprehensive list of prefixes we currently use, if anyone is interested.

              Feedback and suggestions are welcome :)

              Cheers, Mike




              ________________________________
              From: "abyssoft@..." <abyssoft@...>
              To: jslint_com@yahoogroups.com
              Sent: Sun, July 4, 2010 3:11:36 PM
              Subject: [jslint] Re: Enhancement Request: Identifier length restriction


              That is why I would like it as a switch/option not a requirement.

              I would write

              for (var i = 0; i < foo.length; i += 1) {}

              as

              var fooIndex;
              for (fooIndex = foo.length -1 ; fooIndex + 1 ; fooIndex -= 1) {
              //Loop Content even if only a one liner.
              }

              I never declare vars in loops, or in the setup of a loop.

              --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
              >
              >
              >
              > What about this (very) common construct:
              >
              > for (var i = 0; i < foo.length; i += 1) {}
              >
              > I agree that very short identifiers are generally a bad idea, but I also think there are a couple exceptions (like the above).
              >
              > --- In jslint_com@yahoogroups.com, "abyssoft@" <abyssoft@> wrote:
              > >
              > > Reasoning
              > >
              > > Identifiers of only 1 or 2 Characters can lead to errors in thought and poor readability of code. I have a preference for identifiers that consist of 3 or more characters and they are rarely that short.
              > >
              > > An alternate enhancement is for support of single and double letter identifiers when listed in /*global*/.
              > >
              >




              [Non-text portions of this message have been removed]
            • pauanyu
              As long as it s an optional switch, I m fine with that. I can see why that would help some people, especially in a team.
              Message 6 of 11 , Jul 5, 2010
              • 0 Attachment
                As long as it's an optional switch, I'm fine with that. I can see why that would help some people, especially in a team.

                --- In jslint_com@yahoogroups.com, "abyssoft@..." <abyssoft@...> wrote:
                >
                > That is why I would like it as a switch/option not a requirement.
                >
                > I would write
                >
                > for (var i = 0; i < foo.length; i += 1) {}
                >
                > as
                >
                > var fooIndex;
                > for (fooIndex = foo.length -1 ; fooIndex + 1 ; fooIndex -= 1) {
                > //Loop Content even if only a one liner.
                > }
                >
                > I never declare vars in loops, or in the setup of a loop.
                >
                > --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@> wrote:
                > >
                > >
                > >
                > > What about this (very) common construct:
                > >
                > > for (var i = 0; i < foo.length; i += 1) {}
                > >
                > > I agree that very short identifiers are generally a bad idea, but I also think there are a couple exceptions (like the above).
                > >
                > > --- In jslint_com@yahoogroups.com, "abyssoft@" <abyssoft@> wrote:
                > > >
                > > > Reasoning
                > > >
                > > > Identifiers of only 1 or 2 Characters can lead to errors in thought and poor readability of code. I have a preference for identifiers that consist of 3 or more characters and they are rarely that short.
                > > >
                > > > An alternate enhancement is for support of single and double letter identifiers when listed in /*global*/.
                > > >
                > >
                >
              • Cheney, Edward A SSG RES USAR USARC
                I do not see the value in a minimal length requirement for identifiers even if that requirement is optional. What problems does this actually prevent? JSLint
                Message 7 of 11 , Jul 5, 2010
                • 0 Attachment
                  I do not see the value in a minimal length requirement for identifiers even if that requirement is optional. What problems does this actually prevent? JSLint already catches undeclared variables and so forth regardless of the length of such. Really, what this looks like to me an abstract arbitrary name replaced by a longer name that is just as much abstract and arbitrary. In my opinion this fix merely sounds like an attempt to make code for reader friendly, which is a false expectation from such a requirement as expanding length by no means implies the longer length identifier is any more relevant a name.

                  Austin Cheney
                  http://prettydiff.com/
                • abyssoft@ymail.com
                  Austin, Your reply looked rather vitriolic to my eyes. If it is optional why such disdain? For me I have found that with short identifiers in a long procedure
                  Message 8 of 11 , Jul 5, 2010
                  • 0 Attachment
                    Austin,

                    Your reply looked rather vitriolic to my eyes. If it is optional why such disdain?

                    For me I have found that with short identifiers in a long procedure I am quite prone to accidental reuse of them in a manner that introduces bugs. By forcing myself to use longer identifiers I can also be more assured that I have not left in debug code, as that is the only time I would wish to use short identifiers. Under the use of these conditions I would find it of great benefit.

                    As for abstract arbitrary names length, and casing can help. Personally I always attempt to make it as clear as possible the purpose of the identifier in it name. On the rare occasion this proves difficult I make sure to add documentation.

                    For me personally it is exceedingly annoying to encounter code that has nothing but 1 to 2 char identifiers and no or poor documentation. I always wish to leave code in a better designed and documented state then when I first encountered it so that those who come after me, including myself at a later point, have an easier time modifying/correcting/adding.

                    --- In jslint_com@yahoogroups.com, "Cheney, Edward A SSG RES USAR USARC" <austin.cheney@...> wrote:
                    >
                    > I do not see the value in a minimal length requirement for identifiers even if that requirement is optional. What problems does this actually prevent? JSLint already catches undeclared variables and so forth regardless of the length of such. Really, what this looks like to me an abstract arbitrary name replaced by a longer name that is just as much abstract and arbitrary. In my opinion this fix merely sounds like an attempt to make code for reader friendly, which is a false expectation from such a requirement as expanding length by no means implies the longer length identifier is any more relevant a name.
                    >
                    > Austin Cheney
                    > http://prettydiff.com/
                    >
                  • Marc Draco
                    Austin may be vitriolic, but he has a point. Code Complete by Steve McConnell is my bible and it has some interesting things to say on single-character
                    Message 9 of 11 , Jul 6, 2010
                    • 0 Attachment
                      Austin may be vitriolic, but he has a point.

                      Code Complete by Steve McConnell is my bible and it has some interesting
                      things to say on single-character identifiers.

                      Personally, I only ever use single-character vars in short loops. For a
                      single iterator, I tend to use "n" (which betrays my beginnings in an
                      early BASIC); and I would generally eschew i, j, k for nested loops
                      unless there's a very good reason - i and j are so easy to confuse due
                      to "confirmation bias".

                      x & y (and z) are a special case also - these are handy for short loop
                      iterations when co-ordinate systems are in use.

                      Where speed isn't paramount, I've found a short object can be very
                      helpful. Using X and Y as an example, let's say I need two versions of
                      each, I might create two literal, local objects like this:

                      var old = {};
                      var cur = {};

                      and initialise some variables

                      old.x = 0;
                      old.y = 0;
                      cur.x = old.x +10;
                      cur.y = old.x +10;

                      Any operations could conceivably use "with" on these but that has
                      problems all of its own. Personally I never use it.

                      This is far clearer than using very long names, is very easy to type and
                      less error prone because we're grouping related variables. Of course,
                      your mileage may vary.
                    • Michael Mikowski
                      Sure James. Cut and paste from our standards document: All arguments to a function have a master prefix, arg_ . Prefixes for compound variable types prefix
                      Message 10 of 11 , Jul 6, 2010
                      • 0 Attachment
                        Sure James. Cut and paste from our standards document:

                        All arguments to a function have a master prefix, 'arg_'.

                        Prefixes for compound variable types

                        prefix
                        variable type (vtype)
                        obj_ full object with methods
                        hash_ object as associative array
                        ary_ array
                        elem[type]_ dom element object; type is optional

                        $
                        jquery object


                        Prefixes for scalar variable type
                        prefix
                        scalar type (stype)
                        count_ Integer counter
                        idx_ Integer loop or array index
                        idint_ Integer interval id
                        idto_ Integer timout id
                        int_
                        Integer, general

                        ms_ Integer millisecond
                        num_
                        floating point number, general

                        px_ Integer pixel units
                        str_ string, general

                        sw_ boolean switch (true or false)
                        Examples:

                        A single scalar might be px_screen_x.

                        If the variable is compound then the prefixes should be strung together, e.g. ary_px_screen or hash_px_screen.

                        var fnRenderScreen = function ( arg_hash_px_screen ){...};

                        If a function takes multiple named arguments, we use a single input hash called arg_hash_spec, e.g:

                        var fnRenderScreen = function ( arg_hash_spec ){...};

                        called like so:

                        ret = fnRenderScreen({ sw_overlay : true, px_left : 10, px_top: 250, px_width: 150, px_height: 150 });

                        Hope that helps :)

                        Cheers, Mike




                        ________________________________
                        From: James Friedman <james.william.friedman@...>
                        To: z_mikowski@...
                        Sent: Mon, July 5, 2010 3:40:50 AM
                        Subject: Re: [jslint] Re: Enhancement Request: Identifier length restriction

                        Hello Mike,


                        I am interested in the prefixes that you use. I find the use of
                        prefixes to be invaluable in keeping track of what-is-what - But then
                        I do often suffer from "Teflon of the brain - nothing sticks..."


                        Thank you,

                        - James

                        On Mon, Jul 5, 2010 at 12:53 AM, Michael Mikowski <z_mikowski@...> wrote:
                        >
                        >
                        >
                        > Hi All:
                        >
                        > On a bit of a tangent, there are no sigils in javascript, so therefore we use RPN to indicate data types. So my implementation would look something like this:
                        >
                        > var
                        > ary_foo = [ 'bing','bang','boom'],
                        > idx_foo
                        > ;
                        >
                        > for ( idx_foo = 0; idx_foo < ary_foo.length; idx_foo++ ){ }
                        >
                        > We have a comprehensive list of prefixes we currently use, if anyone is interested.
                        >
                        > Feedback and suggestions are welcome :)
                        >
                        > Cheers, Mike
                        >
                        > ________________________________
                        > From: "abyssoft@..." <abyssoft@...>
                        > To: jslint_com@yahoogroups.com
                        > Sent: Sun, July 4, 2010 3:11:36 PM
                        > Subject: [jslint] Re: Enhancement Request: Identifier length restriction
                        >
                        > That is why I would like it as a switch/option not a requirement.
                        >
                        > I would write
                        >
                        > for (var i = 0; i < foo.length; i += 1) {}
                        >
                        > as
                        >
                        > var fooIndex;
                        > for (fooIndex = foo.length -1 ; fooIndex + 1 ; fooIndex -= 1) {
                        > //Loop Content even if only a one liner.
                        > }
                        >
                        > I never declare vars in loops, or in the setup of a loop.
                        >
                        > --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
                        > >
                        > >
                        > >
                        > > What about this (very) common construct:
                        > >
                        > > for (var i = 0; i < foo.length; i += 1) {}
                        > >
                        > > I agree that very short identifiers are generally a bad idea, but I also think there are a couple exceptions (like the above).
                        > >
                        > > --- In jslint_com@yahoogroups.com, "abyssoft@" <abyssoft@> wrote:
                        > > >
                        > > > Reasoning
                        > > >
                        > > > Identifiers of only 1 or 2 Characters can lead to errors in thought and poor readability of code. I have a preference for identifiers that consist of 3 or more characters and they are rarely that short.
                        > > >
                        > > > An alternate enhancement is for support of single and double letter identifiers when listed in /*global*/.
                        > > >
                        > >
                        >
                        > [Non-text portions of this message have been removed]
                        >
                        >


                        --
                        --------------------------
                        Television and the media culture have replaced thoughtfulness with
                        entertainment. We are being converted from a critically minded
                        inquisitive population enjoying informed discourse to a nation of
                        passive retards.


                        [Non-text portions of this message have been removed]
                      • Cheney, Edward A SSG RES USAR USARC
                        ... Beautify the code using a JSLint white space compatible algorithm. Then perform the following replacements: For functions: - Manually change the name of
                        Message 11 of 11 , Jul 6, 2010
                        • 0 Attachment
                          > For me personally it is exceedingly annoying to encounter code that
                          > has nothing but 1 to 2 char identifiers and no or poor documentation.

                          Beautify the code using a JSLint white space compatible algorithm. Then
                          perform the following replacements:

                          For functions:
                          - Manually change the name of the function where it is declared
                          - Find and replace on the following after ensure that each of the
                          following is not in quotes:
                          + space + variable name + left paren
                          ex: " a("
                          + space + variable name + comma
                          ex: " a,"
                          + space + variable name + right paren
                          ex: " a)"
                          + space + variable name + right square brace
                          ex: " a]"
                          + space + variable name + right curly brace
                          ex: " a}"

                          For arrays:
                          - Same as above except find and replace on a left square brace
                          instead of opening paren

                          For object literals
                          - Same as above except find and replace on a left curly brace instead
                          of opening paren

                          For value literals (strings and numbers)
                          - Same as above except find and replace on a space, instead of an
                          opening paren

                          You could write a JS application to do all of this for you. This would
                          be the best bet because you are not going to influence how other people
                          write code their own code. The only code that you can effectively
                          influence is the code under your own responsibility.

                          Austin Cheney
                          http://prettydiff.com/
                        Your message has been successfully submitted and would be delivered to recipients shortly.