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

feat: Add bare Kotlin type overloads for expression functions #196

Merged

Conversation

sargunv
Copy link
Owner

@sargunv sargunv commented Dec 26, 2024

closes #193

@sargunv sargunv requested a review from westnordost December 26, 2024 23:14
Copy link
Owner Author

sargunv commented Dec 26, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sargunv sargunv merged commit e1de5e5 into main Dec 26, 2024
9 checks passed
@sargunv sargunv deleted the feat_add_bare_kotlin_type_overloads_for_expression_functions branch December 26, 2024 23:49
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be missing for

  • both switch (i.e. the fallback, but also secondary constructors for the case and condition
  • all the comparison functions
  • within

By the way, why is the constructor of Case and Condition private and then there is a function that is basically a constructor for it?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just stylistic preference. I prefer to think of the expressions DSL as regular functions, and short-lived objects like Case and Condition are implementation details to get the typing and syntax right.

Additionally, Dokka shows documentation for functions on a different page from types, and this keeps documentation for the construct and also the branches on the same page.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and similar to math, overloads for generic stops means writing a whole lot of overloads for many different types

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true... , but using literals for these constructs is pretty much the default case for these constructs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all overloads with bare types are missing for the math functions

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For math operators, it felt odd to me to have different types on two sides of the operator. Maybe it's okay though

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also for anything related to numbers with units, we'd write a lot of overloads for bare types (no unit, Dp, TextUnit, Duration, maybe Meters in the future). Seems not worth it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not sure, IIRC the Android MapLIbre SDK does that. (For Floats only, of course)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stops for the interpolate expressions and step expressions don't have bare Kotlin overloads.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With current typing (the Pair), either all stops will have to be Kotlin values, or all stops Expressions. Thoughts on doing something like case and condition (maybe stop?) so we can use different overloads on each stop?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is rather the default / usual case that no expressions are used, so the overload that doesn't allow any expressions for the stops would I think be the most used one.
Having data classes for step and interpolate i.e. stop(...) sounds fine to me, too. It's only marginally less convenient/more verbose than the to (and anyway, that is just a normal infix function, you could name the function that creates a Stop also like that.)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be wary of shadowing to so would want a different infix name, or just stop() like the others.

It's true that most stops/case/condition would be const, but also interpolate/switch is already a pretty big, verbose, construct, and so adding one const per stop doesn't hurt readability much (at least to my eye).

Compared to get and has which were small enough that the const dwarfed the get/has and made it confusing to read.

@westnordost
Copy link
Collaborator

westnordost commented Dec 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add bare Kotlin type overloads for expression functions
2 participants