Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Maps all use Array instead of Object  (Read 14770 times)
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« on: February 16, 2011, 04:57:04 »

All maps like "proxyMap", "commandMap", "viewMap", "instanceMap" etc in PureMVC Standard and Multicore version use an Array instead of an Object when Array is not needed.

It even lead to bugs like http://forums.puremvc.org/index.php?topic=107.0

Rem: Don't forget not to use Vector instead of Object as it's Flash 10> only.
« Last Edit: February 16, 2011, 05:09:33 by Tek » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 17, 2011, 09:29:36 »

This has been addressed before.

My answer for *why* it PureMVC/AS3 uses arrays instead of objects is here: http://forums.puremvc.org/index.php?topic=473.msg2029#msg2029

The point about the oddity bug you referenced is more than offset by the fact that you can't use reserved words for properties on objects: http://forums.puremvc.org/index.php?topic=473.msg2029#msg2029

-=Cliff>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #2 on: February 18, 2011, 02:33:14 »

Reading both the post you referenced and the bug report I link to I must say that I agree with "wez" and that I'm even more convinced that there is more reasons using Object instead of Array.

You will agree that Array has many more properties than Object so errors can happen many more time than using Object with {key:value} and Object native properties aren't so used in command/mediator/proxy names where thos of Array are really commons :

Where Object only has :

:

Object.hasOwnProperty(name:String):Boolean
Object.isPrototypeOf(theClass:Object):Boolean
Object.propertyIsEnumerable(name:String):Boolean
Object.setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
Object.toString():String
Object.valueOf():Object

Array has :

:
Object.hasOwnProperty(name:String):Boolean
Object.isPrototypeOf(theClass:Object):Boolean
Object.propertyIsEnumerable(name:String):Boolean
Object.setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
Object.toString():String
Object.valueOf():Object
Array.length:uint
Array.concat(... args):Array
Array.every(callback:Function, thisObject:* = null):Boolean
Array.filter(callback:Function, thisObject:* = null):Array
Array.forEach(callback:Function, thisObject:* = null):void
Array.indexOf(searchElement:*, fromIndex:int = 0):int
Array.join(sep:*):String
Array.lastIndexOf(searchElement:*, fromIndex:int = 0x7fffffff):int
Array.map(callback:Function, thisObject:* = null):Array
Array.pop():*
Array.push(... args):uint
Array.reverse():Array
Array.shift():*
Array.slice(startIndex:int = 0, endIndex:int = 16777215):Array
Array.some(callback:Function, thisObject:* = null):Boolean
Array.sort(... args):Array
Array.sortOn(fieldName:Object, options:Object = null):Array
Array.splice(startIndex:int, deleteCount:uint, ... values):Array
Array.toLocaleString():String
Array.toString():String
Array.unshift(... args):uint
« Last Edit: February 18, 2011, 05:29:12 by Tek » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: February 20, 2011, 12:04:22 »

It's not just the property names of Object that cause collision - it is ALL AS3 lexical and syntactical keywords and reserved words. These include:

as, break, case, catch, class, const, continue, default, delete, do, else, extends, false, finally, for, function, if, implements, import, in, instanceof, interface, internal, is, native, new, null, package, private, protected, public, return, super, switch, this, throw, to, true, try, typeof, use, var, void, while, with, each, get, set, namespace, include, dynamic, final, native, override, static, abstract, boolean, byte, cast, char, debugger, double, enum, export, float, goto, intrinsic, long, prototype, short, synchronized, throws, transient, type, virtual, volatile

Try doing a

:
var o:Object = {continue:"50"};
Can't do it, won't compile. So now you can't have a notification called "continue"?

Consider someone porting their PureMVC app to AS3 from another language where perfectly ordinary verbs like: continue, export, delete, import, do and use were all notification names. Suddenly they all break - because they're reserved words in AS3?

I think we'll stick with arrays if for no other reason than this.

The other undeniable reason is that nothing is broken. Changing it means a lot of work. Not for me personally, but for all the users of PureMVC who will undoubtedly assume they need to upgrade to the latest and greatest or worry about being left on an 'old release'. They'll release new versions of their apps and will inevitably find that some of their notifications that used to work no longer work. Maybe they won't find out about this until production time when edge case notifications that are rarely sent are suddenly triggered by users, etc. Or maybe they'll discover it right away because the first time they run it with the new version of the framework, they find out that the delete notification is causing a runtime error. They'll either drop back to the previous version or they'll change the note name and create a new release, grumbling all the while.

Folks, I realize the software world is one of constant change. But that doesn't mean it has to be that way. If something works, let it be. Please.

Cheers,
-=Cliff>
« Last Edit: February 20, 2011, 12:23:31 by puremvc » Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #4 on: February 20, 2011, 12:24:42 »

In JavaScript as in ActionScript you can do:
:
var o:Object = { "continue": 15, "break": 25};

Which leads to the possibility to do this:
:
var notification1:String = "continue";
var notification2:String = "break";
var o:Object = {};
o[notification1] = 50;
o[notification2] = 10;
trace( o[ notification1 ] );
trace( o[ notification2 ] );

We always use map this manner in PureMVC core, property are set dynamically not the static way, setting a property "continue" as a String in the registerCommand (as an example) method is not a problem at all.

And in languages like Java, C#, JavaScript PureMVC already use Map instead of Arrays.

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: February 20, 2011, 12:28:42 »

Arrays in AS have had the associative array (map) functionality at least since AS2. The use of Array over object was always the more obvious choice for me.

-=Cliff>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #6 on: February 20, 2011, 01:34:18 »

Cliff, if creating a minor version update to PureMVC is only a problem of time for you, I totally understand that. You already warn the community about this lack of time on a blog post on the PureMVC blog last or previous year. But as you may know this always a good thing to think on how to manage future evolution of a community framework.

As I already suggested you on Twitter, a good solution for PureMVC would be to use a community solution like Github to manage its multiple sources and documentation. A lot of very popular projects use it now. Projects always keep track of the root node project on each clone it was created or it depends on. This means that each project would reference www.puremvc.org/project url as its main url and www.puremvc.org will still continue to centralize the PureMVC knowledge. Plus forums and the help you give on it are invaluable.

So, if time is the only problem and you're still looking for a person who can help to manage PureMVC I can be this person helping on migrating sources to Github if needed. I'm pretty sure that slowly moving sources five by five or something like that would help in involving more and more users on the project.

On Github there's a feature named "pull request" which is simply the way users can ask the proprietary of a projects to inject its modifications on the project. If we continue the way we have managed PureMVC since its start with a proprietary for each project, this could easily be managed.

On Github there are even page templates for wiki which can replace projects page that is so hard for you to manage here on PureMVC.

This is just an idea. But my own involvement on the project recently has probably prove you that I really need and care for PureMVC to evolve the best.
« Last Edit: February 20, 2011, 01:36:08 by Tek » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: February 20, 2011, 02:06:34 »

@Tek, the reason I push back so strenuously on changes to the core framework is not that I don't have time. I always have time for fixing things that are broken. The reason I push back is that a lot of people out there rely on the stability of the framework and I don't want to jerk them around.

As PureMVC was maturing, there were a few cases of making changes that seemed simple that cascaded into more bugs. In at least one case, the bug instigating the change was of a completely theoretical nature, that upon reflection (after 2 releases trying to restore order) wasn't even a real problem. I firmly believe that when something works, there's no need to fix it.

I do agree that migrating to github might be worthwhile in the end. I've never used git myself, and I've even heard you complain about it though. SVN works and is pretty widely used. I do agree that the current repo situation is less than fantastic, primarily because I have to send requests to Codesion to copy a Trac template each time I create a new repo. So, I'm iffy on github. I'll look more into it, or eventually be hired to do work for someone who uses it, I'm sure.

If we ever did such a migration, though we'd also have to take the opportunity to change over the license. People have complained about the choice of open source license and want it changed to something like GPL or MIT. Who ever thought that saying 'it's free do whatever you want with it as long as you attribute me' was such a big deal. Every class in all ~100 or so PureMVC repos has to be changed in addition to their license.txt files. I can't imagine handling every project without planning this in. That's something else that's been pushed back on, primarily because of the huge amount of effort required to visit every project and change all the files.

Maybe we could raise the money for it on kickstarter.com. All the folks who want PureMVC to be available on GitHub, AND the folks that want the license changed could donate to the cause. (This is only a half-joke, it might actually work).

-=Cliff>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #8 on: February 20, 2011, 02:48:29 »

The plus with Github is that you can use it even using an SVN client (read and write now) if you're more used too. But as we discussed on Twitter, the advantage of Github is not Git, even if a lot of people seems to find a lot of reasons to love it, nothing more convince me to change for Git on my personal projects but Github.

I can help to change license too. I did this batch editing so many times while creating demos or ports for PureMVC that I already know the process. It's not so hard to batch process license headers in file as in most cases developers have simply copied the same headers on each file of the project. A simple batch on each project with a cautious verification file after file in  a text editor immediately show any error.

A short but good Git/Github learning track and tests would be necessary before moving a lot of projects not to create the same errors multiple time. At least a call for some guy who can help on this in realtime (like IM) would be a great plus. I perfectly can imagine to have a deep look into how to manage that a week-end.

The recommended start for Git seems to be : http://progit.org/book/ especially for me as there is French translation of the book which is written by one of the guy under Github. I'll try to read this asap.
« Last Edit: February 20, 2011, 02:58:44 by Tek » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #9 on: February 21, 2011, 08:44:00 »

I'd definitely want to test the waters with it first. Perhaps I'll create an account and see what it's like. If you create a dummy repo to learn, can you delete it?

-=Cliff>
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #10 on: February 21, 2011, 09:50:53 »

You can create and delete it, no problem. I already have started to learn from ProGit since yesterday I told about it. ;)

From what I saw what need more test is the Organization functionality for our needs.

What is quite less cool with Github is what they charge by month for so few users and few repositories. I don't know how this could be managed... probably by creating more than one account for PureMVC ? Not sure how to do, there's probably other community project that found a workflow for this. I'm currently investigate it in.

Logged
Pages: [1]
Print