Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Archived Topics for the old Version 3.0 JavaScript Menu
Forum Topic: Click to view post
Last Updated: Wednesday July 18 2012 - 06:07:44

Coding style

Poster: jperret __at__
Dated: Thursday March 14 2002 - 16:09:42 GMT

I've just discovered the Milonic DHTML Menu and in the browser
it looks quite good.

I've been reading the source code and I must say
there are a few things that are done in ways that
I don't understand, and some that seem dangerous
to me. I must admit I'm not very knowledgeable in
cross-browser support, so please tell me if I say
something stupid.

For a start, most variables (either global or local)
are never declared. As every Javascript doc I've seen
recommends variable declaration, I wonder why this
has not been done ?

Another mystery : why does menu_array.js (in the samples I've
seen) always have :

function addmenu(){menunum ;menus[menunum]=menu;}
addmenu(menu=["mainmenu", ...]);


Unless I'm missing something huge, the addmenu(...) line
above is equivalent to :

menu=["mainmenu", ...];

And it would be cleaner (IMHO) to write it this way, without
using a global variable :

function addmenu(newmenu){menunum ;menus[menunum]=newmenu;}
addmenu(["mainmenu", ...]);

I have tested this change and it works fine for me. Is there
a reason that this shouldn't work on some browsers ?

I have several other suggestions but that will be enough
for now :)


Re: Coding style

Poster: justinwayne __at__
Dated: Tuesday February 19 2002 - 2:53:18 GMT

It's all to do with keeping the file size as small as possible.

If I can get away without declaring variables I will if it saves on space. As you can see it all works fine.

And the reason for the way addmenu works is to keep the system as simple as possible. That's what the users want and it seems to work fine too.


Re: Coding style

Poster: equuleus __at__
Dated: Tuesday February 19 2002 - 16:42:30 GMT

Andy, thanks for your prompt reply.

I can understand you're concerned about file size.
However from an engineering point of view, there are
some tradeoffs between space and robustness/maintenance
that shouldn't be made lightly (IMHO).

Actually in your code I'm less concerned with the lack of
variable declaration than the number of global variables with
extremely plain names, such as a, am, oa im, om, ... I am quite
fearful of the consequences of integrating your script with
other scripts that may be using these variables, even for
temporary storage. That is the main reason that is preventing
me right now from using your menu.

I've looked at HierMenus too and though there are lots of things
I don't like in their system, they have prefixed (most of) their
variables, which looks much safer.

Perhaps you would be interested in a tool that would allow
you to work on clearly written(indented, commented, etc.) code
and release densely packed code to the client ?

I've experimented with the C preprocessor (cpp) and I think it can be
very useful. Here's an example of what you could do :

#define MENU_NAME 0
#define MENU_TOP 1
#define MENU_LEFT 2
#define MENU_WIDTH 3

while(eval("" m))
mr ="menu" m ",";
tmenu=eval("menu" m);
m ;

When processed through cpp, the #define lines simply disappear,
and MENU_NAME gets replaced with 0.
A slightly more intelligent tool could remove unneeded line
breaks and indentation, etc.

What do you think of this approach ? I think it is the only viable
way to reconcile sane engineering practices with the need to
keep file size down to a minimum.

As for you point on addmenu() : I don't understand, really. The
format I have proposed is both :
1) shorter and simpler than the current
2) fully backwards-compatible


Re: Coding style

Poster: webmaster __at__
Dated: Tuesday February 19 2002 - 17:36:44 GMT

I'm finishing up a .NET server control as we speak that fixes these coding style problems. If you're not familiar with .NET server controls, think of them as COM objects for now.

I've created a very object-oriented approach to creating the menus where the menu, the menu items, and the menu links are all different objects. It's MUCH easier and full proof to create a very large menu with the controls I'm building.