Hidden control flow with computed properties #1192
Replies: 2 comments 2 replies
-
They're not absolutely necessary. If we didn't have them, some places currently spelled I'm not dead set against the idea. At the same time, I do believe in abstraction, which means stuff gets hidden, one way or another; I therefore find the claim that no-hidden-control-flow is a huge win suspect. It's pretty clear to me that forcing people to add That said, there's very little Hylo code in existence right now, so we don't have a good way to assess the damage, if any, that might be caused by removing computed properties altogether, and I'm not certain they (or parameter-less subscripts) would be common in any code. My usual thought is to start conservatively by removing features and waiting for a real need to be demonstrated, and my suggested compromise position is pretty messy. So, color me in favor of running an experiment where we remove computed properties and see what happens. |
Beta Was this translation helpful? Give feedback.
-
In general, I don't think we can promise that accessing a value via dot-syntax is always as cheap as computing a pointer offset. That would be a contract very difficult to honor in a generic context. Take a look at this API:
Unless we can guarantee that this function is always monomorphized, there's no way to promise that accessing We could say that traits are not allowed to define property requirements, but that sounds like a frustrating restriction to me. I also think that it would impede on our ability to apply generic programming without introducing boilerplate when we see that two types share common properties. For example, say you're looking to refactor this code:
It looks quite tempting to say that both That being said, I agree that it should probably be considered bad practice to have computed properties with non-constant time complexity. Such a rule would be difficult to enforce but we could make the effort to guide the community to exercise self-discipline. |
Beta Was this translation helpful? Give feedback.
-
Perhaps my opinion is in the minority, but I've always thought that computed properties were a little odd. They behave much like a function/method in Objective-C and Swift, and I see in the Hylo language tour that they are a no-parameter subscript which will yield a value.
But when I'm reading code that has some dot notation without parentheses (or square brackets), I'm inclined to think that I'm dealing with a regular old property and its value, not a function call that might involve multiple statements being executed.
The folks working on the Zig language argue that no hidden control flow is a big, important feature that differentiates their systems programming language from others, and I'm decidedly in agreement with them.
I do like many things about Hylo so far, especially its claims of simplicity, but is there a chance that the language could be further simplified by removing computed properties to remove the hidden control flow found therein?
I'm willing to be educated about why computed properties are absolutely necessary to realize the goals of mutable value semantics if they would indeed play such a role.
Beta Was this translation helpful? Give feedback.
All reactions