4 ms·
I like Jai's `use` keyword. Fun fact: Odin has this exact same thing with `using`. https://odin-lang.org/docs/overview/#using-statement https://odin-lang.org/d
by olah_1 7y ago
I like Jai's `use` keyword.
Fun fact: Odin has this exact same thing with `using`. https://odin-lang.org/docs/overview/#using-statement https://odin-lang.org/docs/overview/#using-statement
- hota_mazi 7y agoKotlin also has it as "apply": Windows().apply { width = 100 height = 200 } Now, I can't help but see the following kind of code: val someStructure = ... someStructure.x = ... someStructure.y = ... someStructure.name = ... as an immediate language code smell
- gingerBill 7y agoOdin's `using` comes from Pascal's `with`, of which was block based. Odin's `using` can be applied to a load more than just scopes: https://odin-lang.org/docs/overview/#using-statement https://odin-lang.org/docs/overview/#using-statement
- hota_mazi 7y agoYes, the general idea is not new but the devil is in the details. As far as I can tell, Odin's `using` is applicable in the same areas as Kotlin's, but I still favor Kotlin's scoped version. When I see "using foo;" in Odin, it's not quite obvious to me where the scope of applicability is. Any reason why you didn't do something like entity.use { // "this" is now the entity instance } // back to your regular "this" ?
- gingerBill 7y agoYou can easily do the same in Odin, if you would like. However, `using` works for a lot more than that just this. `using` allows for many for type system features beyond a basic scope import like Pascal's with. `using` can be applied to procedure parameters, struct field declarations allow for subtype polymorphism (even of pointers), scope imports, and more. Koltin's approach is limited to purely the same Pascal's `with` allowed. But if you want to be clear: { using entity; // the fields of "entity" are not usable in this scope x = 123; } entity.x = 123;
- gingerBill 7y ago* are now usable typo