https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
h

Hullaballoonatic

12/03/2019, 9:23 PM
If
Byte
is a
Number
, then why isn't a
Bit
/`Boolean`? Iirc,
Boolean
isn't actually stored with just one bit in memory, but does that actually matter?
r

Ruckus

12/03/2019, 9:29 PM
How it's stored doesn't really matter. When it comes down to it, everything is just stored as bytes. The difference is semantics.
Byte
represents numeric values and can perform numeric operations.
Boolean
doesn't.
h

Hullaballoonatic

12/03/2019, 9:30 PM
Sure but isn't a
Boolean
logically equivalent to a
Bit
, which is a number
s

streetsofboston

12/03/2019, 9:35 PM
I guess the same reason a
Char
is not a
Number
r

Ruckus

12/03/2019, 9:36 PM
Why do you say
Bit
is a number? (Also,
Bit
isn't a type in Kotlin, so that comparison doesn't really apply here).
h

Hullaballoonatic

12/03/2019, 9:36 PM
What do non-ascii characters return when you call
Char::toInt
?
For whatever reason a
Byte
is a number, the same can be applied to a
Bit
I'm saying
Bit
does exist in Kotlin. it's just called
Boolean
r

Ruckus

12/03/2019, 9:38 PM
I guess that depends on how you would define
Bit
. If you define it to be
Boolean
, then it has nothing to do with
Byte
.
h

Hullaballoonatic

12/03/2019, 9:39 PM
A Bit is a 0 or 1. Logical operations with bits are logically equivalent to those performed with booleans. If two things are logically identical, they are the same thing.
r

Ruckus

12/03/2019, 9:40 PM
Then that's not a
Boolean
. A
Boolean
is
true
or
false
. Not
1
or
0
. They may be represented the same in memory, but that's irrelevant.
h

Hullaballoonatic

12/03/2019, 9:41 PM
but in bit arithmetic 1==true, 0==false. all digital computation is based on Boolean logic by way of bit arithmetic. in bit arithmetic a bit is a True/False value.
r

Ruckus

12/03/2019, 9:42 PM
They aren't logically identical by definition. `Boolean`s are logical, and that definition of
Bit
is numerical. You seem to be operating off the assumption that
1 === true
and
0 === false
, which isn't true. (Sorry, I started writing that before I saw your message)
h

Hullaballoonatic

12/03/2019, 9:42 PM
Why are logical and numerical mutually exclusive?
r

Ruckus

12/03/2019, 9:43 PM
Not mutually exclusive, just orthogonal.
h

Hullaballoonatic

12/03/2019, 9:44 PM
I apologize if I sound combative. I'm not arguing to win, more to explore a concept
r

Ruckus

12/03/2019, 9:44 PM
If
Bit
were defined, it could be done in a way that makes it logical and numerical.
Boolean
just isn't.
Same here 🙂 I quite enjoy these kinds of discussions. They can make you rethink some of your assumptions, which can be very useful.
h

Hullaballoonatic

12/03/2019, 9:48 PM
I guess my point is there need not be such a distinction. It is the same point as "Why does Kotlin/Java treat the boolean
&&
differently from the bitwise
and/&
? Shouldn't
true xor false
compile? It doesn't because true and false are not bitwise values, but in boolean logic if two statements have identical truth tables, they are logically equivalent; bitwise
and
and logical
&&
have identical truth tables. Same goes for all bitwise and boolean unary and binary functions
r

Ruckus

12/03/2019, 9:49 PM
In some languages it is true that
1 == true
and
0 == false
, but in others that's not true. Even if they are represented the same internally, it often makes sense (especially in strongly typed languages) to have them be semantically separated.
h

Hullaballoonatic

12/03/2019, 9:50 PM
I guess I also question the lack of boolean xor, nor, nand in the language, too
r

Ruckus

12/03/2019, 9:50 PM
I'm pretty sure
xor
is there, but not
nand
or`nor`.
h

Hullaballoonatic

12/03/2019, 9:50 PM
the only one of which that is actually felt missing however is
xor
.
There's a
Boolean::xor
?
I know there's a bitwise one
r

Ruckus

12/03/2019, 9:51 PM
h

Hullaballoonatic

12/03/2019, 9:51 PM
oh shit
my bad. I guess I just assumed it didn't exist since
and
and
or
are exclusive to bitwise operations
r

Ruckus

12/03/2019, 9:54 PM
Yeah, there are a few downsides to infix vs operator. Unfortunately the existence of bitwise operators (while super useful) do blur the logical vs numerical distinction, but that could be cleared up by assuming a
Bit
type that is both numerical and logical and handles conversion to/from number types.
h

Hullaballoonatic

12/03/2019, 9:56 PM
🤫 That line is so blurry because it actually doesn't exist...
r

Ruckus

12/03/2019, 9:56 PM
😆
I guess you also then have to figure out if maybe
true == 1
but
true !== 1
...
h

Hullaballoonatic

12/03/2019, 9:59 PM
Should they hash to the same value?
r

Ruckus

12/03/2019, 10:00 PM
Sure but lot's of things that hash to the same value aren't equal.
h

Hullaballoonatic

12/03/2019, 10:00 PM
I mean. 1L !== 1 We're already pretty comfortable with different number types
Boolean
would just extend
Number
and be comparable to other `Number`s.
I actually don't know what
===
vs
==
distinction is in kotlin. I initially assumed
===
meant equal hashcodes or that they must be the same javaclass, and that
==
was using
compareTo
operator, but that is not the case.
s

streetsofboston

12/03/2019, 10:04 PM
===
compares the instance reference.
==
executes the
equals
method
r

Ruckus

12/03/2019, 10:05 PM
That's not exactly true for primitives (which most numbers are as well as booleans)
h

Hullaballoonatic

12/03/2019, 10:05 PM
therefore the only way to use
operator compareTo
to compare equivalency between 2 instances is to do
x.compareTo(y) == 0
? That's pretty silly
s

streetsofboston

12/03/2019, 10:05 PM
True… for primitives,
==
and
===
are the same
No,
==
should suffice for equivalency.
h

Hullaballoonatic

12/03/2019, 10:06 PM
Well I know the following doesn't compile:
when(myLong) {
    0 -> ... // type mismatch Int/Long
    1 -> ... // type mismatch Int/Long
    else -> ...
}
s

streetsofboston

12/03/2019, 10:07 PM
Hmmm… I thought
equals
takes an
Any?
as input parameter….
h

Hullaballoonatic

12/03/2019, 10:07 PM
🤷‍♂️ I tried it today
s

streetsofboston

12/03/2019, 10:08 PM
This maybe an additional check for a
when
clause by the compiler…. Wonder if the
Number#equals
enforces the receiver and the input parameter to be of the same class.
r

Ruckus

12/03/2019, 10:08 PM
No, this comes down to primitive being special. There is no actual
equals
function for primitives on the JVM.
s

streetsofboston

12/03/2019, 10:09 PM
True, but Kotlin is not just JVM…
h

Hullaballoonatic

12/03/2019, 10:09 PM
s

streetsofboston

12/03/2019, 10:12 PM
Something odd going on with Numbers with regards to `equals`… You can replace
myLong == 0
, which won’t compile with
myLong.equals(0)
, which does compile, but still complains
Going back to the JVM, this is how
equals
is implemented for a java.lang.Long:
public boolean equals(Object obj) {
        if (obj instanceof Long) {
            return value == ((Long)obj).longValue();
        }
        return false;
    }
r

Ruckus

12/03/2019, 10:15 PM
There's a fair amount of rewriting going on with the Kotlin compiler
s

streetsofboston

12/03/2019, 10:15 PM
If the input parameter is not a
Long
, it will return false. Since it will always be false,
myLong == myInt
will not compile, since it always will return
false
h

Hullaballoonatic

12/04/2019, 5:22 PM
Oh, and @streetsofboston
Char
is a
Number
in Kotlin
s

streetsofboston

12/04/2019, 5:23 PM
public class Char private constructor() : Comparable<Char>
h

Hullaballoonatic

12/04/2019, 5:23 PM
Oh, actually it isn't
i got confused because all `Number`s must include
toChar
thank you