Define prefix MM to function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • drhowarddrfinedrhoward

    #1

    Define prefix MM to function

    I see a number of pages with functions like MM_somefunction (). Where does
    the MM_ come from? I don't see it in any books I'm studying.


  • rf

    #2
    Re: Define prefix MM to function

    drhowarddrfined rhoward
    [color=blue]
    > I see a number of pages with functions like MM_somefunction (). Where does
    > the MM_ come from? I don't see it in any books I'm studying.[/color]

    Dreamweaver. Usually for things like rollovers which are far better done
    with CSS anyway.

    MM means MacroMedia.

    --
    Cheers
    Richard.


    Comment

    • Dana Cartwright

      #3
      Re: Define prefix MM to function

      >I see a number of pages with functions like MM_somefunction (). Where does[color=blue]
      >the MM_ come from? I don't see it in any books I'm studying.[/color]

      I'll assume you're just getting started writing code, and forgive me if
      that's not true and I'm telling you something you already know...

      When you write a function, you can give it any name you want. The
      underscore character is a valid character to appear in a name. So you're
      free to call a function "foo_bar", for example, or "MM_FOO_BAR ", or
      whatever. In that sense, there's nothing special about a function whose
      name starts with "MM_", that is, it is not different from any other
      function.

      If you are writing functions that will be used by other people, and *in
      particular* if you are writing functions that other people will mix with
      their own functions, you need to avoid using a name that they are already
      using.

      So common names like "delete" or "upgrade" or "download" would be bad
      choices, because chances are those are already being used.

      So you could tack on '_QWOPT' to all your function names, hoping that nobody
      else in the world would do that, so your function names would never collide
      with theirs. So your 'delete' function becomes 'delete_QWOPT'. But, it's
      better to put something on the front, because then when you sort a list of
      functions into alphabetical order, all *your* functions will show up in a
      contiguous part of this list. So the Dreamweaver folks elected to use their
      company initials in this way, hence they name their functions 'MM_'.

      As an aside, there are various schemes for naming functions. Some people
      like to use short function names (like 'add', or 'lcd', or 'hook'). I, like
      a lot of people, prefer to use more descriptive function names. So, for
      example, if I have a function that appends one array on to another array, I
      might call the function 'appendarrays'.

      OK, but that's hard to read. So then some people capitalize the first
      letter of the names, so we get 'AppendArrays', which is easier to read.
      Others like lowercase and underscores, so we get 'append_arrays' (which is
      even easier to read, in my opinion, and may be easier to type). I'm in the
      latter camp.

      Evidently the people at Macromedia prefer the latter approach as well.
      Notice that they used uppercase, which is a common practice when mixing
      functions together from different sources...the assumption being that
      functions with uppercase letters in them are 'system' functions of some
      sort, while those with all lowercase are user functions.

      -Dana


      Comment

      • Michael Winter

        #4
        Re: Define prefix MM to function

        On Tue, 02 Nov 2004 12:08:43 GMT, Dana Cartwright
        <danapub2@weave maker.com> wrote:

        [snip]
        [color=blue]
        > If you are writing functions that will be used by other people, and *in
        > particular* if you are writing functions that other people will mix with
        > their own functions, you need to avoid using a name that they are
        > already using.[/color]
        [color=blue]
        > So common names like "delete" [...] would be bad [...][/color]

        Particularly as it's a reserved word, so an illegal identifier. :)
        [color=blue]
        > So you could tack on '_QWOPT' to all your function names, hoping that
        > nobody else in the world would do that, so your function names would
        > never collide with theirs.[/color]

        I would argue that the best method is to wrap your functions in an object.
        This means that apart from the object name itself, none of your functions
        pollute the global namespace.

        You can call the object anything you like. If it does clash with a name
        that the client wishes to use, they simply rename your object.

        How you construct that object may vary, depending upon the current
        circumstances. The pattern I've used frequently recently is:

        var identifier = (function() {
        /* Add local (private) variables and functions here. */

        return {
        /* Add members of the public interface
        * here using object literal notation:
        *
        * prop1 : 'a string',
        * prop2 : 15,
        * method1 : function() { ... },
        * method2 : function() { ... },
        * method3 : function() { ... }
        */
        };
        })();

        This allows you to create a structure like you would find in other
        languages where you separate the public and private methods.

        The idea of the code above is that you begin by creating an anonymous
        function (the outermost function expression). This creates a new scope
        block where you can add functions and variables. With the exception of
        things you choose, these entities will be unaccessible to code outside of
        this block.

        Next an object is returned using an object literal. The members of this
        object act as the public interface. If you wanted a function to be both
        public and private, and want to avoid referencing the containing object's
        name, you would do something like:

        var identifier = (function() {
        function local() {
        }

        return {
        member : local
        }
        })();

        Notice in both code snippets, the last line: })(); This calls the outer
        function, running the code it contains to create the object.

        In case you're concerned, this does work in old browsers like NN4.

        [snip]
        [color=blue]
        > As an aside, there are various schemes for naming functions. Some
        > people like to use short function names (like 'add', or 'lcd', or
        > 'hook'). I, like a lot of people, prefer to use more descriptive
        > function names.[/color]

        I tend to use more descriptive identifiers in demonstration code as it
        makes it easier to follow, but code that is for distribution has minimised
        names. This is for two reasons:

        1) The code is a "black box". You only need to access the interface, not
        the inner workings.
        2) It produces a smaller file which saves bandwidth.

        Why should a user have to download a heavily-commented, verbose set of
        code, when it could be but a few kilobytes.
        [color=blue]
        > So, for example, if I have a function that appends one array on to
        > another array, I might call the function 'appendarrays'.
        >
        > OK, but that's hard to read. So then some people capitalize the first
        > letter of the names, so we get 'AppendArrays', which is easier to read.[/color]

        I follow, in general, the Java naming conventions where:

        - Classes, or constructor functions in Javascript, begin with an
        uppercase letter.
        - Methods and variables begin with a lowercase letter
        - Constants (not that Javascript actually has them) are all in
        uppercase.

        Aside from constants, the identifers themselves use "camel notation":
        words within an identifier starts with a capital. This would make your
        identifer above, appendArrays.
        [color=blue]
        > Others like lowercase and underscores, so we get 'append_arrays' (which
        > is even easier to read, in my opinion, and may be easier to type). I'm
        > in the latter camp.[/color]

        A study was performed some time ago on code layout. I think neither
        underscored identifiers, nor "camel notation", was found to be more
        readable. It varied from person to person. The more critical factors were
        block indentation (the biggest) and line length. I don't remember if brace
        positioning was found to be important, or if operators should end a line
        or start a new one:

        blah +
        blah

        or

        blah
        + blah

        Of course, that example is misleading as long lines obsecure the
        operators. I prefer the latter.

        [snip]

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • Andrew Thompson

          #5
          Re: Define prefix MM to function

          On Tue, 02 Nov 2004 12:49:19 GMT, Michael Winter wrote:

          (snip)[color=blue]
          > blah +
          > blah
          >
          > or
          >
          > blah
          > + blah
          >
          > Of course, that example is misleading as long lines obsecure the
          > operators. I prefer the latter.[/color]

          Well there ya' go. I did not realise the second was valid.
          (but yes, it makes sense that it's easier to read).

          --
          Andrew Thompson
          http://www.PhySci.org/codes/ Web & IT Help
          http://www.PhySci.org/ Open-source software suite
          http://www.1point1C.org/ Science & Technology
          http://www.LensEscapes.com/ Images that escape the mundane

          Comment

          • Michael Winter

            #6
            [Important] Re: Define prefix MM to function

            On Tue, 02 Nov 2004 12:58:51 GMT, Andrew Thompson <SeeMySites@www .invalid>
            wrote:

            [snip]
            [color=blue][color=green]
            >> [...] obsecure [...][/color][/color]

            Why do I always write "obsecure"?

            Note to self: There's NO BLOODY e!
            [color=blue]
            > Well there ya' go. I did not realise the second was valid.
            > (but yes, it makes sense that it's easier to read).[/color]

            There are certain cases where no line terminators may appear between
            tokens, but that only applies to the postfix increment and decrement
            operators, and the continue, break, return, and throw statements.

            The former doesn't make sense anyway:

            identifier
            ++;

            but it's important to note that it would be treated as:

            identifier;
            ++;

            Notice the extra terminating semi-colon.

            return
            (expression);

            would be treated the same, so it should be written:

            return (expression);

            or

            return (
            expression
            );

            This is important for the pattern I showed in my first post. Changing

            return {
            // ...
            };

            to

            return
            {
            // ...
            };

            is invalid and result in returning undefined. I should have mentioned that
            earlier.

            Mike

            --
            Michael Winter
            Replace ".invalid" with ".uk" to reply by e-mail.

            Comment

            • Douglas Crockford

              #7
              Re: [Important] Re: Define prefix MM to function

              > There are certain cases where no line terminators may appear between[color=blue]
              > tokens, but that only applies to the postfix increment and decrement
              > operators, and the continue, break, return, and throw statements.
              >
              > The former doesn't make sense anyway:
              >
              > identifier
              > ++;
              >
              > but it's important to note that it would be treated as:
              >
              > identifier;
              > ++;
              >
              > Notice the extra terminating semi-colon.
              >
              > return
              > (expression);
              >
              > would be treated the same, so it should be written:
              >
              > return (expression);
              >
              > or
              >
              > return (
              > expression
              > );
              >
              > This is important for the pattern I showed in my first post. Changing
              >
              > return {
              > // ...
              > };
              >
              > to
              >
              > return
              > {
              > // ...
              > };
              >
              > is invalid and result in returning undefined. I should have mentioned
              > that earlier.[/color]

              JSLINT can detect and report these mistakes.


              Comment

              • Mark Preston

                #8
                Re: Define prefix MM to function

                drhowarddrfined rhoward wrote:
                [color=blue]
                > I see a number of pages with functions like MM_somefunction (). Where does
                > the MM_ come from? I don't see it in any books I'm studying.
                >[/color]

                Macromedia (the people who make DreamWeaver). Its their "code" for "we
                wrote this bit of JavaScript".

                Comment

                • Andrew Thompson

                  #9
                  Re: [Important] Re: Define prefix MM to function

                  On Tue, 02 Nov 2004 13:22:16 GMT, Michael Winter wrote:
                  [color=blue]
                  > On Tue, 02 Nov 2004 12:58:51 GMT, Andrew Thompson wrote:
                  >
                  > [snip]
                  >[color=green][color=darkred]
                  >>> [...] obsecure [...][/color][/color]
                  >
                  > Why do I always write "obsecure"?
                  >
                  > Note to self: There's NO BLOODY e![/color]

                  (chuckles) My theory? You're (sub-consciously) starting a trend.

                  Thanks for the extra detail (now snipped).

                  Thanks also to Douglas for pointing out that JSLint can determine
                  typos. in usage. That was a half-formed, but not asked, addendum
                  to my original comment.

                  --
                  Andrew Thompson
                  http://www.PhySci.org/codes/ Web & IT Help
                  http://www.PhySci.org/ Open-source software suite
                  http://www.1point1C.org/ Science & Technology
                  http://www.LensEscapes.com/ Images that escape the mundane

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Define prefix MM to function

                    Mark Preston wrote:
                    [color=blue]
                    > drhowarddrfined rhoward wrote:[color=green]
                    >> I see a number of pages with functions like MM_somefunction (). Where
                    >> does the MM_ come from? I don't see it in any books I'm studying.[/color]
                    >
                    > Macromedia (the people who make DreamWeaver). Its their "code" for "we
                    > wrote this bit of JavaScript".[/color]

                    s/wrote/dumped/
                    s/of/of not properly tested/


                    PointedEars
                    --
                    Chaos, panic, & disorder - my work here is done.

                    Comment

                    Working...