The two programming styles - Kent Beck

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

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

  • @RavenMobile
    @RavenMobile 11 часов назад +4

    I am a bit of both. I start with a giant lump of code, and as I start to see which parts of the code are similar and repeating, make some functions that cover those use cases, gradually refactoring. I don't like to get obsessive over doing a lot of functions early, because I don't yet know the details on what pieces will be involved yet, still working out the best approach to code it. Times when I've tried splitting too early I just end up wasting a lot of time after needing to pull all the code back out and rearranging it all.
    In a recent case I was trying to create a recursive function and was having a lot of troubles wrapping my head around it. This function was not split up at all, so it was a few hundred lines of code by the end. I was about to start refactoring it with named sub-functions, but then I realised that the approach I had taken wasn't ideal, and reorganised a lot of the code and made changes. If I had already created all the sub-pieces, it would have been a lot more work redoing it. As it was, I could just quickly copy and paste the chunks of code into the new order and change the bits around the edges.
    Get the code fully working, then reduce it into pieces.

  • @perfectionbox
    @perfectionbox 20 часов назад +15

    a frustration in programming is that a feature (which is a mental concept) doesn't always map neatly to a single module or set of modules. Sometimes you get these cross-cutting concerns.

    • @nickbarton3191
      @nickbarton3191 20 часов назад +2

      @@perfectionbox That's true, but we try our level best to minimise it. I've found that a more optimal solution is not the first one, have to live with it for a while. Nearly every sprint starts with some refactoring.

    • @uumlau
      @uumlau 13 часов назад

      You always get cross-cutting concerns. Why? Because reality is full of many-to-many relationships, while typical programming approaches outside of SQL and databases are hierarchical. E.g., any JSON or XML doc is a hierarchy, not a set of relationships. What Beck is talking about here might be regarded as "factors". In psychology the "Five Factor Model" of personality arises from "clusters" of words that people use to describe themselves. So it's reasonable to regard those clusters as actual "factors" of human personality. So what Beck is getting at is that the "poop" comes in clusters, too, so it makes sense in some cases to formalize that cluster and make it a "thing" that is easier to manage. It doesn't get rid of the many-to-many relationships, but it puts them in one spot so that the rest of your code is mostly hierarchical.

    • @fred.flintstone4099
      @fred.flintstone4099 4 часа назад

      Another frustration is when I create a class but then I want to have another implementation that I can swap out so try to create an interface but struggle because the implementations work in quite different ways so it becomes hard to make a interface.
      Another frustration is when I want to separate concerns so I have two classes, one class use the other class, but I find it difficult to decide what belongs in which class, the boundaries of the concerns.

    • @nickbarton3191
      @nickbarton3191 2 часа назад

      @fred.flintstone4099 You need to learn about Liskov substitution principle, that'll help with your first part.

  • @michaelbaker2718
    @michaelbaker2718 12 часов назад +3

    I'm a firm believer in a combination of these two approaches. Splitting is best for code that is likely to be reused or needs to be more modular, whereas lumping is better for improving the readability of some more complex functions. I like the way he put it, where you're lumping the crap together so at least you know where it is.
    My general rule is that functions should serve a purpose which can be described by its name. It doesn't necessarily matter if the function is small or large so long as it achieves its task. Further, anyone reviewing the code should be able to understand it without having to read each dependency. It may make sense to break some functional components into their own functions, provided they again, have a discrete purpose which can be easily conveyed by the function name, but conveying their purpose through naming is essential. Splitting things unnecessarily makes the code convoluted and difficult to read and understand. That said, lumping things together can make code inefficient to review which is improved with selective splitting.

    • @fred.flintstone4099
      @fred.flintstone4099 6 часов назад

      Yes, if you split the code into too many functions you end up with ravioli code.

  • @timelston4260
    @timelston4260 18 часов назад +5

    I think it's often harder to read things all in one place if there is too much complexity looking back at you. If I hide some of the complexity under readable object and method names, the high-level flow becomes more comprehensible. If someone is interested in the complexity that becomes hidden that way, it's easy enough to click into it.

    • @fred.flintstone4099
      @fred.flintstone4099 6 часов назад +1

      You can do things such as splitting out the expressions in your if conditions into a private function with a name that describes what it does, so instead of "if x < 1 && y > 2 || z == 3" you do "if is_valid(x, ,y, z)".

  • @nickbarton3191
    @nickbarton3191 21 час назад +6

    I'm a splitter. The problem with lumping code together is that it's all to easy to create poor coupling and hence side effects. Splitting code enforces discipline.

    • @NukeCloudstalker
      @NukeCloudstalker 17 часов назад +5

      Conversely, splitting necessarily obfuscates and makes it easier to create bad state and over-complicated flows.
      Either has downsides if done naively, but its worth mentioning that coupling is only an issue if it is the wrong coupling. Obfuscation is a cost you and everyone on your team constantly pays the price for.

    • @michaelbaker2718
      @michaelbaker2718 11 часов назад +1

      @@NukeCloudstalker Your point about either approach done naively is problematic, which is why it shouldn't be one or the other, but rather an intentional application of both.

    • @nickbarton3191
      @nickbarton3191 11 часов назад

      @@michaelbaker2718 Nice reply.

    • @nickbarton3191
      @nickbarton3191 11 часов назад

      @@NukeCloudstalker Maybe my comment has to do with recent refactoring experience of files 8000 lines long!
      But I do take your point, it's all about splitting wisely.

    • @babgab
      @babgab 10 часов назад +1

      "Splitting code enforces discipline"
      That doesn't track with my experience. In my experience, splitting code gives you a *facsimile* of discipline, by ticking the boxes that The Masters say you should tick, that can deceive your team into thinking they don't need to spend the energy being disciplined. Everyone can go off and play in their sandbox at the level of quality they find fun, and the end result is hundreds of tiny trivial functions, lots of duplication, and no way to see the big picture. Lumping code makes it obvious up front that, among other things, you need to be disciplined to not turn the code into something makes your successor scream in frustration, so people are more motivated to actually spend that energy on discipline. Lumping code forces collaboration because you're all working in the same space. Some people don't actually like collaboration, of course, so splitting makes them happy...

  • @markharris142
    @markharris142 6 часов назад

    I am a lumping old man programmer. Early in my career (1980s), I learned how to read large programs really well, and was able to track down difficult bugs. Developing a program is a lot like the stages in writing (drafting, revising, and editing). Editing doesn't come first, it comes after the final draft. For me, its easier to have it all in one place as possible to do the drafting and revising. Splitting decisions is a lot like editing decisions.

    • @aytviewer2421
      @aytviewer2421 3 часа назад

      I am fine with splitting it up. YET, I must be able to see ALL functions/procedures in a file in one single listing. I do not like coding environments that only let you see the function you are working on. I need to be able to see it all at once and scroll as needed. I started in to mid '80s. COBOL and BASIC followed shortly by C and Oracle Pro-C. Was also familiar with Fortran and Pascal at the time, though that was likely less than 5% of my time with the bulk of my work in COBOL or BASIC depending on the project.

  • @markoates9057
    @markoates9057 13 часов назад

    As an avid splitter for years, I recently rediscovered being a lumper, specifically for a class that represents an object (and many derived objects) in a game. This happened strictly so that the machine would not be jumping around vtables and pointer lists in performance-critical code.

  • @StyzeSoulmaker
    @StyzeSoulmaker 9 часов назад

    Used to be a splitter but more and more becoming a lumper. It's just so much easier to debug or change something if all the logic related to one thing is in the same place, and some parts are not reused in other places. Of course ultimately it depends on the situation. Repeating something in a few places often makes the system itself a lot simpler and more robust, even if it looks ugly or wrong to us developers

  • @ivanjermakov
    @ivanjermakov 5 часов назад

    There is always a balance between the two. Since both approaches have own benefits, it only comes with practice when lump is too big and when split is too sparse.

  • @jmrah
    @jmrah 4 часа назад

    I'm a lumper, and proud of it!

  • @funkdefied1
    @funkdefied1 15 часов назад +3

    I prefer splitting. It might be an adhd thing. I get overwhelmed trying to hold too much state in my head

    • @pudicio
      @pudicio 9 часов назад

      This comment doesn't make sense to me. If you split you need to keep more state in your head?

    • @fred.flintstone4099
      @fred.flintstone4099 5 часов назад

      @@pudicio Well you can move out a long complicated if condition into a private boolean method with a good name.

  • @aytviewer2421
    @aytviewer2421 3 часа назад

    I think I am a lumping splitter. I like lumps of related code split up into relevant functions/procedures. I guess I like classes, yet I do not like multi-inheritance. I learned the hard way back in the early '90s that multi-inheritance is a complete recipe for weird behavior and bugs that can be difficult to reliable replicate and troubleshoot. It sort of like having two equal bosses at work assigning you conflicting tasks that sometimes have incompatible requirements.

  • @JohnHall
    @JohnHall Час назад

    I do both depending on the tool/language.

  • @iAPX432
    @iAPX432 8 часов назад

    For my last prototype I was a slumper. For my last micro framework project, I was a splitter.
    One needed to get developed fast to have something working to show. The second one needed to be correctly architectured, readable, understandable while still working.
    One thing is that you could *NEVER* correctly go from one to the other: you have to rewrite from scratch!

    • @aytviewer2421
      @aytviewer2421 3 часа назад

      In code, I think it is easier to split lumps than to lump splits.

    • @iAPX432
      @iAPX432 2 часа назад +1

      @@aytviewer2421 You have to rethink the responsibilities and contracts to create clean interfaces (not "interface" in sense of some OOP languages). Elsewhere it will still be slump code in a clean code attire...

  • @wiczus6102
    @wiczus6102 15 часов назад

    Splitting relies on trust that down the line the things are what they say they are and that they are grouped in a way that is predictably accessible.And if the naming is good then it is also easier to navigate.

  • @jamesigoe
    @jamesigoe 13 часов назад +2

    Well, I would think you start with lumping - draw the big picture - then breaking it down into details...

    • @michaelbaker2718
      @michaelbaker2718 11 часов назад +2

      That is how I started, though with experience it became more obvious where to split and when it's best not to. When in doubt, I tend to lump, because as you say, you can always break it down later.

    • @aytviewer2421
      @aytviewer2421 3 часа назад

      When I need a fast-as-possible prototype for a demo, I lump. Otherwise, for reliable production code built for years -- I split.

  • @sanderd17
    @sanderd17 8 часов назад

    For me, mental load is important. There's a maximum of stuff I can keep track of in my mind.
    If the code is very repetitive I don't mind files with thousands of lines in the global scope.
    If the code is clever, then things need to be split up, scope needs to be limited, files smaller.

    • @aytviewer2421
      @aytviewer2421 3 часа назад

      Mental load is eased by having 3-4 large monitors where you can see many windows, specs, functions, and data at a glance. At least it is for me!

  • @Coburah
    @Coburah 18 часов назад +1

    I'm a splitter, but am extremely keen on keeping things grouped as locally as possible, like modules, to prevent improper (re)use of methods private to the module. In C#, I keep several classes in the same file as a module if it's small enough, or even use nested private classes.

    • @fred.flintstone4099
      @fred.flintstone4099 5 часов назад

      And always use the private visibility modifier, and if that don't work then use the internal visibility modifier, and then lastly if that don't work, only then use the public visibility modifier.

    • @Coburah
      @Coburah 5 часов назад

      @fred.flintstone4099 definitely!

  • @cassianofranco3082
    @cassianofranco3082 18 часов назад +1

    all in one place make easier for AI to get context of your code

    • @aytviewer2421
      @aytviewer2421 3 часа назад

      Not to get on a rant--but AI has absolutely wasted more of my time than helped. It's helpful predictive naming/renaming of variables based on what I have been typing has caused me pain by altering working code. I no longer use it. (Looking at you Co-Pilot!)

  • @adambickford8720
    @adambickford8720 13 часов назад +1

    I was a splitter to the most atomic level for over a decade. SRP! Demeter! Abstraction! Then I realized it was stupid. Breaking a solution into dozens of 'collaborators' that, in practice, only collaborate in 1-2 ways, is mental masturbation. Yagni.
    The longer you can wait to make *informed* abstractions, the better. *Maybe* your sweet abstraction works. Great, you spent time writing code when it wasn't needed but turned out useful. You could also just... wait until you know what you need and write it then.

    • @babgab
      @babgab 9 часов назад

      I sometimes wish I had a tool that would automatically "de-split" code for me so I could re-evaluate the value of its current decomposition. Like how some compilers optimize by inlining code, but on the source text itself.

    • @adambickford8720
      @adambickford8720 8 часов назад

      @@babgab Exactly. Things like loose coupling have downsides. It isn't inherently better; you really only want loose coupling where its actually providing value.

    • @aytviewer2421
      @aytviewer2421 3 часа назад

      Ahhhh, with age and experience comes wisdom over time. It can only be self-learned through hard lessons and reflection upon maintaining your own code base.

  • @asdqwe4427
    @asdqwe4427 15 часов назад

    A lot of the time people create huge amounts of indirection by splitting in the name of clean code.

    • @wiczus6102
      @wiczus6102 15 часов назад

      Indirection is removed by the compiler so who cares.

    • @adambickford8720
      @adambickford8720 13 часов назад

      @@wiczus6102 The humans that have to maintain that illogical mess

    • @wiczus6102
      @wiczus6102 13 часов назад

      @@adambickford8720 Putting a piece of code under a category does not change the logic in any way and is easy to navigate if you don't code in notepad.

    • @adambickford8720
      @adambickford8720 12 часов назад +2

      @@wiczus6102 This has NOTHING to do with technology or code editors.
      Every level of indirection makes it harder to understand. Period. Sometimes that's worth it, sometimes not.

    • @wiczus6102
      @wiczus6102 12 часов назад

      ​@@adambickford8720 You don't understand what you've just said, that's why I won't argue with you.

  • @georgehelyar
    @georgehelyar 8 часов назад +1

    Both extremes are bad. The best place to be is in the middle.

  • @prashanthb6521
    @prashanthb6521 10 часов назад

    I am a splitter.