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.
  • V [email protected]

    A) Rust doesn't have a formal specification other than "whatever the fuck our team hallucinated in this compiler version"

    B) Doesn't matter the definition if it fucks your day because you're not careful.

    Sure sure Heil Rust but be mindful of the fuck you're doing before you get bit ¯\_ (ツ) _/¯

    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]
    #79

    Rust doesn’t have a formal specification other than “whatever the fuck our team hallucinated in this compiler version”

    That's simply not true. The Reference, while not an ISO-style formal spec, does actually specify most of the intended language behavior, and incrementally approaches completion over time. But even if you insist on an ISO-style formal spec, there's Ferrocene: https://ferrous-systems.com/blog/the-ferrocene-language-specification-is-here/

    it fucks your day because you’re not careful

    The cve-rs vulnerability is actually not really something you'd ever write by accident. Also note that the bug report has multiple versions because, even though a "full" solution is pending some deeper compiler changes, the first two three versions of the exploit are now caught by the compiler. So, like I said, the compiler bugs do get fixed over time.

    1 Reply Last reply
    2
    • 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.

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

      0 in our case, but we are pretty strict. Same at the first place I worked too. Big tech companies.

      1 Reply Last reply
      11
      • zacryon@feddit.orgZ [email protected]

        I mostly see warnings when compiling source code of other projects. If you get a warning as a dev, it's your responsibility to deal with it. But also your risk, if you don't. I made it a habit to fix every warning in my own projects. For prototyping I might ignore them temporarily. Some types of warnings are unavoidable sometimes.

        If you want to make yourself not ignore warnings, you can compile with -Werror if using GCC/G++ to make the compiler a pedantic asshole that doesn't compile until you fix every fucking warning. Not advisable for drafting code, but definitely if you want to ship it.

        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
        #81

        Except when you have to cast size_t on int and vice versa (for "small" numbers). I hate that warning.

        1 Reply Last reply
        0
        • T [email protected]

          Structs with union members that allow the same place in memory to be accessed either word-wise, byte-wise, or even bit-wise are a god-sent for everyone who needs to access IO-spaces, and I'm happy my C-compiler lets me do it.

          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
          #82

          #pragma push

          T 1 Reply Last reply
          1
          • zacryon@feddit.orgZ [email protected]

            That what comments and documentation are for.

            merc@sh.itjust.worksM This user is from outside of this forum
            merc@sh.itjust.worksM This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #83

            A yes, comments.

            int flubTheWozat(void *) {
              for (int i=0; i<4; i++) {
                lfens += thzn[i] % ugy;  // take mod of thnz[i] with ugy and add to lefens.
              }
              return (lfens % thzn[0]) == 4; // return if it's 4ish
            }
            
            zacryon@feddit.orgZ 1 Reply Last reply
            4
            • D [email protected]

              Ideally? Zero. I'm sure some teams require "warnings as errors" as a compiler setting for all work to pass muster.

              In reality, there's going to be odd corner-cases where some non-type-safe stuff is needed, which will make your compiler unhappy. I've seen this a bunch in 3rd party library headers, sadly. So it ultimately doesn't matter how good my code is.

              There's also a shedload of legacy things going on a lot of the time, like having to just let all warnings through because of the handful of places that will never be warning free. IMO its a way better practice to turn a warning off for a specific line.. Sad thing is, it's newer than C++ itself and is implementation dependent, so it probably doesn't get used as much.

              merc@sh.itjust.worksM This user is from outside of this forum
              merc@sh.itjust.worksM This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #84

              I've seen this a bunch in 3rd party library headers, sadly. So it ultimately doesn't matter how good my code is.

              Yeah, I've seen that too. The problem is that once the library starts spitting out warnings it's hard to spot your own warnings.

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

                I've seen this a bunch in 3rd party library headers, sadly. So it ultimately doesn't matter how good my code is.

                Yeah, I've seen that too. The problem is that once the library starts spitting out warnings it's hard to spot your own warnings.

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

                Yuuup. Makes me wonder if there's a viable "diaper pattern" for this kind of thing. I'm sure someone has solved that, just not with the usual old-school packaging tools (e.g. automake).

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

                  So, did you get it down to 0 warnings and manage to keep it there? Or did it eventually start creeping up again?

                  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
                  #86

                  I'm not the person you're asking but surely they just told the compiler to treat warnings as errors after that. No warnings can creep in then!

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

                    A yes, comments.

                    int flubTheWozat(void *) {
                      for (int i=0; i<4; i++) {
                        lfens += thzn[i] % ugy;  // take mod of thnz[i] with ugy and add to lefens.
                      }
                      return (lfens % thzn[0]) == 4; // return if it's 4ish
                    }
                    
                    zacryon@feddit.orgZ This user is from outside of this forum
                    zacryon@feddit.orgZ This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #87

                    Haha, meaningful, informative comments that make it easier to understand the code of course. 😉

                    1 Reply Last reply
                    2
                    • 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.

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

                      I put -Werror at the end of my makefile cflags so it actually treats warnings as errors now.

                      1 Reply Last reply
                      16
                      • spacecowboy@lemmy.caS [email protected]

                        Even with qualitative measurements they can do stupid things.

                        For work I have to write code in C# and Microsoft found that null reference exceptions were a common issue. They actually calculated how much these issues cost the industry (some big number) and put a lot of effort into changing the language so there's a lot of warnings when something is null.

                        But the end result is people just set things to an empty value instead of leaving it as null to avoid the warnings. And sure great, you don't have null reference exceptions because a value that defaulted to null didn't get set. But now you have issues where a value is an empty string when it should have been set.

                        The exception message would tell you exactly where in the code there's a mistake, and you'll immediately know there's a problem and it's more likely to be discovered by unit tests or QA. Something that's an value that's supposed to be set may not be noticed for a while and is difficult to track down.

                        So their research indicated a costly issue (which is ultimately a dev making a mistake) and they fixed it by creating an even more costly issue.

                        There's always going to be things where it's the responsibility of the developer to deal with, and there's no fix for it at the language level. Trying to fix it with language changes can just make things worse.

                        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
                        #89

                        For this example, I feel that it is actually fairly ergonomic in languages that have an Option type (like Rust), which can either be Some value or no value (None), and don't normally have null as a concept. It normalizes explicitly dealing with the None instead of having null or hidden empty strings and such.

                        spacecowboy@lemmy.caS 1 Reply Last reply
                        4
                        • P [email protected]

                          I don't know which is worse. Using C++ like lazy C, or using C++ like it was designed to be used.

                          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
                          #90

                          An acquaintance of mine once wrote a finite element method solver entirely in C++ templates.

                          1 Reply Last reply
                          3
                          • zacryon@feddit.orgZ [email protected]

                            I suppose it's a matter of experience and practise. The more you wotk with it the better you get. As usual with all things one can learn.

                            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
                            #91

                            The question becomes, then, if I spend 5 years learning and mastering C++ versus rust, which one is going to help me produce a better product in the end?

                            1 Reply Last reply
                            2
                            • her0@beehaw.orgH [email protected]

                              For this example, I feel that it is actually fairly ergonomic in languages that have an Option type (like Rust), which can either be Some value or no value (None), and don't normally have null as a concept. It normalizes explicitly dealing with the None instead of having null or hidden empty strings and such.

                              spacecowboy@lemmy.caS This user is from outside of this forum
                              spacecowboy@lemmy.caS This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #92

                              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 1 Reply Last reply
                              1
                              • V [email protected]

                                Yeah and those are the ones currently identified (btw that issue isn't completely fixed) because rust never was nor advertised itself as sound. Meaning, you gotta be careful when writing Rust code too. Not as much as C++, but it's not a magical shield against memory problems like people have been shilling it as.

                                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
                                #93

                                I guess what you mean is that Rust doesn't advertise the compiler as being bug-free?

                                The massive difference here is that C++ has no soundness guarantees even when the compiler is working as intended, whereas Rust actually does in fact give soundness guarantees in the absence of compiler bugs.

                                1 Reply Last reply
                                1
                                • 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
                                          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