flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Harui <aha...@adobe.com>
Subject Re: FlexJS XML string assignment
Date Sun, 07 Aug 2016 14:52:17 GMT
On 8/7/16, 1:55 AM, "Harbs" <harbs.lists@gmail.com> wrote:

>To sum up:
>
>There are a number of issues involved here.
>
>What started with a concern about implicit type conversions on XML turned
>into a much broader issue.
>
>In ActionScript, when you assign any object type to  typed variable of a
>primitive type (or really any type), it is implicitly converted. Here’s a
>list of the possible type conversions that I could think of:
>
>int: possible values — any integer
>unit: possible values — any positive integer
>Number: possible values — a number or NaN
>Boolean: possible values — true or false
>String: possible values — a string or null
>Object: possible values — an object or null
>“*” (untyped): possible values — undefined, null or any object

Thanks for the summary.


>
>Practically, you VERY rarely want implicit conversions of Objects to
>strings. I think the average client would be doing toString() or some
>other conversion manually. I think XML is an exception to this because
>E4X blurs the distinction between different types and E4X relies pretty
>heavily on implicit conversions.
>
>What I noticed in my code is that by making XML and XMLList classes
>pretend they are strings and numbers, that solves virtually all the
>implicit conversions I had. The biggest exception to that was comparisons
>between XMLLists converted to strings. As it turns out, these comparisons
>were done exclusively in function calls. If function parameters are
>converted to their types, that solves every single case I’ve encountered
>so far. Logically, assuming that function parameters have the correct
>types make sense that it should be more rigid than normal variables.
>
>In a purist sense, it makes sense to ensure type safety, but practically,
>you will not always want it. If you have a tight loop which sets
>variables many thousands of times, you’re not going to want the extra
>cycles type testing your variables. Also, adding code for type checks
>everywhere will inflate code size.

Isn't it possible to optimize your inner loop code with getters on the
objects and local variables so the compiler doesn't think it has to do
this conversion?  Maybe show a code example so we have something concrete.

Thanks,
-Alex

Mime
View raw message