Nothing is really cool in Kotlin

Поділитися
Вставка
  • Опубліковано 14 січ 2025

КОМЕНТАРІ • 25

  • @ArthurKhazbs
    @ArthurKhazbs 4 місяці тому +56

    This is the most brilliant non-clickbait clickbait I've ever seen on UA-cam

  • @denisgithuku8563
    @denisgithuku8563 5 місяців тому +42

    Had me in the first half.

  • @StreetsOfBoston
    @StreetsOfBoston 4 місяці тому +9

    Nice short and to the point video.
    "Nothing" also has a mathematical meaning behind it.
    A type defines the valid values of a variable, ie a type defines a "set" of (valid) values:
    - A sub-type is a sub-set of those values (eg in Java, Integer is a sub-set of Number.
    S < T
    - An *empty* set is a sub-set of every other set you can imagine (X is not empty).
    {} < X
    - The type "Nothing" defines a an *empty* set, since it has no values.
    Nothing --> {}
    - This means that "Nothing" is a sub-type of every other type.
    Nothing < T
    And that is why you can assign "null" to any nullable type (String?, Int?, Foo?):
    - The value "null" has the type "Nothing?" and "null" is its only value.
    Nothing? --> {} | "null" = { "null" }
    - Because "Nothing" is a sub-type of every other type, "Nothing?" is a sub-type of every other nullable type.
    { } | null < X | null --> Nothing? < X?
    - And since "null" is a "Nothing?", you can assign "null" to every nullable variable.

  • @JolanRensen
    @JolanRensen 3 місяці тому +5

    Recently made a PR which I named "This fixes Nothing". Couldn't stop myself haha

  • @tajapan
    @tajapan 2 місяці тому +4

    Is Nothing in fact Everything?

    • @s.sellmair
      @s.sellmair  2 місяці тому +1

      @@tajapan To be or not to be, that's the question.

  • @MyriadColorsCM
    @MyriadColorsCM 4 місяці тому +4

    As a student of philosophy. to say there is a 'nothing' type is absolutely terrifying.
    As a programmer, this is cool.

  • @nomadshiba
    @nomadshiba 5 місяців тому +15

    tbh its equal to `never` type in typescript

  • @coroutinedispatcher
    @coroutinedispatcher 5 місяців тому +2

    once a fan of Either, always a fan of Either :P

  • @technopradyumn
    @technopradyumn 5 місяців тому

    Please make video on jetpack compose for supabase database with login sign up with email and password and verify email using otp and reset password using otp please make video on this topic

  • @TheGamemaster4455
    @TheGamemaster4455 4 місяці тому

    Thank you so much for this!

  • @elelan
    @elelan 5 місяців тому +1

    Just wow!!!

  • @viniciusabreu3288
    @viniciusabreu3288 4 місяці тому

    Nice content, thanks for posting! Quick question: if I decide to specify a type context for T, it won't be possible to stick to Nothing in the Error data class because of type intersection. How would you tackle this?

  • @squ34ky
    @squ34ky 4 місяці тому

    You got me!

  • @slavsquatsuperstar
    @slavsquatsuperstar 5 місяців тому

    I think you solved the Halting Problem :P

  • @MABD-Dev
    @MABD-Dev 4 місяці тому +8

    Please use dark mode. This really hurts
    As always amazing video, crisp clear explanation

    • @HumanBeingSpawn
      @HumanBeingSpawn 4 місяці тому +6

      get out of your cave, caveman

    • @masterflitzer
      @masterflitzer 3 місяці тому

      @@HumanBeingSpawn if videos would support dynamic theme that would be next level, cause i like to have light mode on daytime at work and dark mode on nighttime when working on personal projects

  • @GraphicQuest
    @GraphicQuest 5 місяців тому +1

    hh a funny title 🃏🃏

  • @byaruhaf
    @byaruhaf 4 місяці тому

    LOL, was expecting to see a diffrent video

  • @rikschaaf
    @rikschaaf 5 місяців тому

    But wait, what would `httpResponse.length` print if `httpResponse()` returned an `OurResult.Error`? What is the value of nothing.length?

    • @s.sellmair
      @s.sellmair  5 місяців тому +2

      If httpResponse() returns `OurResult.Error` then the `.valueOr { return }` will enter the this `alternative` function.
      However the `{ return }` will return from the `main` function as `valueOr` is marked as `inline`, therefore it can never happen that `nothing.length` would be evaluated.
      The code is similar to
      ```
      fun main() {
      val httpResponse = when(val result = httpRequest()) {
      OurResult.Success -> result.value
      OurResult.Error -> return / *