• lysdexic@programming.dev
    link
    fedilink
    English
    arrow-up
    7
    ·
    edit-2
    11 months ago

    From the article:

    (…) but recently, another type of criticism seems to be on the rise.

    The code that I suggest is too verbose. It involves too much typing.

    This reads like a one-sentence strawman. Describing code as “too verbose” is really not about the risk of carpal tunnel syndrome. It’s about readability and cognitive load.

    The blogger seems to almost get the point when he writes the following:

    In short, the purpose of source code is to communicate the workings of a piece of software to the next programmer who comes along. This could easily include your future self.

    The purpose of source code is to communicate (…) to the next programmer who comes along.

    If you make the mistake of going the “enterprise quality java code” meme approach, you’re making the next programmer’s life needlessly harder.

    The blogger then tries to make his case with verbose code, and makes the following statement:

    Which alternative is better? The short version is eight lines of code, including the curly brackets. The longer version is 78 lines of code. That’s ten times as much.

    I prefer the longer version. While it takes longer to type, it comes with several benefits. (…)

    This is yet another strawman. The longer version is awful code, not because it’s longer but because it’s needlessly jam-packed of boilerplate code. Ignorign basic things like interfaces and contracts, It’s been proven already that bugs in code are directly proportional to the number of lines of code, and thus the code the author prefers is likely to pack ten times more bugs.

    The shorter code in this case would not be the 78-loc mess that the author picked as the thing he prefers. The shorter code in this case would be something like onboarding the project onto Project Lombok to handle all-args constructors, property methods, and even throw a builder in for free. This requires onboarding Lombok to the project, and add two annotations to the short example. Two lines of code, done.

    After the blogger fails to make his case, he doubles down on the typing non-sequitur:

    Perhaps you’re now convinced that typing speed may not be the bottleneck (…)

    This is a blog post that fails to justify a click. It’s in the territory of “not even wrong”.

  • vettnerk@lemmy.ml
    link
    fedilink
    arrow-up
    6
    ·
    11 months ago

    Typing speed matters in programming the same way hammer hits per second matters when building a house. There’s a little bit more to it.

  • Anders429@programming.dev
    link
    fedilink
    arrow-up
    5
    ·
    11 months ago

    I’m a bit confused about the premise of the article. Does anyone assert that typing speed is a bottleneck at all? I’ve been in the industry for years, and have never heard that claim.

    I do agree about the whole “less code is not always more”, but I get confused when the author keeps bringing it back to typing speed.

    • PowerSeries@lemmy.ca
      link
      fedilink
      English
      arrow-up
      5
      ·
      11 months ago

      I’ve watched some slow typists program, and I think I have the answer. If it takes you a while to type the code out, you are much more likely to stick to the first approach that works, and not rewrite it as much.

    • dbilitated@aussie.zone
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      11 months ago

      yeah the issue honestly is how much someone else has to read to understand your code. it’s weird because the whole article is about making readable code for the next person and he never stops to address the fact that leaving 10x as much code to read might also make life more difficult.

      I feel like he just wanted to make a point about how it’s nice to make types immutable and suggest other techniques can be worth implementing too, which I agree with, but honestly his premise is a trainwreck.

  • a1studmuffin@aussie.zone
    link
    fedilink
    English
    arrow-up
    3
    ·
    11 months ago

    I discovered this very quickly after breaking a finger. One-finger typing didn’t slow me down at all. Turns out my brain was the bottleneck.

  • Kissaki@feddit.de
    link
    fedilink
    English
    arrow-up
    3
    ·
    11 months ago

    Are people, their critics, really bothered with the writing aspect of verbose code?

    Verbose code - and their example shows it quite well - is less concise. To me, their example and reasoning looks more overly verbose, over-engineered rather than well or thoroughly designed and safe.

    What makes more sense depends on the context. Where is and will it be used? What is it being exposed to?

    A simple data holding class for one “internal” layer to the next can have a very simple form, so it’s easily understood. It may not be safe against misuse or mistakes, but the simplicity and clear use-case and intention much outweighs those costly safeguards to me. For maintainability, for readability, for clarity.

    It’s always a balancing act between simplicity and easy understanding vs safeguards and costs. If there’s less risk you can make it much simpler - which reduces other, less obvious risks and costs.


    The example made me immediately spot how C# quite a while ago introduced language constructs for what would otherwise be a lot of boilerplate programming like they do in their example.

    public record Reservation(DateTimeOffset Date, string Email, string Name, int Quantity, bool IsAccepted);
    

    no need for 78 lines of code with 9 methods.

    C# also has the with keyword for copy-adjusting immutable types.

    And required init syntax provides another alternative for an effectively immutable type.

    public class Reservation
    {
        public required DateTimeOffset Date { get; init; }
        public required string Email { get; init; }
        public required string Name { get; init; }
        public required int Quantity { get; init; }
        public required bool IsAccepted { get; init; }
    }
    
  • nous@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    11 months ago

    8,000 characters in five hours is 1,600 characters per hour, or 27 characters per minute.

    This is irrelevant. Typing when coding is not evenly spaced out over those 5 hours. It is sporadic with most of the time thinking or reading documentation or reading source code and trying to figure out what you want to type. No good conclusions can be drawn from this logic and makes that whole part of the argument irrelevant.

    If I were typing that slowly I would quickly forget what the hell I was even trying to do in the first place. Which is the bigger part - when you do need to type you want to quickly get the ideas you have down as fast as you can think them. Going too slow can cause your mind to wander and that can really hamper your productivity.

    There is also the cost of context switching. And it is a context switch to go from writing ideas down to making sure I have all the boiler plate and syntax correct. The less of the need for doing that the better IMO.

    And TBH I don’t really understand the rest of their arguments. They introduce two bits of code, one very short simple class then one with lots of helper methods to set various things while creating a new object. And then concludes with a short paragraph on some real benefits without really explaining why. With the whole paragraph being more of an argument about immutable code being better rather than longer vs shorter code. Then follows up with an entire section on why his code increases maintenance as refactoring requires more points to update with his immutable code and thus prefers languages like F# where the immutable version is a one liner… Which defeats the whole argument that typing is not the bottleneck? I really don’t follow his logic here.

    Apparently, it has to be explicitly stated: Programmer productivity has nothing to do with typing speed.

    I feel they have completely failed to convince me of this fact. Despite me already thinking it is not one of the more important factors of productivity and there are better things to optimise around.

    My opinion is that code length is not that important a factor, but you should not go hog while and write the longest things you can either. Every extra bit of code should add some value somewhere. Like taking his examples, spending a bit of time writing the immutable version here lets you reduce the amount you need to write when using that code. Which is a trade-off that can be worthwhile - increasing typing now for reducing typing later. But also the reduced typing makes the where the code is used easier to read and clearer as to what is happening, get a copy of the object with one field updated. That is a nice concept to have and read. Without the need to refer to all the fields every time you want a copy.

  • onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    11 months ago

    I agree, typing is not a bottleneck, repeating yourself is. All that boilerplate code in the example, shouldn’t have to be written. It’s wasted time.