Code Monkey home page Code Monkey logo

Comments (8)

joshtynjala avatar joshtynjala commented on July 19, 2024

Is for (item in items) guaranteed to be in order? Even if that's the case, I'm somewhat wary because it's not always true in other languages. I'd rather have code that doesn't require remembering how something behaves.

so probably using Std.downcast is better in this case.

Just to be sure that I fully understand, can you post an actual code example of the change that you're suggesting?

from feathersui-openfl.

nadako avatar nadako commented on July 19, 2024

Is for (item in items) guaranteed to be in order? Even if that's the case, I'm somewhat wary because it's not always true in other languages. I'd rather have code that doesn't require remembering how something behaves.

Ordering depends on a collection/iterator, and since Array is an ordered collection, of course it's guaranteed to be in order. I think that's the same for every language that supports "declarative" for.

can you post an actual code example of the change that you're suggesting

Something like:

var layoutObject = Std.downcast(item, ILayoutObject);
if (layoutObject != null && !layoutObject.includeInLayout) {
    continue;
}

from feathersui-openfl.

Gama11 avatar Gama11 commented on July 19, 2024

Is for (item in items) guaranteed to be in order? Even if that's the case, I'm somewhat wary because it's not always true in other languages.

Huh? In what language is this not the case?

from feathersui-openfl.

back2dos avatar back2dos commented on July 19, 2024

JS/AS would come to my mind, because there it means key iteration. But for/of (which is the actual counterpart to Haxe's for/in) is indeed well defined for arrays.

from feathersui-openfl.

nadako avatar nadako commented on July 19, 2024

JS/AS would come to my mind, because there it means key iteration.

AFAIK the order of "keys" for Array is still defined there.

from feathersui-openfl.

back2dos avatar back2dos commented on July 19, 2024

AFAIK the order of "keys" for Array is still defined there.

Sorry to disappoint, but I have bad news for you:

There is no guarantee that for...in will return the indexes in any particular order. - MDN

IIRC AS2 would rather consistently give the array keys to you in reverse order ¯\_(ツ)_/¯

from feathersui-openfl.

nadako avatar nadako commented on July 19, 2024

IIRC AS2 would rather consistently give the array keys to you in reverse order ¯_(ツ)_/¯

LOL, but oh well, as you already mentioned, Haxe for is different and more properly "maps" to ES6 for/of loops, or e.g. C# for each, so one should not be afraid to use it and it has better expressiveness.

from feathersui-openfl.

joshtynjala avatar joshtynjala commented on July 19, 2024

@nadako Unfortunately, this code that you suggested does not work:

var layoutObject = Std.downcast(item, ILayoutObject);
if (layoutObject != null && !layoutObject.includeInLayout) {
    continue;
}

Compiler error:

Constraint check failure for downcast. feathers.layout.ILayoutObject should be openfl.display.DisplayObject

from feathersui-openfl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.