R – Is it a bad idea to get rid of the mx: in your Flex code

actionscriptapache-flex

I am a newbie at Flex, and I don't like the way you have to write the namespace mx: for every control declaration you write. It makes the code cluttery. I would like to write:

<Panel ...

rather than

<mx:Panel ...

I tried writing

xmlns="http://www.adobe.com/2006/mxml"

for the top level element instead of

xmlns:mx="http://www.adobe.com/2006/mxml"

In the top level declaration. This work to an extent, but broke some existing code. For one, XML data that are defined in the document are all appended with aaa: as the namespace during runtime. I've also noticed other issues in my very small sample program.

Is there a way to do this that works, or is this a lost cause? And some background information on why would be appreciated.

Update: Thanks all for the replies, but I would like to have heard from someone who actually tried this and thought it was important. Although most of you told me it was a bad idea, I was not discouraged. I got a couple of programs working this way smoothly now. And plan to do this in all my flex apps. One trick seemed to work for me although I can't claim it'll work universally. If you need separate namespaces within your doc, take, HTTPService parameters for example, you could create a namespace within that element like so:

    <HTTPService id="service" url="http://blah.com"
        method="POST" result="gotResult(event)">
        <request xmlns:p="*">
            <p:param1>p1</p:param1>
            <p:param2>p2</p:param2>
        </request>
    </HTTPService>

Hope this helps someone. I am very happy with how clean my code is now, almost as clean as a normal html file. As for people who think writing mx: throughout your code is clearer and what not, I disagree completely. I think languages that require you to repeat the same character sequence excessively in your code – which you should consider a document – have design flaws. Here's an analogy for you: how would you like it if you were reading an article on Barack Obama, and every single sentence contained the words 'Barack Obama', that would get pretty tiresome wouldn't it?

Best Answer

I think that removing the mx namespace will almost certainly cause you trouble with name conflicts as your project gets larger.

Personally I think the mx namespace makes the code clearer rather than more cluttered, especially if you have component based flex development or a lot of your own controls. Having owned a large flex code base for the last two years I find the mx namespace unobtrusive, especially when you have custom objects embedded inline such as item renderers.

My recommendation (unscientifically asserted) is to put up with it, especially if you are finding issues when removing it. I bet you'll stop noticing it after a while.

Related Topic