Marc Knaup
03/11/2021, 3:59 PM0
to a Double
? Why 0.0
?Paul Woitaschek
03/11/2021, 4:17 PMZach Klippenstein (he/him) [MOD]
03/11/2021, 4:20 PMMarc Knaup
03/11/2021, 4:21 PMInt
when inferring a type.
@Zach Klippenstein (he/him) [MOD] actually Kotlin does.Paul Woitaschek
03/11/2021, 4:21 PMPaul Woitaschek
03/11/2021, 4:22 PMMarc Knaup
03/11/2021, 4:24 PMMarc Knaup
03/11/2021, 4:26 PM0
as universal unitless value.
In kotlin-css
for example we could just write top = 0
instead of top = 0.px
. But that’s another more advanced use case 😄Ruckus
03/11/2021, 6:28 PMuniversal unitless value
So,
null
Marc Knaup
03/11/2021, 6:31 PMnull
is absence of value. 0
means 0
.
Whether the div
is 0
cm
, px
or rem
away from the top doesn’t matter - it’s at the top. Hence it’s just 0
in CSS.
null
would mean that the distance to top is not defined.Ruckus
03/11/2021, 6:37 PM0
. What 0
means is dependent on the unit. Usually systems line up their 0
values, but not always. For example, 0C != 0F
.Ruckus
03/11/2021, 6:39 PM0
is used for a lot more than just CSS size definitions.Marc Knaup
03/11/2021, 6:39 PM0
can be converted in any type that supports it.
Just like we have in Kotlin already:
val int: Int = 0
val long: Long = 0 // implies 0L
if (int == long) // not allowed
The same way I could write
marginTop(0)
And allow that only for integer 0
and no other. The respective overload would resolve that properly and it only works if explicitly supported.Ruckus
03/11/2021, 6:41 PMtop = 0
still wouldn't work as top
isn't a number.Ruckus
03/11/2021, 6:42 PM0
sounds like it would cause far more problems than solve.Marc Knaup
03/11/2021, 6:46 PMkotlin-css
and have written my own library. Properties are too inflexible, functions are much better here.
Zero
could work the same way as Nothing?
does. It only has one valid value. Only difference is that it is inferred as Int
and Zero
is only used explicitly.Ruckus
03/11/2021, 6:51 PMtop = Zero
. How would you be able to automatically convert Zero
to a LinearDimension
?
That could get more complicated with, say, transforms. Should Zero
mean Identity
or a matrix full of `0`s?Marc Knaup
03/11/2021, 6:53 PMNothing?
.
top(0)
With
fun top(value: Zero) {
top(LinearDimension("0")) // example
}
fun top(value: LinearDimension) { … }
0
is not a matrix and thus wouldn’t be an acceptable value. In that case you’d probably use Matrix.identity
or alike.Ruckus
03/11/2021, 6:56 PMvar x = 0
x = 5 // Error: Expected Zero, found Int
Marc Knaup
03/11/2021, 6:57 PMvax x = 0
// Int
vax x: Zero = 0
// Zero
Marc Knaup
03/11/2021, 6:57 PMvar x = 0
// Int
var x: Long = 0
// Long
Marc Knaup
03/11/2021, 6:59 PMInt
on the callee side - or totally inaccessible.Ruckus
03/11/2021, 7:00 PM0
wouldn't be an Int
, it would be a Zero
. Adding special implicit cases like that is exactly the "magic" that Kotlin tries to avoid.Marc Knaup
03/11/2021, 7:01 PM0
on its own has no type. Otherwise you couldn’t assign it to Byte
, Long
, etc.Marc Knaup
03/11/2021, 7:02 PMclass LinearDimension(val value: String) {
companion object: ZeroConstructible {
override fun constructFromZero() = LinearDimension("0")
}
}
val foo: LinearDimension = 0
Marc Knaup
03/11/2021, 7:03 PMRuckus
03/11/2021, 7:06 PM0
special?Marc Knaup
03/11/2021, 7:07 PM0
specifically.
They have for IntegerLiteral
, FloatLiteral
, StringLiteral
, ListLiteral
(e.g. for Set construction) etc.Marc Knaup
03/11/2021, 7:07 PMMapLiteral
Marc Knaup
03/11/2021, 7:08 PMExpressibleBy…
by now
https://developer.apple.com/documentation/swift/expressiblebyintegerliteralRuckus
03/11/2021, 7:08 PMvar x: LinearDiminsion by ...
set(value) { ... }
set(value: Int) { set(value.px) }
Marc Knaup
03/11/2021, 7:08 PMMarc Knaup
03/11/2021, 7:09 PMZero
would be already but still an acceptable trade-off for simpler CSS API.Marc Knaup
03/11/2021, 7:09 PMMarc Knaup
03/11/2021, 7:09 PM0
but not unitless 1
in CSS.Ruckus
03/11/2021, 7:09 PMMarc Knaup
03/11/2021, 7:09 PM1
needs a unit and cannot be implicitly pixel.Marc Knaup
03/11/2021, 7:10 PM0
. For example in some calc(…)
expressions.
So 0
should never implicitly become 0px
.Ruckus
03/11/2021, 7:14 PMMarc Knaup
03/11/2021, 7:15 PM0
everywhere where it has the same meaning. Int
, Byte
, Long
, Double
and customs like css.LinearDimension
.Marc Knaup
03/11/2021, 7:16 PM0
for Float
and Double
😄Ruckus
03/11/2021, 7:18 PM0
. That's where I came into the conversation (and prefixed my original comment accordingly to make that clear).Marc Knaup
03/11/2021, 7:19 PMcss.LinearDimension
is about literal 0
not the Int
value 0
Ruckus
03/11/2021, 7:20 PM0
should be a valid Double
. I'm just adding my $0.02 on whether 0
should be a special unitless universal, and what that would entail.Marc Knaup
03/11/2021, 7:21 PMMarc Knaup
03/11/2021, 7:21 PMRuckus
03/11/2021, 7:27 PMMarc Knaup
03/11/2021, 7:31 PM0
literal for floating-point values.Zach Klippenstein (he/him) [MOD]
03/11/2021, 7:53 PM