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

Type conversions complexity #18

Open
machaval opened this issue Sep 29, 2020 · 3 comments
Open

Type conversions complexity #18

machaval opened this issue Sep 29, 2020 · 3 comments

Comments

@machaval
Copy link
Contributor

One of the things that I struggle the most is type conversions that are not trivial. This means that requires Parameters

For example converting a DateTime
toEpoch

now() as Number {unit: "seconds"}

Or toMillis

now() as Number {unit: "milliseconds"}

Or converting a Date to String

now() as String {format: "YYYY/MM/dd - hh:mm:ss"}

I think all this transformations are not that hard to understand what it does when you read it but are very hard to remember how to do it. It requires to now one this new syntax of how to pass arguments to the type conversion.

Questions

  • Should we transform this into functions?
  • Should we have one module called Conversions with all the type conversions? Or should we put each type conversion in the corresponding module
@afelisatti
Copy link

What examples do we have for similar functionality in other languages? Will users understand they require a "conversion" or would they prefer working with target/source types?

@menduz
Copy link
Contributor

menduz commented Sep 30, 2020

The closest I can think of is SQL (Transact SQL is very well documented in general terms)

Other remotely similar approaches, I don't recall languages with formatting on the type system, the following are libraries:

Those are have some common patterns. In uncommon cases conventions vary tho.

@jorgegarciamule
Copy link

We should not forget that the compiler knows that after Number you put an object with unit and other 3 attributes and that unit is expecting a value from a fixed list. All of this typing gives the IDE tools to assist the developer no need to remember everyhting.

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

No branches or pull requests

4 participants