Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pitch: rename the "Child" types #2902

Open
distractedlambda opened this issue Jul 16, 2019 · 7 comments
Open

pitch: rename the "Child" types #2902

distractedlambda opened this issue Jul 16, 2019 · 7 comments
Labels
accepted This proposal is planned. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@distractedlambda
Copy link

I can understand the origin of the name choice Child, but I dislike it for a couple of reasons:

  • It doesn't read well in code; I don't think of the pointed-to type of a pointer as it's "child"
  • It's unnecessarily ambiguous when you don't know what the type on the left-hand-side of the . is, and I think unique names would improve readability in-practice, even if only slightly.

I therefore propose that the Child types get renamed to some set of new (and unique) names. I don't think it matters so much what the exact names are, but rather that they are unique, and that they have something to do with what the type represents. A few suggestions:

  • For pointers, Pointee, Target, or Dereferenced, etc.
  • For optionals, Unwrapped, Inner, Value, NonNull, etc.
  • For arrays, Element, Item, etc.
  • For vectors, Element, Component, Scalar, etc.
@distractedlambda distractedlambda changed the title pitch: rename the "Child" types to be unique pitch: rename the "Child" types Jul 16, 2019
@marler8997
Copy link
Contributor

marler8997 commented Jul 16, 2019

Note that if they all use the same name, then generic code can be simpler in some cases:

fn foo(a: var) @typeOf(a).Child { ... }

How would you write this with your proposal?

Also, If we had a different name for each type of array, wouldn't it be harder to remember the specific name for each one? Child is kind of an odd name, I wouldn't mind changing it but I'm not seeing the benefit of creating a unique name for each type of array.

@andrewrk
Copy link
Member

andrewrk commented Jul 16, 2019

Child is actually deprecated, to be future proof use @typeInfo. See also std.meta.Child.

@andrewrk andrewrk added this to the 0.5.0 milestone Jul 16, 2019
@andrewrk andrewrk added the breaking Implementing this issue could cause existing code to no longer compile or have different behavior. label Jul 16, 2019
@distractedlambda
Copy link
Author

distractedlambda commented Jul 17, 2019

@marler8997
I can see your point, although if the plan is to switch to implementing these sorts of "type traits" in user code atop @typeInfo, then we could reasonably have both at the same time. We could all have Child functions and Element functions and Unwrapped functions and whatever else suited our particular fancies.

@marler8997
Copy link
Contributor

Yes, using @typeinfo allows for both.

@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 16, 2019
@andrewrk andrewrk added accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Feb 10, 2020
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 10, 2020
@andrewrk andrewrk added stage1 The process of building from source via WebAssembly and the C backend. standard library This issue involves writing Zig code for the standard library. labels Feb 10, 2020
@andrewrk
Copy link
Member

This affects, e.g.

child: type,

Note also the naming convention of types should be respected.

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 17, 2020
@ghost
Copy link

ghost commented Dec 16, 2020

  • For pointers, Pointee, Target, or Dereferenced, etc.

  • For optionals, Unwrapped, Inner, Value, NonNull, etc.

  • For arrays, Element, Item, etc.

  • For vectors, Element, Component, Scalar, etc.

You know, Element would work for all of these.
Rly maks u thonkum

@data-man
Copy link
Contributor

What's problem?
std.meta.Elem is already exists.

@andrewrk andrewrk modified the milestones: 0.8.0, 0.10.0 May 19, 2021
@Vexu Vexu removed the stage1 The process of building from source via WebAssembly and the C backend. label Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

5 participants