-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Inconsistency between fieldnames and propertynames #34788
Comments
I believe these are different for a reason. In 1.0 we tried to eliminate many of the |
@JeffBezanson Your points are well taken. But somehow I still feel that the current behavior is unpleasantly asymmetric and initially confusing. Under the premise that a property is a generalization of a field, then a function named |
I do think it would help to more clearly separate functions that operate at the type level, e.g. accept a type as a representative of its instances. For example |
Currently,
fieldnames
returns the fields ascribed to a type, whereaspropertynames
returns the properties of an instance:Since properties are abstractions of fields, I feel that fields and properties should be treated more consistently. I have two independent suggestions:
Currently, the fallback for
propertynames
ispropertynames(x) = fieldnames(typeof(x))
. My suggestion would be to define the corresponding fallbackfieldnames(x) = fieldnames(typeof(x))
as well. This seems to me to be the only sensible meaning whenx
is not a type. Furthermore, this addition would be non-breaking.IMHO, the result of
propertynames(A)
in the example above is unexpected. I suggest defining the fallbackpropertyname(x::DataType) = fieldnames(x)
(and related methods for special types such asUnionAll
andTuple
). I believe this would technically be a breaking change, but it would make the behavior ofpropertynames(A)
consistent withfieldnames(A)
and (arguably) more expected.The text was updated successfully, but these errors were encountered: