Advanced Kotlin Techniques for Spring Developers

Поделиться
HTML-код
  • Опубликовано: 11 янв 2025

Комментарии • 44

  • @xyvadimxy
    @xyvadimxy Год назад +4

    Great session guys!

  • @LostMekka
    @LostMekka Год назад +3

    thanks for this talk, you are awesome! ♥
    some notes i scribbled down while watching:
    - 10:24 i know this is nitpicking, but seeing that there is no trailing comma in the data class constructor really triggered me. it is a silly pet peeve of mine i guess 😅
    - wow, even as a senior dev i didnt know that primitive fields were auto-assigned to their primitive default value when null is given in the json request body. thanks for this insight ^^ (i think i didnt notice it so far because i always use openapi to generate clients for the fontend and server stub interfaces for the backend, so the frontend cannot accidentally supply a null value for a primitive field that is marked as required)
    - personally, i like the annotation based bean declaration, but i definitely see the value of the bean dsl. however i dont think that the dsl is faster, since spring reflectively scans all components anyways. once a @Bean method is found, registering it as a bean provider function should be about as fast as registering a dsl lambda as a bean provider function, so you should only see performance benefits if you completely disable bean discovery, right?

    • @asm0di0
      @asm0di0 Год назад

      Thank you! Regarding 3rd point: they said that Groovy DSL is faster than annotations, but slower than XML. Probably the same is true for Kotlin, but needs benchmarking

  • @TimoTeamMeinInternet
    @TimoTeamMeinInternet Год назад +1

    Great session and learned a lot.
    Thanks for your time! :)

  • @asm0di0
    @asm0di0 Год назад +7

    In case you want to workaround the primitives another way (Jackson-specific) there is a way:
    spring:
    jackson:
    deserialization:
    FAIL_ON_NULL_FOR_PRIMITIVES: true

  • @bader-eddineqodia5964
    @bader-eddineqodia5964 Год назад +5

    Thank you so much

  • @softwarengineeringwithfabri
    @softwarengineeringwithfabri Год назад +1

    very useful info, thanks 🎉

  • @asker3042
    @asker3042 Год назад +2

    Hi, can you please make a video about reified and inline function? I have no idea about those. I k ow I can read docs but better if you explain and show some examples thanks

    • @HerbertLandei
      @HerbertLandei Год назад +1

      There is really not much to know about it apart from the syntax. It looks like the type is not erased at runtime, but what happens is that because the function is inlined, the compiler can "see" which type is used in every particular scope, and insert the correctly typed code already at compile time. There are some subtle differences and limitations for inlined functions, but nothing serious, it just works 99% of the time.

    • @paprikar
      @paprikar Год назад

      @@HerbertLandei yeah, looks like it just behaves like a macros that inserts this real code into each place when its used. That is probably what is actually happening, especially, as far as I know, the performance of such methods may not be so good, because such a strategy does not allow to use the essence of the hotspot approach, because in bytecode this method simply won't exist

  • @donwald3436
    @donwald3436 Год назад

    43:28 Now there is a new concept, leaky DSL, analogue of leaky abstraction. Why make a DSL that is worse than not using it?

    • @AnotherDimension
      @AnotherDimension 11 месяцев назад

      that's true, but isn't that rather a framework's problem than language's one?

  • @donwald3436
    @donwald3436 4 месяца назад

    41:55 Use constructor injection........

  • @avalagum7957
    @avalagum7957 Год назад

    If we like the lastest of everything, should we change the kotlin version to 1.8.10 instead of 1.7.xx?

    • @AntonArhipov
      @AntonArhipov Год назад +1

      If you like the latest and greatest - sure, go on and try it! :)

    • @asm0di0
      @asm0di0 Год назад +3

      I tried and it works!

  • @boriskaloshin8989
    @boriskaloshin8989 Год назад +5

    Забавно смотреть как два русскоговорящих ведут стрим на английском ) И шутка про акцент очень даже в тему, хорошо еще , что чешский акцент, я бы сказал с рязанским ) А доклад хороший)

  • @programalol
    @programalol Год назад

    Yo que vengo de java me resulta muy comodo trabajar con kotlin

  • @berkowk
    @berkowk 9 месяцев назад

    Using data classes for JPA entities seems counterproductive 😂
    I guess java records have similar problems.

  • @Teemofey
    @Teemofey Год назад +5

    Чувствуется очень сильный чешский акцент. Лет ми спик фром май харт!

    • @replicant9611
      @replicant9611 Год назад +8

      Очень некрасиво указывать людям на акцент. Живу в Англии и никто ни разу не упрекнул и не пошутил на счёт моего русского акцента. Но среди русскоязычных это вообще как воды попить. То индусский акцент, то чешский теперь. Учитесь культуре общения.

    • @Teemofey
      @Teemofey Год назад +3

      @@replicant9611 Видимо это у вас некрасиво. Не знаю почему, может у вас за это убивают или сажают в тюрьму. Учитесь терпимости и юмору. У нас и акцент, и внешность это повод для беззлобного юмора. Учитесь тому, что существуют разные культуры, в том числе непохожие на вашу.

    • @replicant9611
      @replicant9611 Год назад +5

      Это называется бескультурье и смеяться с акцента "беззлобно" - это, в лучшем случае, бытовой расизм. Продолжайте упорствовать.

    • @Teemofey
      @Teemofey Год назад +1

      @@replicant9611 Я не упорствую, а рассказываю вам о другой культуре с другим отношением к юмору. У нас приняты интернационализм и равноправие, а ещё принято к себе и к другим относиться с пониманием и юмором. Если вы хотите насаждать свою единственно верную культуры и свои единственно верные взгляды то должны быть готовы к тому, что ваша диктатура встретит сопротивление.

    • @replicant9611
      @replicant9611 Год назад +1

      @@Teemofey Вы айтишник-экспат из Еревана? Расскажите как вы в последний раз посмеялись над акцентом и внешностью своего коллеги.

  • @ОлегПушкарев-ъ1ю
    @ОлегПушкарев-ъ1ю Год назад +1

    Some comments about @Entity declaration
    1.A better way of defining id property is to use 0
    @Id @GeneratedValue(strategy = IDENTITY)
    val id: Long = 0,
    This way we get rid of always using ? when we access id
    2. You dont Have to declare all properties as var, you can define val if you want to, like in ID example above.
    So your name and age could be val instead of var if you want to, and it will perfectly work

    • @asm0di0
      @asm0di0 Год назад

      That's a nice idea, thanks! I will use it in my talk on JavaZone!

    • @deepakbisht4957
      @deepakbisht4957 Год назад

      Actually Val and var is about the layer you are working on.
      I use nullable and var in Network and Entity (Database) data classes in the data layer.
      But for the domain layer all my models or data classes don't have any nullable field and no var field ( i.e. I use all fields with Val)
      This is the rule I define to make my domain model with no field with nullable and all fields should be immutable or immune for changes.
      For ex
      for db model
      data class UserEntity(
      val Id : Long?,
      var name: String?,
      var email: String?
      var phone: String)
      for network model
      UserNetwork(
      val Id : Long?,
      var name: String?,
      var email: String?
      var phone: String)
      But for Domain
      Same thing should be
      User(
      val Id : Long,
      val name: String,
      val email: String,
      val phone: String)
      As I'm adding default values to the User model when I create a mapper for mapping UserEntity or UserNetwork to User...
      Using this way I can use my domain model freely without any null checks and without doing any computation to mutate fields of User in Presentation layer and by this I'm decoupling the responsibility of transformation of field of User from my presenter to any service or Repository class...

  • @donwald3436
    @donwald3436 Год назад

    31:57 I would write
    Person(
    id = rs.getInt("id"),
    name = rs.getString("name"),
    age = rs.getInt("age"),
    )
    What do you think?