• NateNate60@lemmy.world
      link
      fedilink
      arrow-up
      34
      arrow-down
      3
      ·
      24 hours ago

      This diagram is nonsense. JavaScript programmers know to simply never use == but to use === instead. Half of JavaScript is like this. Oh, there’s a feature, but it behaves in a super weird way so we don’t use it to avoid the weirdness.

      • Denys Nykula@piefed.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        10 hours ago

        == has never, ever caused me a single issue. Parsing all server input with type-safe schemas makes sure that where I expect a string, I get a string; where I expect a number, I get a number. Bad data must result in an error before it reaches logic.

      • ParlimentOfDoom@piefed.zip
        link
        fedilink
        English
        arrow-up
        7
        arrow-down
        1
        ·
        17 hours ago

        As someone trying to learn Javascript, it just makes me mad that at this garbage heap of a language is so widely used.

      • dan@upvote.au
        link
        fedilink
        arrow-up
        10
        ·
        22 hours ago

        The recommended ESLint rules catch most of the bad stuff, and these days this is all you need in your ESLint config to enable them:

        import {defineConfig} from 'eslint/config';
        import js from '@eslint/js' 
        
        export default defineConfig([
          js.configs.recommended,
        ]; 
        

        There’s one use case where == is still commonly used: == null matches both null and undefined. Lint rules that block == usually allows the null case as an exception.

        • Venator@lemmy.nz
          link
          fedilink
          arrow-up
          3
          ·
          22 hours ago

          I wonder how much bandwidth is wasted on the extra =, since it survives minification 😅

          • Ignotum@lemmy.world
            link
            fedilink
            arrow-up
            5
            ·
            21 hours ago

            But if every single comparison used in a file is a triple =, then any compression algo worth its weight in salt will compress that bloat away during transmission

            The real issue is all the precious precious RAM those extra = use on the client device once received and unpacked!

          • 9point6@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            21 hours ago

            Gzip (any properly configured static server will serve compressed assets) probably compresses them down so probably a single extra byte per file

            • dan@upvote.au
              link
              fedilink
              arrow-up
              1
              ·
              edit-2
              11 hours ago

              Gzip is old-school. The majority of modern sites use Brotli now. It’s slower to compress, but that’s not normally an issue for static resources (CSS, JS, etc) because they can be pre-compressed during the build and the web server serves the pre-compressed files instead of dynamically compressing them.

      • 9point6@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        22 hours ago

        IIRC modern linter rulesets generally just outright error if you do anything remotely like this.

  • mkwt@lemmy.world
    link
    fedilink
    arrow-up
    8
    arrow-down
    1
    ·
    17 hours ago

    If anyone is starting to learn C++, make sure to use books or training materials based on C++11 or later.

      • boonhet@sopuli.xyz
        link
        fedilink
        arrow-up
        4
        ·
        16 hours ago

        As someone who last touched any C++ books when C++11 was very new and has only written like 20-30 lines of non-tutorial C++ since then, what are some significant changes to the language that I should be aware of if I wanted to give it a try now?

        • glibg10b@lemmy.zip
          link
          fedilink
          arrow-up
          6
          arrow-down
          1
          ·
          16 hours ago

          A few examples:

          • CTAD: Instead of std::pair<int, int> myPair{ 1, 2 }, you just write std::pair myPair{ 1, 2 }
          • std::optional, std::variant and std::any
          • Guaranteed copy elision in some cases, making it more feasible to apply the rule of 5 everywhere
          • Attributes like [[nodiscard]] (compiler warning if an object or return value is discarded) and [[fallthrough]] (suppress a switch fallthrough warning)
          • Generic lambdas ([](auto it){ /* do something */ })
          • std::string_view, which is much safer as a function parameter than const char*
  • Girl Named ZERO@piefed.zeromedia.vip
    link
    fedilink
    English
    arrow-up
    21
    ·
    edit-2
    22 hours ago

    For those needing help the code is:

    using namespace std;
    int main()
    {
    while (true)
    {
    cout << 'e';
    cerr << 'e';
    }
    return 'e';
    }
    

    Anyway, my opinion: c is the best thing to ever exist, and c++ is evil

    • xxce2AAb@feddit.dk
      link
      fedilink
      arrow-up
      1
      ·
      15 hours ago

      Yeah. I kept reducing my sane “C with classes” subset until I just ended up back writing C99 too, and just about the only difference that made for my use case was better compilation times. If I ever need more than that, I’ll likely reach for Zig or C3 before C++.

  • trxxruraxvr@lemmy.world
    link
    fedilink
    arrow-up
    27
    arrow-down
    1
    ·
    1 day ago

    No. I don’t find it a particularly nice language to work with, but there’s no reason to fear it. Just make sure you know what you’re doing if/when you use it.