473,378 Members | 1,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.
Jul 23 '05 #1
9 2977
rf
drhowarddrfinedrhoward
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.


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

MM means MacroMedia.

--
Cheers
Richard.
Jul 23 '05 #2
>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.


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
Jul 23 '05 #3
On Tue, 02 Nov 2004 12:08:43 GMT, Dana Cartwright
<da******@weavemaker.com> wrote:

[snip]
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" [...] would be bad [...]
Particularly as it's a reserved word, so an illegal identifier. :)
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.
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]
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.
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.
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.
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.
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.


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.
Jul 23 '05 #4
On Tue, 02 Nov 2004 12:49:19 GMT, Michael Winter wrote:

(snip)
blah +
blah

or

blah
+ blah

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


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
Jul 23 '05 #5
On Tue, 02 Nov 2004 12:58:51 GMT, Andrew Thompson <Se********@www.invalid>
wrote:

[snip]
[...] obsecure [...]

Why do I always write "obsecure"?

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


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.
Jul 23 '05 #6
> 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.


JSLINT can detect and report these mistakes.

http://www.crockford.com/javascript/lint.html
Jul 23 '05 #7
drhowarddrfinedrhoward wrote:
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.


Macromedia (the people who make DreamWeaver). Its their "code" for "we
wrote this bit of JavaScript".
Jul 23 '05 #8
On Tue, 02 Nov 2004 13:22:16 GMT, Michael Winter wrote:
On Tue, 02 Nov 2004 12:58:51 GMT, Andrew Thompson wrote:

[snip]
[...] obsecure [...]


Why do I always write "obsecure"?

Note to self: There's NO BLOODY e!


(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
Jul 23 '05 #9
Mark Preston wrote:
drhowarddrfinedrhoward wrote:
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.


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


s/wrote/dumped/
s/of/of not properly tested/
PointedEars
--
Chaos, panic, & disorder - my work here is done.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Morgan Cheng | last post by:
Hi, In my program module, there are some Constants should be defined to be integer key value of std::map. In the module, methods of a few classes will return std::map containing value indexed by...
30
by: Xah Lee | last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee, 2006-03-15 In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”....
1
by: Ken Newman | last post by:
I need to code my SOAP Header to have a prefix for the SOAP Header namespace. The server I communicate sends replies with the SOAP Header namespace and xml tags qualified with a prefix and the...
3
by: subramanian100in | last post by:
Consider the code fragment: vector<intcontainer; container.insert(container.begin(), 10); int& ref = *--container.end(); From this, it looks like we can apply prefix decrement operator to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.