kuuhana
  • Communities
  • Multi-communities
  • Support Lemmy
  • Search
  • Login
  • Sign Up
Programmer Humor@programming.devbySolrac@quokk.au
20 days

Is my fear of C/++ Justified?

English
Is my fear of C/++ justified?, -cursed `e` coding-, The Engima of Segmentation Fault

36
    You must log in or register to comment.

    • grue@lemmy.world
      20 days

      Less fucked-up than Javascript.

        • NateNate60@lemmy.world
          20 days

          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.

            • GeirGrusom@lemmy.world
              20 days

              Where’s the >== operator? Because they also have the exact same problem.

              • dan@upvote.au
                20 days

                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.

                  • BradleyUffner@lemmy.worldEnglish
                    20 days

                    So you’re saying the jank has become structural?

                    • Venator@lemmy.nz
                      20 days

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

                        • Ignotum@lemmy.world
                          20 days

                          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
                            20 days

                            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
                                20 days

                                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.

                          • ParlimentOfDoom@piefed.zipEnglish
                            20 days

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

                              • Victor@lemmy.world
                                20 days

                                The problem is that you can’t break compatibility.

                                Only in some exceptional cases. 🙃

                                  • ParlimentOfDoom@piefed.zipEnglish
                                    20 days

                                    Not with that attitude

                                      • Victor@lemmy.world
                                        20 days

                                        Personally, I’d love to break compatibility for better features and consistency. We should be able to declare the version at the top of the file or something. Nothing at the top = legacy crap. 🤷‍♂️ I dunno.

                                  • 9point6@lemmy.world
                                    20 days

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

                                    • Denys Nykula@piefed.socialEnglish
                                      20 days

                                      == 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.

                                        • NateNate60@lemmy.world
                                          20 days

                                          “I have no problem living in a house of cards as I make sure to never bump against the walls.”

                                            • grue@lemmy.world
                                              20 days

                                              I wonder how many millions of programmer man-hours have been wasted working around JavaScript’s design mistakes that could’ve been saved simply by putting Scheme or Python (which were actually being considered) in the browser instead.

                                              • Denys Nykula@piefed.socialEnglish
                                                19 days

                                                Opposite, living in a house of cards is when you blindly trust data that comes from user. Regardless of the language. eqeqeq isn’t in the recommended linting presets because if you end up needing it, you’re probably already in big trouble because of insecure software design.

                                                  • NateNate60@lemmy.world
                                                    19 days

                                                    Nobody is advocating for blindly trusting data from the user.

                                                      • Denys Nykula@piefed.socialEnglish
                                                        19 days

                                                        Then where do you see the house of cards? What’s the practical difference between == and ===, when your app is type-checked and the inputs are safely parsed?

                                                          • NateNate60@lemmy.world
                                                            18 days

                                                            Because you don’t know whether you’ve actually type-checked everything and that your inputs are safely parsed. Part of defensive programming is to adopt multiple defences to prevent bad data from getting through, including avoiding ==.

                                                  • diaphragmwp@discuss.tchncs.de
                                                    20 days

                                                    When I had to use JS I wrote JS 1.2 because why not. Fun how I had strings of numbers instead of actual numbers in some for loops, yet it all sort of functioned until something didn’t. I then decided to add Number() to random values just in case.

                                                  • Solrac@quokk.auEnglish
                                                    20 days

                                                    I did not wish to believe… but then I saw.

                                                    image

                                                  • trxxruraxvr@lemmy.world
                                                    20 days

                                                    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.

                                                      • kettuli@lemmy.blahaj.zone
                                                        20 days

                                                        So yes

                                                          • trxxruraxvr@lemmy.world
                                                            20 days

                                                            No

                                                              • MangoCats@feddit.itBanned
                                                                13 days
                                                        • Girl Named ZERO@piefed.zeromedia.vipEnglish
                                                          20 days

                                                          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
                                                              20 days

                                                              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++.

                                                            • axh@lemmy.world
                                                              20 days

                                                              No, the C++ should fear you!

                                                              • mkwt@lemmy.world
                                                                20 days

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

                                                                  • glibg10b@lemmy.zip
                                                                    20 days

                                                                    Even C++11 is pretty old. I would recommend at least C++17

                                                                      • boonhet@sopuli.xyz
                                                                        20 days

                                                                        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
                                                                            20 days

                                                                            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*
                                                                              • Victor@lemmy.world
                                                                                20 days

                                                                                Class Template Argument Deduction (CTAD)

                                                                                For anyone wondering, like I did.

                                                                        • edinbruh@feddit.it
                                                                          20 days

                                                                          Of C? No

                                                                          Of C++? Yes

                                                                          • mnemonicmonkeys@sh.itjust.worksEnglish
                                                                            20 days

                                                                            Your example is just brainfuck but somehow even worse

                                                                            Programmer Humor@programming.dev

                                                                            programmer_humor@programming.dev

                                                                            Subscribe from remote instance

                                                                            Create post

                                                                            Report community

                                                                            Modlog
                                                                            You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

                                                                            Welcome to Programmer Humor!

                                                                            This is a place where you can post jokes, memes, humor, etc. related to programming!

                                                                            For sharing awful code theres also Programming Horror.

                                                                            Rules

                                                                            • Keep content in english
                                                                            • No advertisements
                                                                            • Posts must be related to programming or programmer topics
                                                                              • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
                                                                            Visibility: Public

                                                                            This community is visible to everyone.

                                                                            • 1.01K users / Day
                                                                            • 4.05K users / Week
                                                                            • 8.95K users / Month
                                                                            • 11.6K users / 6 months
                                                                            • 2.61K posts
                                                                            • 97.4K comments
                                                                            • 2 local subscribers
                                                                            • 34.2K subscribers
                                                                            • UI: 1.0.0-beta.0
                                                                            • BE: 1.0.0-alpha.20
                                                                            • Modlog
                                                                            • Instances
                                                                            • Docs
                                                                            • Code
                                                                            • join-lemmy.org