« first day (4939 days earlier)   
08:00 - 22:0022:00 - 23:00

10:01 PM
@IluTov A constructor can be present. Its visibility is respected. Right now I'm struggling to find cases where you have public properties with a public constructor that are broken, aside from things like readonly as mentioned previously. The public property generally means anything type-safe can be written to it at any point so... effectively ignoring the constructor (although again, respecting its visibility) and just writing those properties should be allowed, yes?
 
@LeviMorrison Maybe I didn't think it through, but stdClass just remains a reference type. An alternative with value semantics could be useful, although at that point you could probably just use an array.
@LeviMorrison Right, fully public properties are not really my concern. They may change arbitrarily.
 
@IluTov I meant that in two RFCs that talk about class naming and specifically their casing... how did neither one mention stdClass which doesn't seem to follow any convention at all?
 
@LeviMorrison Oh, I'm sorry. I misunderstood, and thought we were talking about structs.
 
@IluTov No worries. I switched topics suddenly lol
@IluTov So what things are you concerned about? Doesn't need to be struct object specific, class objects should support this too. I still feel like I don't grasp your arguments.
 
@LeviMorrison If the syntax is allowed in the presence of __construct, if breaks interior assumptions. If it doesn't, it introduces BC breaks when adding constructors, and is just less useful overall.
 
10:08 PM
@IluTov Give me an example of an interior assumption that you think would break, based on what you understand from my not-written-down proposal.
 
@LeviMorrison Private properties will remain uninitialized. But you already said you'd disable the syntax in that case, so only really the latter half of my last message is relevant.
 
To be clear, the class itself could use this syntax to initialize private properties, because they have access to them. It's not just "ah, there's a non-public property, can't use this feature on this object!" It's visibility based to the scope calling it.
 
I understand, but the syntax would still break everywhere else.
 
I'll think more about the supposed breakage when adding a constructor but... so far I haven't found any issues when thinking through it.
 
My brain is not really working at full capacity, maybe I'm missing some things. :) Some sleep might help. 😴
 
10:13 PM
@IluTov To be sure, you mean that there is a class with only public properties today, and tomorrow, you add a private property. This is now a BC break because callers which used brace initialization are now broken. Something like this?
 
@LeviMorrison Right. Which might be less common for structs, but probably quite common for classes.
 
@IluTov I believe this is a valid complaint, and one written about in the Rust community. Adding the first private field is a BC break. You'll see sometimes where people add a private field that does nothing just to avoid this kind of thing.
 
@LeviMorrison I see. I was wondering how Rust solves this. In practice, I would expect most libraries to create new initializers for their structs? I have no idea though, I have never done anything productive with Rust.
 
Someone even wrote an RFC about this space: github.com/nikomatsakis/rfcs/blob/extensible-enums-and-structs/….
Basically, this would disable downstream consumers from pattern matching and such:
pub struct S {
    pub f: F,
    ..
}
The exact syntax is because it's like the inverse of let S { f, .. } = s; in pattern matching.
 
"10 years ago" :D I'm guessing #[non_exhaustive] should do something similar today.
 
10:23 PM
The most recent discussion seems focused on some kind of non_exhaustive attribute.
 
Jinx
 
08:00 - 22:0022:00 - 23:00

« first day (4939 days earlier)