Zulip Chat Archive
Stream: mathlib4
Topic: naming bikeshed: `ofFoo`
Arien Malec (Feb 03 2023 at 22:45):
Although undocumented, I believe there's a naming convention that we name ofFoo
toFoo
etc.
- Should this be documented in the wiki?
- Should
Topology.UniformSpace.Separation
be updated to conform to the convention? (e..g.,isClosed_of_spaced_out
eq_of_separated_of_uniformContinuous
)
Jireh Loreaux (Feb 04 2023 at 03:04):
Sorry, can you more explicitly specify what you think this undocumented naming convention is?
Arien Malec (Feb 04 2023 at 04:11):
Sure -- when we have a capitalized object, we often name projections or transformations to/from the object with a toFoo
or ofFoo
, but we are not consistent with that naming convention.
e.g., to_setoid
-> toSetoid
, to_finset
-> toFinset
Arien Malec (Feb 04 2023 at 04:13):
but counterexamples above.
Ruben Van de Velde (Feb 04 2023 at 06:30):
Does it depend on whether Foo is a Prop(-ish)?
Arien Malec (Feb 04 2023 at 06:50):
I don't know? We ofFoo
and toFoo
sometimes and not others...
Arien Malec (Feb 04 2023 at 06:54):
I've got to believe there's some mathport
support here, but I haven't code dived deeply enough yet.
Another example:
Why finprod_eq_prod_pLift_of_mulSupport_toFinset_subset
in Algebra.BigOperators.Finprod
? We have ofFinset
but not ofMulSupport
?
Arien Malec (Feb 04 2023 at 06:55):
I want to believe that if Foo
is a name that gets an UpperCamelCase
name also gets a toFoo
/ofFoo
name, but I haven't see it formalized that way.
Yury G. Kudryashov (Feb 04 2023 at 07:00):
toFinset
is a definition, so we reuse it
Yury G. Kudryashov (Feb 04 2023 at 07:01):
Otherwise we insert _
Yury G. Kudryashov (Feb 04 2023 at 07:01):
This is a strange convention.
Arien Malec (Feb 04 2023 at 16:03):
Got it -- so to write back, I mistakenly pattern matched into a convention of is/of/toFoo
because in Mathlib3 we do in fact have def
and Prop
-typed is/of/to_foo
s which get naming convention translated into IsFoo
/toFoo
, etc, but not always, so a theorem that expresses an invariance might be named of_Foo_toBar
or ofFoo_toBar
or etc., depending on whether there was an underlying definition or not.
I guess I don't then understand why we have Cycle.toFinset
and Cycle.toFinset_toMultiset
but also Cycle.nil_to_finset
.
I'm coming at this from the perspective that it's good for naming conventions to have clear rules, and also good for the rules to be discoverable and consistent for an API user.
Jireh Loreaux (Feb 04 2023 at 16:08):
Have you seen the naming rules listed on the porting wiki? Eventually I think the naming convention will work its way into the website.
Jireh Loreaux (Feb 04 2023 at 16:10):
The nil
one is just misnamed. You should open a PR to fix it.
Arien Malec (Feb 04 2023 at 16:10):
Jireh Loreaux said:
Have you seen the naming rules listed on the porting wiki? Eventually I think the naming convention will work its way into the website.
I wrote it...
Arien Malec (Feb 04 2023 at 16:11):
That's not quite correct, I edited it for clarity.
Jireh Loreaux (Feb 04 2023 at 16:11):
Anyway, there are a few toFinset
things misnamed in that file.
Arien Malec (Feb 04 2023 at 16:12):
But most of my questions here are by way of making sure the rules are clear, and clearly documented...
Eric Wieser (Feb 04 2023 at 16:32):
I don't see it mentioned above; but the toFoo
naming convention is automatically generated by Lean when using the extends
keyword
Eric Wieser (Feb 04 2023 at 16:32):
Eg docs4#MulOneClass .toMul
Arien Malec (Feb 04 2023 at 16:35):
Jireh Loreaux said:
The
nil
one is just misnamed. You should open a PR to fix it.
Last updated: Dec 20 2023 at 11:08 UTC