Why dataclasses in Python are awesome!

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

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

  • @seventeeen29
    @seventeeen29 2 года назад +508

    A rare example of genuinely good advice from this guy

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

      and even then, it's far from being a passable video when we read the documentation of `dataclasses` module.

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

      @@eeriemyxi care to elaborate?

    • @eeriemyxi
      @eeriemyxi Год назад +50

      @@remi1771 He claims himself as to be a tutor and then goes to upload videos where he doesn't even link the documentation which is utterly crucial in this field.
      `dataclasses` module in Python is not just to get rid of some boilerplate code. `dataclass` has vast variety of optional arguments which can be useful, `dataclasses` module also includes various functions; in none of his videos that I've seen has he ever told his viewers to have a look at the documentation to learn more; most of his viewers are beginners who are not tech geek by the age of four or something. This practice forces these beginners to be depended on these creators to learn some "hidden & forbidden genjutsu" about Python as indirectly claimed by the utterance of these gormless creators.

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

      @@eeriemyxi agreed, these ‘tutorials’ are really only useful for intermediate programmers who are looking for some ideas and know to look up the api immediately afterwards

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

      @Patrick Lenihan I have done couple modifications to the comment that you should consider reading.
      > _He summarised "dataclasses" as boilerplate reduction which is a correct summary of what it is._
      `dataclasses` itself is a module, it is not some function that helps to reduce boilerplate code, rather it includes various functions and the function that helps with boilerplate code.
      > _Your claim that Python is its own field_
      IT IS its own field, you might want to revise your definitions.
      > _that it belongs to tech geeks who have been programming from 4 years old is less passable_
      That was never my claim, that's your skeptical speculation.
      > _Python is a tool that is useful to many types of people from many fields._
      Many fields? What are these fields? What are you talking about? There's only one field and that's programming. Python is a programming language, not some math specific tool or someone's sex tool.
      Whenever you make use of a programming language, you are supposed to read what the creators of the programming langauge per se wants you to pore over-not some idiot on RUclips. You are supposed to read the documention and not _solely_ depend on some moron to learn more of Python.
      This gormless tutor never told his viewers to have a look at the documentation to learn more of any topic, which is very crucial in this field.

  • @mapledrop343
    @mapledrop343 2 года назад +111

    Haha thank you, I see these at work but never got around to fully understanding them

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

      lol, what do you at work where you’d see these but not understand something as simple as this?

    • @madhououinkyoma
      @madhououinkyoma Год назад +28

      @@AnEnemyAnemone1 calm done. Seems like you’ve never coded before. You don’t need to understand everything you see, however unrelated, to work on something.

    • @ck88777
      @ck88777 7 месяцев назад

      @@madhououinkyoma no hes right, you and op are morons

  • @plussin2760
    @plussin2760 7 дней назад

    데이터클래스의 단점은 멤버 변수가 많아질 때임
    객체를 생성할 때 헷갈릴 수 있다는 점에 유의해야 함

  • @Darkev77
    @Darkev77 2 года назад +13

    Can you add custom methods to them like you normally would?

    • @domojestic4155
      @domojestic4155 2 года назад +9

      Probably not, I think the intent here is simply to simplify the process of making classes with nothing but data stored in them

    • @alphanow4199
      @alphanow4199 Год назад +9

      @dataclass just add few methods to your class, like a __init__, so you have a completly normal class, you can to define methods, etc

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

      Of course. If not then this would be useless

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

    What's the catch?

  • @2010sparsh
    @2010sparsh Год назад

    Why would need to compare object if they are equal

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

    thx

  • @slartidan
    @slartidan 2 года назад +4

    Nice, just like Java Records!

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

    This breaks the magic of OOP

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

    That will be awesome if you make a loong tutorial about

  • @nestfoo
    @nestfoo 2 года назад

    King of python ❤

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

      You're watching and learning Python from the wrong source then.

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

    Why learn python right now if AI will replace python Developers faster than any other language?

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

    C#: record Person(string name, int age);

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

    Or we can just use a dict or tuple instead of a class

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

    lol, python devs first time see decorators))))

  • @dakoderii4221
    @dakoderii4221 2 года назад +41

    On large screens, YT places the mute button under the like button so you can never press it and hear the video. All you can do is repeatedly like/dislike. Good job Google!

  • @manojm9084
    @manojm9084 2 года назад +14

    This is a wonderful feature . I have recently used it too.

  • @GauravRajput-yd8lg
    @GauravRajput-yd8lg 2 года назад +12

    man!!! you're awesome. Love your shorts.

  • @smanzoli
    @smanzoli 6 дней назад

    It's important to talk about __post_init__ because real code WILL need it, dataclass cannot do all the __init__ most times.

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

    if you think classes in any programming language are awesome means you still haven’t learned anything about programming besides propaganda

  • @GunZFoX
    @GunZFoX 2 года назад +3

    Arjan Codes uses them a lot. Since I learned from them and their tricks it's true that the code is much more simpler and easier to read.

  • @DrDeuteron
    @DrDeuteron Месяц назад

    If I subclass Person, will repr() say Person or type(self)?

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

    I don’t understand why you’re not just using pydantic.

  • @userou-ig1ze
    @userou-ig1ze Год назад

    when you hear the nasal voice and then the face and you wait to spot some silly code or advice... but I think this time no?!

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

    Your content is great you are just a tad too loud. Try talking in a slightly calmer voice maybe.

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

    Not use classes and you can bypass all that junk too, oh wait I am thinking of C

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

    Still can’t get how all these @ decorators working under the hood 😢

  • @Seeker-gw4vv
    @Seeker-gw4vv Год назад

    Why is python always strange, data types are usually on the left side :/

  • @tommysmith5479
    @tommysmith5479 2 месяца назад

    So are there any situations where you wouldn't want to use a data class?

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

    That's why c++ and kotlin are awesome

  • @Marcus_Sherman
    @Marcus_Sherman 11 месяцев назад +1

    You know, the best way I found to learn python was to just do it. Pick a project or topic that interests you and learn as you go. Learning the theory is great and all but you can read every book and still struggle to put it into practice. Don’t fall for the crash courses or the expensive books. Learn by doing, it’s the best education you can get.
    Good luck my fellow nerds!

  • @TomGrubbe
    @TomGrubbe 8 месяцев назад +1

    So are these basically like a struct in C/C++?

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

    @AllargsConstructor in Java 😮

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

      Lombok not native Java

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

    Why didnt it print the Secound one

  • @oneparticle
    @oneparticle 8 месяцев назад

    what is that theme ur using

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

    time to shove this into my next .py file in school

  • @wayofmuhammad
    @wayofmuhammad 2 года назад +1

    Please make dsa full course in python please🙏

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

    Lombok is here😅

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

    love shorts like this

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

    Name of theme ?

  • @vinayakdumbre2828
    @vinayakdumbre2828 2 года назад +2

    Which theme u are using

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

    Wtf is this lol

  • @chrisnorthall8317
    @chrisnorthall8317 8 месяцев назад

    helium?

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

    Great

  • @69k_gold
    @69k_gold 2 года назад +1

    Niice, but what if there are two string attributes in the class. How does Python allot them, is it based on order of declaration?

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

      dec dataclass has also eq and sort meths

  • @prasoondhapola2875
    @prasoondhapola2875 2 года назад +2

    🤯Brilliant. As a python noob this was mind-blowing for me. More shorts like this please 🙏🙏🙏🙏

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

      Learn to do without this first. You'll be able to read and understand it better I hope

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

      @@patelaa86 yeah it's best to avoid shortcuts in the beginning right

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

      @@prasoondhapola2875 It's better to avoid shorts like this too; don't ever trust anyone on RUclips and expect good content from them when it comes to Programming; _most_ of the time, you will be misguided. However, there are exceptions e.g mCoding, and such channels are quite rare.

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

      @@eeriemyxi Corey Schaefer the GOAT

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

    Well we can use better options (not alternatives) like Pydantic for such use-cases, although I won't say Pydantic Baseclass would be the alternative for Python dataclasses

  • @ytusr-ko5rg
    @ytusr-ko5rg Год назад

    but this is not clear because sometimes there are variables that are bound to the class' parameters when instantiating, but some are not. And I would prefer the old longing way to create a class with initial attributes under the init dunder method

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

    Is it hackerrank problem for python day4 ? :D

  • @liamwelsh5565
    @liamwelsh5565 8 месяцев назад

    tldr a data class is the Python version of records in Java

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

    Interesting, like project lombock for Java

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

    Are you Swedish? Please tell me, I'm dying. ;(

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

    Why do you guys use OOP if you still use data structures?

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

    It's the equivalent to Lombok library in Java

  • @DrDeuteron
    @DrDeuteron 2 года назад +1

    too much sugar.

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

      That's the Zen of Python.

    • @DrDeuteron
      @DrDeuteron Месяц назад

      @@eeriemyxi now I love data classes.

    • @eeriemyxi
      @eeriemyxi Месяц назад

      @@DrDeuteron I don't get it. Did you bookmark my comment to reply it a year later?

    • @DrDeuteron
      @DrDeuteron Месяц назад

      @@eeriemyxi no, the algo does repeats.
      And in the mean time I got space data files with 247 attributes.

  • @rp7814
    @rp7814 2 года назад +2

    which theme?

    • @NoName-lu5tg
      @NoName-lu5tg 2 года назад

      Looks like jellyfish

    • @vinayakdumbre2828
      @vinayakdumbre2828 2 года назад +1

      Not jellyfish

    • @rp7814
      @rp7814 2 года назад

      @@vinayakdumbre2828 its not jellyfish. do you know?

    • @mancattelan
      @mancattelan 2 года назад

      @@rp7814 could be tokyonight or catppuccin

  • @guruteja7151
    @guruteja7151 2 года назад +1

    Awesomeness

  • @HeyImJonas
    @HeyImJonas 2 года назад

    sana masarap ulam mo. salamat

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

    That’s cool

  • @mingyang4835
    @mingyang4835 2 года назад +6

    eyy nice i just started learning OOP in python

    • @derMulti26
      @derMulti26 2 года назад

      Soundd great, can u recommend some resources (youtube channels or books) for OOP in python?

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

      @@derMulti26 Pick a visual conception video on OOP which does what the title say: explain you the concept of OOP; then seek the official tutorial of Python to learn the syntax.

  • @Schen-Ten
    @Schen-Ten 4 месяца назад

    Thank you, i didn't know this.

  • @hawks3109
    @hawks3109 2 года назад

    How is the dataclass decorator implemented?

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

    Like C# records

  • @ziokam1
    @ziokam1 2 года назад

    This is awesome atleast coming from c sharp the data class decorator is easier to grasp

  • @Amy-ve3ke
    @Amy-ve3ke Год назад

    Pretty good

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

    I thought print calls __str__ and __repl__ is called by the interactive interpreter

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

    Great for creating anemic object which are an antipattern by themself.

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

      i mean wouldn't this work well in MVC? it's useful to have data and logic separated sometimes

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

    This works with a list too?

  • @az2252
    @az2252 2 года назад +1

    this is awesome !!

  • @khaledalshammari857
    @khaledalshammari857 2 года назад

    Can you use them instead in all situations?

  • @minorandrianarivo661
    @minorandrianarivo661 2 года назад

    dataclass vs pydantic BaseModel ?

  • @danielazulay4936
    @danielazulay4936 2 года назад +13

    Data Class are extremely slow, they implement most if not all magic methods. Be careful with that. You may want to just you regular classes sometimes.

    • @endgamez7621
      @endgamez7621 2 года назад +2

      how slow?

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

      @@endgamez7621 If you happen to be writing some super efficient code for some very complex task where C could be used but you chose Python, you will then feel the slowness.

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

      @@eeriemyxi so should one learn C instead

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

      @@endgamez7621 Depends.

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

      @@endgamez7621 C is a very useful language but modern Python has so much C or Rust or whatever that's running behind the scenes that for a lot of purposes, Python is faster to write and fast *enough*.

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

    That's awesome

  • @V1kToo
    @V1kToo 2 года назад

    They’re just ok

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

    I thought print calls __str__ and __repl__ is called by the interactive interpreter

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

      str() calls repr() if __str__ doesn't exist

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

      @@schlopping Really?? So I can just implement repr() only and be done with it? Does it work the other way, __str__() only?

  • @nowieszco868
    @nowieszco868 2 года назад

    Thy

  • @rockNbrain
    @rockNbrain 2 года назад

    Which python version was it introduced?

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

    Awesome insights

  • @Rumplestiltzchen
    @Rumplestiltzchen 2 года назад

    Yay!

  • @muhammadal-houry608
    @muhammadal-houry608 Год назад

    nice short
    BTW, namedtuple also can do the same job for you, use it like this
    from collections import namedtuple
    Person = namedtuple("Person", ("name", "age"))

  • @SHONNER
    @SHONNER 2 года назад

    That is insane. Python is insanely good .

    • @thepoorsultan5112
      @thepoorsultan5112 2 года назад

      Probably copied from swift

    • @SHONNER
      @SHONNER 2 года назад

      @@thepoorsultan5112 Python steals from C.

    • @thepoorsultan5112
      @thepoorsultan5112 2 года назад

      @@SHONNER well python [cpython] is written in c so ...

    • @SHONNER
      @SHONNER 2 года назад

      @@thepoorsultan5112 And C is a rip-off of...

  • @shashi_kamal_chakraborty
    @shashi_kamal_chakraborty 2 года назад

    WOW!!

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

    just like Lombok?

  • @Nr8k
    @Nr8k 2 года назад

    Wat

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

    Thanks I knew it but often forget to use it

  • @IamKhoramdin
    @IamKhoramdin 2 года назад

    But less undrestandable

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

      Not when you understand meta classes, decorators, and, most importantly, OOP.

  • @Dukep6
    @Dukep6 2 года назад

    You're a legend!

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

    Amazing!

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

    It turns OOP into Predefined Object Oriented Programming, which is shit.

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

    I don't like them. We don't need 100 ways to do everything. Just makes everything more complex for minor visual thing, not worth

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

      Read the documention, then you will feel and see the worth of this module.

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

      @@eeriemyxi xD

  • @Sugurous
    @Sugurous 2 года назад

    Thanks for it👍🏻

  • @quade-mc
    @quade-mc 2 года назад

    This is disgusting syntax just use c#