You're right, but SQL is the same way, and you don't see most developers complaining.
The other thing is that you can't easily build dynamic queries your way. The
same problem can be seen in the LINQ demos for C# 3.0.
And you won't lose too much time. ActionStep has very informative exception
messages throughout. Unlike Macromedia's framework, we make extensive use of
exceptions to tell you exactly what has gone wrong.
I know there are other ways to do the same thing, but I think there are too
many benefits here to pass up.
Scott
-----Original Message-----
From: [EMAIL PROTECTED] on behalf of Nicolas Cannasse
Sent: Mon 1/23/2006 11:32 AM
To: Open Source Flash Mailing List
Cc:
Subject: Re: [osflash] ActionStep predicate support (for filtering
arrays)
> Let's say we have an NSArray containing "person" objects structured as
> follows:
>
> {firstName:String, lastName:String, age:Number, canDrive:Boolean}
>
> Now, let's say in your application, you allow the users to filter by all
> sorts of criteria. Suppose you wanted to display all drivers over 60.
> The predicate string to describe this criteria would be as follows:
>
> "canDrive == true AND age >= 60"
>
> To actually filter the array, here's what you'd do:
>
> var pred:NSPredicate = NSPredicate.predicateWithFormat("canDrive == true
> AND age >= 60"); var driversOver60:NSArray =
> people.filteredArrayUsingPredicate(pred);
>
> And that's it. Pretty cool, huh?
Yes, but it's fully untyped.
What if you make a typo "candrive" instead of "canDrive" or mistake the
flag (using "cantDrive"). What if you apply the predicate to the wrong
Array ? what if you rename one of your objet fields ? All of theses will
be runtime errors. There are not so bad, but if they happen late in the
development of your application, they can make you loose significant
time debugging it.
In haXe for instance, you could be able to fully type it :
class Filter<T> {
static function filterArray(
pred : T -> Bool,
arr : Array<T>
) : Array<T> {
var arr2 = new Array();
var i = 0;
var l = arr.length;
while( i < l ) {
var elt = arr[i];
if( pred(elt) )
arr2.push(elt);
i++;
}
return arr2;
}
}
Then you can write your predicate like this :
var pred = function(p : NSPerson) { return p.canDrive && p.age >= 60; };
Also, you're not restricted to some syntax, since you can use the whole
language as syntax, and even call methods :
var pred = function(p : NSPerson) { return p.birthday() == today; };
You could do the same with MTASC, but with less type checks.
My two eurocents ;)
Nicolas
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org
<<winmail.dat>>
_______________________________________________ osflash mailing list [email protected] http://osflash.org/mailman/listinfo/osflash_osflash.org
