Metaphorically Speaking
Metaphorically Speaking
  • Видео 17
  • Просмотров 36 508
Primitive Obsession: An OOP Code Smell
Discover what the Code Smell "Primitive Obsession" means in coding and how it can signal potential issues in your codebase.
This video breaks down how to recognise this common code smell, understand its implications, and explore ways to refactor your code using Value Objects as the solution to resolve your Primitive Obsession.
Learn how to improve encapsulation, avoid code duplication, and ensure better maintainability by addressing Primitive Obsession in your projects.
---
Website: acairns.co.uk
Twitter: andrewcairns
Discord: acairns.co.uk/discord
Substack: acairns.substack.com
---
0:00 Introduction to Primitive Obsession
1:26 Recognising Primitive Obsession
2:54 Understanding Primitive...
Просмотров: 2 913

Видео

Composition over Inheritance Explained by Games! #programming
Просмотров 13 тыс.8 месяцев назад
Let's explore the principle of Composition over Inheritance in the context of Object-Oriented Programming (OOP) and... our favourite 8-bit video games! This video uses metaphors and analogies from retro video games to explain the concepts of Composition and Inheritance. It highlights the advantages of Composition and why it may be a more beneficial approach. The video illustrates the principle ...
What is a Command Bus? #software #architecture
Просмотров 1,5 тыс.9 месяцев назад
Bonus points for letting me know fun ways the metaphors/analogies fall apart! 🤣 What is a Command Bus? In this video, we'll take a quick look at what a Command Bus is and how it is similar to a bridge connecting land together. We'll explore how the car is a Message which progresses through a Message Bus (which is what a Command Bus is) encountering different segments we can think of as Middlewa...
Dates and Times are HARD! #php
Просмотров 1,3 тыс.11 месяцев назад
Dates and times are hard (and not just in Laravel or PHP!), but they aren't broken. Most of the time, they work fine, but when they don't - it can be super confusing. From off-by-one errors and almost borderline unexplainable results from calculations - it's easy to fear dates. But don't. Accept the fact that dates can be weird because dates are weird in the real world, too! In this video, I ex...
Artisan shortcuts can be dangerous for your project! #laravel #php
Просмотров 4 тыс.Год назад
Don't make this mistake in your Laravel project. Laravel uses Symfony's Console package which allows you to specify shortcuts when running commands from the terminal. However, this is a terrible idea in production as it leaves your vulnerable to making a previously stable command ambiguous. 0:00 intro 0:51 shortcuts 1:15 source diving 1:35 pattern matching 2:47 strong opinions 3:26 outro Websit...
What Are Transaction Boundaries?
Просмотров 668Год назад
What Are Transaction Boundaries?

Комментарии

  • @cosmotect
    @cosmotect 23 дня назад

    As a non coder working with visual scripting languages I have been discovering these concepts by myself, and it's quite rewarding to see my suspisions confirmed by someone more knowledgable

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

    I love the nuance you put in this. It's so easy to go the easy route and make some clickbaity title and going "Why you shouldn't be using primitives" or something like that. But you explained what a code smell is, that primitives are fine as long as you're aware of better options in certain scenario's. Looking forward to what topic you'll cover next!

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

      Really appreciate the kind words and glad you enjoyed the video. Working on decomposing monoliths at the moment, will likely be creating content on the strangler vine pattern or branch-by-abstraction. Would these topics interest you?

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

      @@metaphoricallyspeaking I’m very interested in the strangler vine pattern, as we’re employing that at a project we’re working on. One of the big question marks for me is how to not just start, but actually work towards finishing the ‘strangling’, as you might end up with two half implemented solutions.

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

    Great video once again!

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

    I don't think "Primitive obsession" is the best term to use, at least in the example you described. I absolutely agree that using primitives for everything is a bad practice, just to be clear. Your video demonstrated that very well. The hammer and nail analogy fits, without a doubt. But I would be inclined to think that such cases occur due to the programmer not spending enough time thinking about the problem, or in case of people newer to coding, unawareness that better solutions exist. It doesn't imply an obsession with using primitives, because I'm sure most people would come up with a solution like yours after spending some time thinking about a better way to handle input validation. It's probably other factors that led to the code smell. It's not like the average programmer just can't help himself but use primitives wherever possible, as funny as that thought may be. But the term is more of a semantic issue anyway. As stated, the problem is real, no matter what it's called. Great video, I hope to see more of you!

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

      Well put. Appreciate the kind words and the constructive feedback! The term was popularized by Martin Fowler in his Refactoring book. Not quite sure if he invented it, but it’s one of many OOP anti-patterns I’m looking to cover.

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

    Good explanation, like

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

    I have Enum Obsession, is that bad?

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

    the foo is a valid e-mail address. But not many know that.

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

    1:50 Dart programming language and other programming languages solve this problem with named parameters. It's hard to mix them up, and when you do, only the name characteristic determines to which variable the values are assigned.

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

      Even the programming language in the video supports named parameters, but it's syntactic sugar. It's still possible to make a mistake and mix things up, even if the readability is improved, and still not receive any type violations at runtime. Maybe it's different in dart?

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

      @@metaphoricallyspeaking Yeah you're right, you can still mix them up, given enough time, a mistake will creep in

  • @AndrewGraaff-n4g
    @AndrewGraaff-n4g Месяц назад

    Your content is great. And your communication is very good. The problem and solution described are informative and helpful. But I don't agree with the definition of domain events. A domain event is simply an event which is related to a business process/action being performed e.g. StartEngine Command emits a 'EngineStarted' domain event. These should definitely never be consumed by other domains, external services etc. within the same transactional boundary.

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

    dude that hammer sfx was so much louder than other things I thought someone opened a gate behind me

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

      I didn't add any hammer sfx - are you sure it wasn't really a gate?! Just kidding, sorry. Still learning sound design and this is solid feedback, appreciate it!

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

      @@metaphoricallyspeaking Hahaha I was walking through a field in the countryside listening quietly through cheap and tinny Bluetooth headphones at 2am so I was prone to being spooked, it honestly made me jump a little bit, I rarely comment on RUclips videos but I figured I would while I stopped to catch my breathe. glad to know it's helpful 😂

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

    Simple and engaging explanation, and beautiful animations and editing - thank you!

  • @diegom.3782
    @diegom.3782 Месяц назад

    La verdad... espectacular explicación! muchas gracias, saludos desde Argentina

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

    Prefer a written version? There is a visually-explained post on my blog: acairns.co.uk/posts/primitive-obsession Disagree? Got feedback? Let me know below, or jump on Discord: acairns.co.uk/discord

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

    SuperMario is a Mario. Mario: It's a me?

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

    That's a great video, nice explanation and incredible visuals ! Thanks for sharing you amazing work

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

    I don't like the fact that this video misses the importance of interfaces and polymorphism which are solutions to most of the inheritance problems that the video talks about. I honestly think that if you're going to make any kind of program and you're being smart about you program's architecture, you will inevitable use both.

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

      That's fair. Polymorphism is certainly important. The video aimed to demonstrate how composition can address specific problems associated with inheritance. Hopefully I didn't imply it's the only necessary paradigm.

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

      @@metaphoricallyspeaking No not at all, the video was great! I just felt like it was a bit unfair for inheritance hahah

    • @anand_-
      @anand_- Месяц назад

      ​@@RUEDO123 hey do you have any resources on polymorphism and how do use interface ... ?

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

      @@anand_- No but it's pretty easy to find them with a google search

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

      @@anand_- not at the top of my head, but I'm sure there are videos and tutorials explaining the concepts

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

    Whoa. The "has a" vs "is a" statement flipped the missing switch in my brain. You rock brother.

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

      Thank you - glad I could help you build a mental model of Composition over Inheritance! 💪

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

    Amazing explanation

  • @cariyaputta
    @cariyaputta 3 месяца назад

    Nice explanation.

  • @edgeeffect
    @edgeeffect 3 месяца назад

    I don't understand how all the managers have become so obsessed with Laravel... I've used... uuuum.... 7 .... 8? PHP frameworks over the years and I'd say that Laravel is by far the worst. And way too much magic is one of the many things that make it so.

  • @alexMKDtheBEST
    @alexMKDtheBEST 3 месяца назад

    This was such a cool and beautiful video! I'm probably gonna binge all your videos when I get back from work later

  • @Rai2M
    @Rai2M 3 месяца назад

    2:42 int player_state = 1 // 2, 3, 100, 102020 no inheritance, just pure states )))

    • @metaphoricallyspeaking
      @metaphoricallyspeaking 3 месяца назад

      Sometimes we might not want to merge all logic into a single class and toggle based on the state

    • @UglyMoneyChannel-pw8hl
      @UglyMoneyChannel-pw8hl 3 месяца назад

      @@metaphoricallyspeaking so basically separate the states into separate scripts?

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

    first time watching one of your videos, and honestly im impressed. I hope this goes well for you so that i can enjoy these videos in the fututre and so that you can improve even more the quality.

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

    Refreshing to hear real world advice, rather than the usual "always do this" nonsense. Just because a toolset has a tool, doesn't mean should or shouldn't use it. Tools are not good or bad by themselves, but using a hammer for a screw is a bad idea. Great content

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

      Thanks Dave, Glad you enjoyed the video! Nothing is black and white - just lots of different shades of grey in different contexts. It's our jobs as engineers to understand the tradeoffs and make the best decision with the information we have. Also, I just recently used the hammer/nail metaphor in an article! 🤣 acairns.co.uk/posts/primitive-obsession

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

    Fantastic video! Loved the design, graphics, editing and relatable gaming analogies throughout. Honestly, top work!

  • @pindab0ter
    @pindab0ter 6 месяцев назад

    That’s one hell of a foot gun! It would’ve taken me quite a while to figure that one out. Good to show that explicit is better than implicit.

  • @pindab0ter
    @pindab0ter 6 месяцев назад

    This is amazing stuff!

    • @metaphoricallyspeaking
      @metaphoricallyspeaking 6 месяцев назад

      Thank you! ☺️

    • @pindab0ter
      @pindab0ter 6 месяцев назад

      @@metaphoricallyspeaking I do think there’s a market for accessible and engaging explanations of software engineering concepts. Looks like you’ve got it nailed down. Instantly subscribed!

    • @metaphoricallyspeaking
      @metaphoricallyspeaking 6 месяцев назад

      @@pindab0ter Thank you. Thanks for the kind words! :D Not nailed down at all, I'm afraid. Learning a lot as I go! Haha

    • @pindab0ter
      @pindab0ter 6 месяцев назад

      @@metaphoricallyspeaking the combination of your voice, your visual style and the fact that you’re covering not beginner but intermediate topics make me look forward to you future videos!

  • @adiadiadi
    @adiadiadi 6 месяцев назад

    Awesome vid!! Did you record this inside of a video game?

    • @metaphoricallyspeaking
      @metaphoricallyspeaking 6 месяцев назад

      Yeah, I did indeed - Fortnite. My son’s favourite at the moment

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

    Fantastic production quality and excellent teaching skills. Great work 👏👏

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

    The graphic design is crazy. Easy sub earn

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

    Prefer a written version? There is a visually-explained post on my blog: acairns.co.uk/posts/composition-over-inheritance Disagree? Got feedback? Let me know below, or jump on Discord: acairns.co.uk/discord

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

    haven't watched the video yet, just wanted to say I (a 20yr veteran programmer) just learned about the concept a few weeks ago, though I've been an unknown advocate and practitioner of composition since being introduced to requisite oop in Java in high-school. I've carried the notion through all my projects since. always thought inheritance was a bad idea outside of strict polymorphic virtual functors where you can leverage the compiler to produce code states nessesary vs boilerplate every time a new instance is found. templating in c++ does exactly this for functional and procedural bros ok, watched the video. that last sentence "use inheritance when it exists in that domain" is basically saying the same thing. nothing in the real world actually does this. the nature of reality is to have many close but independently unique variants with- at best- partial heredity on average due to the imperfect copy problem. practically nothing is perfectly all of one other thing plus new stuff.

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

      Super detailed reply. Appreciate you sharing your perspective! 🙌

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

    @ThePrimeTimeagen We need your reaction. Primeagen approved or nah?

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

      This was a great video @metaphoricallyspeaking. Keep up the great work!

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

      I would be proud and terrified - in equal measures! But, if he were to roast the video, at least I could take the low-road and mock his hair! 😁

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

      Appreciate the kind words. Will certainly try! :)

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

    Nice. But the question is: do you really need it? "After column" is not especially performant on large tables as data needs to be shifted.

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

    I really enjoyed this one, especially the animation. Great work.

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

    Love the style for sure! The ad threw me for a loop though. I thought I had click out of the video by accident.

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

      Unfortunately I haven't reached the dizzying heights RUclips have set for monetisation and can't control when the ads show 😢 One day, maybe... Glad you enjoyed it, though!

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

    this video has so much style, I love it, keep up the good work ;)

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

    Very interesting insights, keep it up! Subscribed.

  • @quetzalcoatl-pl
    @quetzalcoatl-pl 8 месяцев назад

    5:07 - oh yes, bonus point for you and scott

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

      Scott is incredible. And his cinematography is at such a high standard. His drawer organiser video made me impulse-purchase a 3d printer.

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

    Nice. Subscribed.

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

    nice explained, but the word "middleware" is not your friend *g*

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

      I'm not sure if you don't like the way I say "middleware", or if you don't like using middleware? 😅

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

    This was very helpful! But some more code examples would be nice!

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

      Yeah, I think that's fair. I do feel code is better consumed in a different format, though - like a blog post? What do you think? Would a follow-up blog post be a useful addition? Glad you found the video helpful and appreciate the constructive feedback! 🙌

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

    Great video! Carbon has numerous "...NoOverflow()" methods (->addMonthWithOverflow()), but you have to know they are there :/ I've also ran into this issue many times.

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

      Thanks Chris! And, thanks for sharing - I had no idea these methods existed!

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

    Awesome explanation, I’ve always struggled to find a good analogy for command bus this sums it up perfectly! Keep it up!

  • @wildfoster
    @wildfoster 10 месяцев назад

    Why not use the php in-built strtotime() function?

    • @metaphoricallyspeaking
      @metaphoricallyspeaking 10 месяцев назад

      Like this? $timestamp = strtotime("2023-10-31 + 1 month"); echo date("Y-m-d H:i:s", $timestamp); :)

  • @phpannotated
    @phpannotated 10 месяцев назад

    What an awesome video! You've gained a subscriber :)

  • @Gustavo-kz8wx
    @Gustavo-kz8wx 11 месяцев назад

    days since last timezone issue: -1

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

    Clear and succinct! $subscriber_count++;

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

    In my opinion. The library should throw an error instead of taking the initiative and turning 31st of November to 1st of December

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

      I agree. We can recreate this in vanilla PHP, too. But for me, this isn’t intuitive. And there are so many edge cases like this with dates!

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

    Great video, straight to the point and good editing 👍