Mine is that the useState hook is an actual plague on the entire React ecosystem. Regardless of your opinions of React, if you wanna use something then use it right.

  • jonathan7luke@lemmy.zip
    link
    fedilink
    arrow-up
    0
    ·
    11 days ago

    Care to elaborate on this? Not saying you’re wrong necessarily, that’s just a pretty bold claim and I’m curious why.

    • danhab99@programming.devOP
      link
      fedilink
      arrow-up
      0
      ·
      11 days ago

      React works by maintaining a virtual representation of the DOM. When you dispatch state changes into the virtual DOM react can determine which components depend on the change and which side useEffects run.

      My gripe is that YouTube tutorials teach that the useState is the equivalent of a variable. This encourages average developers to problem solve solutions that end up using React’s Virtual DOM for business logic. The YouTube tutorials have react devs planting 100s of useStates - some of which don’t directly induce a visible-on-screen rerender - and then ⅒ as many useEffects to bind these states together. This means that for the Virtual DOM to come to the conclusion as to what html elements need to be changed and how it has already mutated 20-50-100s of times and the CTO tells me the react app is slow and they’re mad.

      If 2 states have the opportunity to mutate each other back and forth then the truth is that you have 2 perspectives of the same state. And React gives you solutions for that - proper solutions - the useReducer hook is for defining these complex state mutations and the Context API for communicating that state to any component.

      And this has me quintuple pissed off because these same tutorial grade react devs install REDUX as compulsively as a pack-a-day smoker (that’s #3). They use Redux to file variables in JavaScript memory (that’s #4) like it’s a global variable and rarely if ever use it for the complex state mutations they need instead I’ve seen react devs write components pull state out of redux into a component just so it can mount useEffect and process the state and dispatch the result back into redux. Let’s not even bring up how the react-redux binding library literally uses the React Context API (that’s #5).

      • kionay@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        11 days ago

        Since it’s apparent you can spot what tutorials do it wrong, would you be able to provide links or references to online tutorials that get it right?

        One of the most valuable things you can do if you know a technology well enough to have these gripes is not just to condemn people fucking it up but shine a light on people that are trying to do it well.

      • Cratermaker@discuss.tchncs.de
        link
        fedilink
        arrow-up
        0
        ·
        11 days ago

        As someone who’s worked with react for years, I’m convinced that react itself is the problem and there’s no way to educate new people on the proper way to use it without essentially teaching them everything the abstraction is intended to do for them. Why should newbs have to care about mutations and state dependencies when the api is apparently designed to help them forget about those things?

        • FooBarrington@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          11 days ago

          The React devs fucked up by not wrapping state in trackable containers, and we’re all paying the price with laggy apps.

        • shoo@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          11 days ago

          Exactly this. Instead of learning about the complexity and footguns of working directly on the DOM, people get to learn about the complexity and footguns of manipulating the virtual DOM.

          React isn’t bad, but it was designed in a very opinionated way to build certain kinds of apps. Excessive abuse of React hooks shows a common desire path to build things that don’t require that framework. Most people basically just want signal based reactivity but don’t know that it exists.

      • jtrek@startrek.website
        link
        fedilink
        arrow-up
        0
        ·
        11 days ago

        As a tutorial grade react developer (please return me to the backend where I am mediocre instead of bad), having more senior developers take the time to explain why my code was bad was really helpful.

        Also I think I just kind of hate JavaScript. It always feels like everything is more complicated and booby trapped than it should be.

    • gastroglizzy@piefed.social
      link
      fedilink
      English
      arrow-up
      0
      ·
      11 days ago

      I don’t like working with them any more than you do, but they’re necessary to enforce read/write-level security. Without them, there’d be no differentiation between reading a variable and writing variable from an external class, which kinda defeats the point.

      From a development standpoint, they’re an extra hurdle to clear. From a security standpoint, they’re a necessary evil.

      • Ephera@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        11 days ago

        Moreso correctness, not security. In the end, your user is shooting themselves in their foot, if they mutate a variable that they shouldn’t, and by making the variable private and only offering a getter, we document that.

        Having said that, there’s also big differences between languages and paradigms, though.
        In object-oriented / garbage-collected languages, you often pass around references to an object into so many places that you need to code defensively versus your own codebase. That’s why getters/setters were taught religiously during the height of OOP.

        In other paradigms, you often just have one place that uses an object and then you can …simply not shoot yourself in the foot there. When you control both the definition and the access, you don’t need to protect yourself from yourself. In particular, you would probably think twice before mutating an object anyways.

        • klankin@piefed.ca
          link
          fedilink
          English
          arrow-up
          0
          ·
          11 days ago

          Damn, I was gonna disagree but you bring up some good points.

          I really need to get into functional programming.

          • Ephera@lemmy.ml
            link
            fedilink
            arrow-up
            0
            ·
            10 days ago

            Functional programming is definitely worth a look in this regard as well, but what really drove this home for me is Rust.

            Its ownership+borrowing concept is exactly that, it enforces that you’ve got one place where an object is managed and in particular mutating can only be done in at most one place.
            Obviously, there’s also ways to get out of that, in case you do want some memory managed centrally, but it just isn’t the default.

    • UnfortunateShort@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      11 days ago

      That’s why people invented properties / auto generated getter/setter - in at least 95% of cases they are just busywork.

  • Endmaker@ani.social
    link
    fedilink
    English
    arrow-up
    0
    ·
    11 days ago

    useState hook is an actual plague on the entire React ecosystem

    Personally, I find useEffect to be the real evil.

  • abc@suppo.fi
    link
    fedilink
    arrow-up
    0
    ·
    11 days ago

    PHP sucks and every attempt at defending it is pathetic.

    I get warm and fuzzy feelings that people here are not even talking about it. Perhaps I should follow that trend.

  • Hundun@beehaw.org
    link
    fedilink
    arrow-up
    0
    ·
    11 days ago

    If you are getting paid for engineering software, your labour should be licenced in an appropriate jurisdiction, and you should be liable to losing said licence if you do shit job.

  • kionay@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    11 days ago

    No single letter variable names. Yes I also mean the i in for loops you see in tutorials. Write out “index” or give it a more descriptive name. Doing the typing isn’t the hard part of programming, nor the most time consuming, so making it take a teeny tiny bit longer by having longer variable names is more than worth the value of variables the effortlessly describe themselves.

    line length is not that big of a problem anymore, we’re not on CRTs, people are regularly developing with 4k monitors, we don’t need to limit to 40 character lines but even still if you can’t possibly think of a way to break up that long of a line and the only thing you can think of to make it shorter is using over-acronymized variable names then you’ve already lost the plot somewhere

    • marcos@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      11 days ago

      I do really disagree here. Name lengths should be proportional to the size of their scope.

      If your function has 1 line, your local variables should almost all have 1 letter.

    • onlinepersona@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      11 days ago

      I agree. Short, nonsensical, meaningless, artificial variable names make me think the person writing the code is a dinosaur from when they still had punch cards. Get with the times.

    • Equinox1289@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      10 days ago

      I’ll only agree for advanced for loops and not the basic C style ones. Also if you are iterating over coords like XYZ or UV you can use those variables as single letters too.

    • Quetzalcutlass@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      11 days ago

      I disagree when it comes to standardized single-letter variable names. They’re invaluable when writing dense code for games or other math-heavy applications and you learn to recognize them very quickly.

      So i for index in loops (and j, k for nested loops, but you’re almost always doing something wrong if you need them); x, y, z for position and h, w for size; r, g, b, a for color data, etc - you’ll immediately know what the variable is for at a glance even though it’s a single character.

      Another benefit is that having related variables be the same character width keeps code visually aligned, which helps with readability.

      • kionay@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        11 days ago

        I can concede that in games programming (which I’m not a game dev so I often forget about) x, y, and z coordinates are a valid exception.

        I would disagree about w and h for width and height, typing them out feels like i for index

        I worry about the phrase, “you’ll immediately know what the variable is for at a glance even though it’s a single character”

        how often have you heard developers say that something is simple and it’s just because they wrote it? maybe it is obvious, but if it were more verbose it would be just as obvious but without any possibility of misunderstanding

        and even if it’s obvious now there’s no guarantee a future developer doesn’t pull that variable out and mutate it or do something else with it, and maybe they should change it at that point but the effort to have it verbosely named from the start is miniscule

  • Fontasia@feddit.nl
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    10 days ago

    A lot of what people hate about Windows 11 is 10 years too early, especially when it comes to use of web components as interface

    The Internet was always going to end up like this, attempts at “small, tight-knit, communities” will only last for a few years at most

    Google has done more for web standards than the open source community ever could

    The next mobile OS should abandon apps

    Even if you did truely own your games, you would still be unhappy

    You don’t like personalised advertising not because it feels invasive, but because you’re scared of being predictable and\or manipulable.

  • mlg@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    10 days ago

    The entire modern web tech stack should be thrown in a dumpster, ignited with gasoline, and blown up with a nuke for good measure.