Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. average c++ dev

average c++ dev

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
116 Posts 63 Posters 10 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • spacecowboy@lemmy.caS [email protected]

    I just prefer an exception be thrown if I forget to set something so it's likely to happen as soon as I test it and will be easy to find where I missed something.

    I don't think a language is going to prevent someone from making a human error when writing code, but it should make it easy to diagnose and fix it when it happens. If you call it null, "", empty, None, undefined or anything else, it doesn't change the fact that sometimes the person writing the code just forgot something.

    Abstracting away from the problem just makes it more fuzzy on where I just forgot a line of code somewhere. Throwing an exception means I know immediately that I missed something, and also the part of the code where I made the mistake. Trying to eliminate the exception doesn't actually solve the problem, it just hides the problem and makes it more difficult to track down when someone eventually notices something wasn't populated.

    Sometimes you want the program to fail, and fail fast (while testing) and in a very obvious way. Trying to make the language more "reliable" instead of having the reliability of the software be the responsibility of the developer can mean the software always "works", but it doesn't actually do what it's supposed to do.

    Is the software really working if it never throws an exception but doesn't actually do what it's supposed to do?

    her0@beehaw.orgH This user is from outside of this forum
    her0@beehaw.orgH This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #94

    It is fair to have a preference for exceptions. It sounds like there may be a misunderstanding on how Option works.

    Have you used languages that didn't have null and had Option instead? If we look at Rust, you can't forget not to check it: it is impossible to get the Some of an Option without dealing with the None. You can't forget this. You can mess up in a lot of other ways, but you explicitly have to decide how to handle that potential None case.

    If you want it to fail fast and obvious, there are ways to do this. For example you, you can use the unwrap() method to get the contained Some value or panic if it is None, expect() to do the same but with a custom panic message, the ? operator to get the contained Some value or return the function with None, etc. Tangentially, these also work for Result, which can be Ok or Err.

    It is pretty common to use these methods in places where you always want to fail somewhere that you don't expect should have a None or where you don't want your code to deal with the consequences of something unexpected. You have decided this and live with the consequences, instead of it implicitly happening/you forgetting to deal with it.

    1 Reply Last reply
    0
    • B [email protected]

      But it will let you do it if you really want to.

      Now, I've seen this a couple of times in this post. The idea that the compiler will let you do anything is so bizarre to me. It's not a matter of being allowed by the software to do anything. The software will do what you goddamn tell it to do, or it gets replaced.

      WE'RE the humans, we're not asking some silicon diodes for permission. What the actual fuck?!? We created the fucking thing to do our bidding, and now we're all oh pwueez mr computer sir, may I have another ADC EAX, R13? FUCK THAT! Either the computer performs like the tool it is, or it goes the way of broken hammers and lawnmowers!

      mormegil@programming.devM This user is from outside of this forum
      mormegil@programming.devM This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #95

      I understand the idea. But many people have hugely mistaken beliefs about what the C[++] languages are and how they work. When you write ADC EAX, R13 in assembly, that's it. But C is not a "portable assembler"! It has its own complicated logic. You might think that by writing ++i, you are writing just some INC [i] ot whatnot. You are not. To make a silly example, writing int i=INT_MAX; ++i; you are not telling the compiler to produce INT_MIN. You are just telling it complete nonsense. And it would be better if the compiler "prevented" you from doing it, forcing you to explain yourself better.

      B 1 Reply Last reply
      4
      • V [email protected]

        #pragma push

        T This user is from outside of this forum
        T This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #96

        Context?

        V 1 Reply Last reply
        0
        • mormegil@programming.devM [email protected]

          I understand the idea. But many people have hugely mistaken beliefs about what the C[++] languages are and how they work. When you write ADC EAX, R13 in assembly, that's it. But C is not a "portable assembler"! It has its own complicated logic. You might think that by writing ++i, you are writing just some INC [i] ot whatnot. You are not. To make a silly example, writing int i=INT_MAX; ++i; you are not telling the compiler to produce INT_MIN. You are just telling it complete nonsense. And it would be better if the compiler "prevented" you from doing it, forcing you to explain yourself better.

          B This user is from outside of this forum
          B This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #97

          I get what you're saying. I guess what I'm yelling at the clouds about is the common discourse more than anything else.

          If a screw has a slotted head, and your screwdriver is a torx, few people would say that the screwdriver won't allow them to do something.

          Computers are just tools, and we're the ones who created them. We shouldn't be submissive, we should acknowledge that we have taken the wrong approach at solving something and do it a different way. Just like I would bitch about never having the correct screwdriver handy, and then go look for the right one.

          1 Reply Last reply
          1
          • T [email protected]

            Context?

            V This user is from outside of this forum
            V This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #98

            You use it to "pack" bitfields, bytes etc together in structs/classes (wo functions), otherwise the computer usually align every variable on a 32bit boundary for speed.

            T 1 Reply Last reply
            0
            • V [email protected]

              You use it to "pack" bitfields, bytes etc together in structs/classes (wo functions), otherwise the computer usually align every variable on a 32bit boundary for speed.

              T This user is from outside of this forum
              T This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #99

              You don't need that pragma to pack bitfields.

              V 1 Reply Last reply
              0
              • T [email protected]

                You don't need that pragma to pack bitfields.

                V This user is from outside of this forum
                V This user is from outside of this forum
                [email protected]
                wrote on last edited by [email protected]
                #100

                With say a 3bit int, then a 2bit int and various char, int etc and so on you did have to use the pragma with gcc & visual around 2012 at least

                T 1 Reply Last reply
                1
                • merc@sh.itjust.worksM [email protected]

                  "C++ compilers also warn you..."

                  Ok, quick question here for people who work in C++ with other people (not personal projects). How many warnings does the code produce when it's compiled?

                  I've written a little bit of C++ decades ago, and since then I've worked alongside devs who worked on C++ projects. I've never seen a codebase that didn't produce hundreds if not thousands of lines of warnings when compiling.

                  C This user is from outside of this forum
                  C This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #101

                  A production code should never have any warning left. This is a simple rule that will save a lot of headaches.

                  P 1 Reply Last reply
                  4
                  • L [email protected]

                    "washing your hands isn't a guarantee that the patient isn't going to get an infection, they could get infected some other way too".

                    Every single doctor should know this yes.

                    It seems people are adding a sentence I didn't say "rust can be unsafe and thus we shouldn't try" on top of the one I did say "programmers should be aware that rust doesn't automatically mean safe".

                    B This user is from outside of this forum
                    B This user is from outside of this forum
                    [email protected]
                    wrote on last edited by [email protected]
                    #102

                    You didn't say "programmers should be aware that rust doesn’t automatically mean safe". You said:

                    People just think that applying arbitrary rules somehow makes software magically more secure...

                    You then went on to mention unsafe, conflating "security" and "safety"; Rust's guarantees are around safety, not security, so it sounds like you really mean "more safe" here. But Rust does make software more safe than C++: it prohibits memory safety issues that are permitted by C++.

                    You then acknowledged:

                    I understand that rust forces things to be more secure

                    ...which seems to be the opposite of your original statement that Rust doesn't make software "more secure". But in the same comment:

                    It’s not not like there’s some guarantee that rust is automatically safe...

                    ...well, no, there IS a guarantee that Rust is "automatically" (memory) safe, and to violate that safety, your program must either explicitly opt out of that "automatic" guarantee (using unsafe) or exploit (intentionally or not) a compiler bug.

                    ...and C++ is automatically unsafe.

                    This is also true! "Safety" is a property of proofs: it means that a specific undesirable thing cannot happen. The C++ compiler doesn't provide safety properties[1]. The opposite of "safety" is "liveness", meaning that some desirable thing does happen, and C++ does arguably provide certain liveness properties, in particular RAII, which guarantees that destructors will be called when leaving a call-stack frame.

                    [1] This is probably over-broad, but I can't think of any safety properties C++ the language does provide. You can enforce your own safety properties in library code, and the standard library provides some; for instance, mutexes have safety guarantees.

                    1 Reply Last reply
                    1
                    • C [email protected]

                      A production code should never have any warning left. This is a simple rule that will save a lot of headaches.

                      P This user is from outside of this forum
                      P This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #103

                      Neither should your development code, except for the part where you're working on.

                      1 Reply Last reply
                      3
                      • danhab99@programming.devD [email protected]

                        I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

                        C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

                        That's why I love C++

                        S This user is from outside of this forum
                        S This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #104

                        Aand what is wrong with that?

                        1 Reply Last reply
                        1
                        • B [email protected]

                          But it will let you do it if you really want to.

                          Now, I've seen this a couple of times in this post. The idea that the compiler will let you do anything is so bizarre to me. It's not a matter of being allowed by the software to do anything. The software will do what you goddamn tell it to do, or it gets replaced.

                          WE'RE the humans, we're not asking some silicon diodes for permission. What the actual fuck?!? We created the fucking thing to do our bidding, and now we're all oh pwueez mr computer sir, may I have another ADC EAX, R13? FUCK THAT! Either the computer performs like the tool it is, or it goes the way of broken hammers and lawnmowers!

                          S This user is from outside of this forum
                          S This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #105

                          Yup, I am with you on this one

                          1 Reply Last reply
                          0
                          • danhab99@programming.devD [email protected]

                            I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

                            C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

                            That's why I love C++

                            A This user is from outside of this forum
                            A This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #106

                            Did you know 100% of C programmers were sex offenders?

                            1 Reply Last reply
                            3
                            • B [email protected]

                              But it will let you do it if you really want to.

                              Now, I've seen this a couple of times in this post. The idea that the compiler will let you do anything is so bizarre to me. It's not a matter of being allowed by the software to do anything. The software will do what you goddamn tell it to do, or it gets replaced.

                              WE'RE the humans, we're not asking some silicon diodes for permission. What the actual fuck?!? We created the fucking thing to do our bidding, and now we're all oh pwueez mr computer sir, may I have another ADC EAX, R13? FUCK THAT! Either the computer performs like the tool it is, or it goes the way of broken hammers and lawnmowers!

                              C This user is from outside of this forum
                              C This user is from outside of this forum
                              [email protected]
                              wrote on last edited by [email protected]
                              #107

                              Yeah, but there's some things computers are genuinely better at than humans, which is why we code in the first place. I totally agree that you shouldn't ever be completely controlled by your machine, but strong nudging saves a lot of trouble.

                              1 Reply Last reply
                              1
                              • merc@sh.itjust.worksM [email protected]

                                "C++ compilers also warn you..."

                                Ok, quick question here for people who work in C++ with other people (not personal projects). How many warnings does the code produce when it's compiled?

                                I've written a little bit of C++ decades ago, and since then I've worked alongside devs who worked on C++ projects. I've never seen a codebase that didn't produce hundreds if not thousands of lines of warnings when compiling.

                                A This user is from outside of this forum
                                A This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #108

                                My team uses the -Werror flag, so our code won't compile if there are any warnings at all.

                                1 Reply Last reply
                                4
                                • A This user is from outside of this forum
                                  A This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #109

                                  Debugging code is always harder that writing it in the first place. If you make it as clever as you can, you won't be clever enough to debug it.

                                  1 Reply Last reply
                                  1
                                  • danhab99@programming.devD [email protected]

                                    I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

                                    C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

                                    That's why I love C++

                                    O This user is from outside of this forum
                                    O This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by [email protected]
                                    #110

                                    The problem is that it's undefined behavior. Quake fast inverse square root only works before the types just happen to look that way. Because the floats just happens to have that bit arrangement. It could look very different on other machines! Nevermind that it's essentially always exactly the same on most architectures. So yeah. Undefined behavior is there to keep your code usable even if our assumptions about types and memory change completely one day.

                                    1 Reply Last reply
                                    1
                                    • danhab99@programming.devD [email protected]

                                      I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

                                      C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

                                      That's why I love C++

                                      lillypip@lemmy.caL This user is from outside of this forum
                                      lillypip@lemmy.caL This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by [email protected]
                                      #111

                                      Why use a strongly typed language at all, then?

                                      Sounds unnecessarily restrictive, right? Just cast whatever as whatever and let future devs sort it out.

                                      $myConstant = ‘15’;
                                      $myOtherConstant = getDateTime();
                                      $buggyShit = $myConstant + $myOtherConstant;

                                      Fuck everyone who comes after me for the next 20 years.

                                      1 Reply Last reply
                                      6
                                      • V [email protected]

                                        With say a 3bit int, then a 2bit int and various char, int etc and so on you did have to use the pragma with gcc & visual around 2012 at least

                                        T This user is from outside of this forum
                                        T This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #112

                                        OK, I use the Keil ARM compiler, and never needed to push anything.

                                        V 1 Reply Last reply
                                        1
                                        • B [email protected]

                                          But it will let you do it if you really want to.

                                          Now, I've seen this a couple of times in this post. The idea that the compiler will let you do anything is so bizarre to me. It's not a matter of being allowed by the software to do anything. The software will do what you goddamn tell it to do, or it gets replaced.

                                          WE'RE the humans, we're not asking some silicon diodes for permission. What the actual fuck?!? We created the fucking thing to do our bidding, and now we're all oh pwueez mr computer sir, may I have another ADC EAX, R13? FUCK THAT! Either the computer performs like the tool it is, or it goes the way of broken hammers and lawnmowers!

                                          P This user is from outside of this forum
                                          P This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #113

                                          New copypasta just dropped

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups