Skip to content
Aug 31 2009 / alecmce

Vector – Annoying Naming Conventions

When Adobe released the Flash Player 10 last year, it facilitated a new class, a strongly-typed array: Vector.<T>. I suppose we should all be grateful; now we can finally type arrays, leading to more robust code. I don’t feel very grateful, though. Adobe has given me a headache.

In Geometry the word “vector” has a clear meaning: a vector describes a translation in space. To differentiate from other uses of the word, Wikipedia offer the terms Euclidean, Spatial or Geometric Vector. We recognise this use of the word because every single Flash coder understands the distinction between vector graphics and raster (or bitmap) graphics.

I have been working on a Geometric library recently (my as3voronoi library), and have found the need to create an interface to encapsulate a translation in Cartesian space. What will I call it? It’s a vector, but “Vector” is going to cause a lot of headaches, because Adobe’s new Vector class is in the default namespace.

Which leads me to an utterly futile question: why on earth would they call their strongly-typed array class “Vector”? Why not facilitate the strong-typing of Arrays, since Array is the existing term? Untyped Arrays could be considered functionally equivalent to Array.<*> or Array.<Object>. I realise that Adobe cannot change this decision now it has been made, but why did they do it in the first place?

The only answer that I can see is that the vector class is in the C++ standard template library as a one-dimensional array. Was the decision made on the basis that if it’s good enough for C++, then it’s good enough for Flash? I hope not, because the Array class is not like the C++ array, and I don’t see “bitset”, “deque”, “list”, “map”, “queue”, “set”, or “stack” anywhere in the Flash library. Why adopt the C++ convention in just this context?

Flash has a different context to C++. Flash is a word used to describe a player that uses ActionScript and a vector drawing tool rolled into one. Surely the word “vector” has particular significance for the users of Adobe technology?

So what do I call my vector interface? “Vector2D”? “EuclideanVector”? I haven’t called my Polygon interface “Polygon2D” or “EuclideanPolygon”, nor my line interface “Line2D” or “EuclideanLine”. I don’t need to. The terse name does the job perfectly well. If I only target Flash Player 9 I don’t need to call my vector interface anything other than “Vector”.

The headache is unresolved; I am stuck with wanting an array to be an Array and a vector to be a Vector, but will have to accept that an array will be a Vector and a vector … something else.

  • http://twitter.com/alecmce alecmce

    I’m annoyed with Adobe again. Why “Vector”? http://bit.ly/ZXFOd
    This comment was originally posted on Twitter

  • http://www.twitter.com/mikestead Mike Stead

    I agree the naming is poor.

    Could it be possible it’s an ECMA Script proposed standard that Adobe didn’t want to deviate from?

    I do know there’s a Java Vector class which has been around for a long time, and which I never liked the name for:

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html

    If they based it on that or a class in the STL then, as Josh Bloch said in his great talk on API design ( http://www.infoq.com/presentations/effective-api-design ), “Don’t Transliterate!”.

  • http://www.twitter.com/mikestead Mike Stead

    I agree the naming is poor.

    Could it be possible it’s an ECMA Script proposed standard that Adobe didn’t want to deviate from?

    I do know there’s a Java Vector class which has been around for a long time, and which I never liked the name for:

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html

    If they based it on that or a class in the STL then, as Josh Bloch said in his great talk on API design ( http://www.infoq.com/presentations/effective-api-design ), “Don’t Transliterate!”.

  • http://alecmce.com Anonymous

    Yes, I’d overlooked ECMA. I was under the impression that ECMA was going to die horribly sometime soon because none of the stake-holders could agree.

    If it is from ECMA specifications, then it’s a good reason not to like ECMA.

    Thanks for the insight, Mike.

  • http://alecmce.com alec

    Yes, I’d overlooked ECMA. I was under the impression that ECMA was going to die horribly sometime soon because none of the stake-holders could agree.

    If it is from ECMA specifications, then it’s a good reason not to like ECMA.

    Thanks for the insight, Mike.

  • Pingback: Another Vector Bug at AlecMcE.com

  • Glidias

    The reason why there’s no strict-typing for Arrays in Flash is because an Array is nothing more than a sparse Object hash with a “length” property that changes due to numeric keys being used (which are all string-based anyway like Object,…like PHP’s array(), it’s just a plain Dynamic Object, where any numeric string-based property is most probably casted over to integer to support updating the array’s length property, unlike Dictionary which uses strict quality to differentiate pure integer keys with string-based keys).

    Haxe supports strict typing of arrays, but that’s only for compile-type checking/code-hinting for developers and as far as Flash player is concerned, it’s still treated as a Dynamic object. Vectors are completely different from arrays, because they’re true dense arrays where the pointer addresses are immediately allocated into memory when the vector is initialized with a certain length (reserving those slots in memory). This isn’t the case with a sparse array/object in Javascript/AS3/ECMAScript, which is why Vector value-assigning and retrieval is probably faster than arrays.

  • Glidias

    The reason why there’s no strict-typing for Arrays in Flash is because an Array is nothing more than a sparse Object hash with a “length” property that changes due to numeric keys being used (which are all string-based anyway like Object,…like PHP’s array(), it’s just a plain Dynamic Object, where any numeric string-based property is most probably casted over to integer to support updating the array’s length property, unlike Dictionary which uses strict quality to differentiate pure integer keys with string-based keys).

    Haxe supports strict typing of arrays, but that’s only for compile-type checking/code-hinting for developers and as far as Flash player is concerned, it’s still treated as a Dynamic object. Vectors are completely different from arrays, because they’re true dense arrays where the pointer addresses are immediately allocated into memory when the vector is initialized with a certain length (reserving those slots in memory). This isn’t the case with a sparse array/object in Javascript/AS3/ECMAScript, which is why Vector value-assigning and retrieval is probably faster than arrays.

    • http://alecmce.com Alec McEachran

      Thank you for your comment Glidias. I appreciate that this came from my suggestion that Array. would have been preferable to Vector. but I am not convinced that the difference is as great as you express.

      What you say misses some significant differences between Object and Array. An Array is not simply a hash table, but can also act as a dense array. Internally it holds both data structures, which has important memory and performance implications. For a thorough analysis of this, you should really check out JP Auclair’s excellent blog:

      http://jpauclair.net/2009/12/02/tamarin-part-i-as3-array/
      http://jpauclair.net/2009/12/05/tamarin-part-ii-more-on-array-and-vector/

      Given JP’s analysis, anybody using an Array as a hash is mad. I realize if they had chosen to name an array “Array.” there would be this tension between the two meanings of the word “Array”: one just ‘array’ and the other ‘array (but also hash if you’re mad)’, but I think that this confusion is still less than the the confusion caused by using the term “Vector”, even given other languages’ nomenclatures.

  • http://alecmce.com Anonymous

    Thank you for your comment Glidias. I appreciate that this came from my suggestion that Array.< *> would have been preferable to Vector.< *> but I am not convinced that the difference is as great as you express.

    What you say misses some significant differences between Object and Array. An Array is not simply a hash table, but can also act as a dense array. Internally it holds both data structures, which has important memory and performance implications. For a thorough analysis of this, you should really check out JP Auclair’s excellent blog:

    http://jpauclair.net/2009/12/02/tamarin-part-i-as3-array/
    http://jpauclair.net/2009/12/05/tamarin-part-ii-more-on-array-and-vector/

    Given JP’s analysis, anybody using an Array as a hash is mad. I realize if they had chosen to name an array “Array.< *>” there would be this tension between the two meanings of the word “Array”: one just ‘array’ and the other ‘array (but also hash if you’re mad)’, but I think that this confusion is still less than the the confusion caused by using the term “Vector”, even given other languages’ nomenclatures.