Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • 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
Code Project
  1. Home
  2. The Lounge
  3. *cries in C++*

*cries in C++*

Scheduled Pinned Locked Moved The Lounge
c++cssquestion
57 Posts 26 Posters 1 Views 1 Watching
  • 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.
  • C charlieg

    but to be honest, that can be done in any language. I'm reading through "learning python" and just hit the description of formatting strings. I don't know what that guy was smoking when they came up with their approach, but I want some.

    Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

    J Offline
    J Offline
    jschell
    wrote on last edited by
    #46

    charlieg wrote:

    but to be honest, that can be done in any language.

    Err..no it can't. I had a C program that had assembly code in a text literal. I would cast it to a function and the call it. Pseudo code for that was something like the following

    char* code = "\xCC\xFF...";
    typedef int* myfunct(int i)
    int result = (myfunct)(code)(45);

    If I hadn't put a lot of comments around that, including the exact assembly, then a maintenance programmer, even an experienced one, would have spent a lot of time figuring that out.

    C 1 Reply Last reply
    0
    • J jschell

      Memtha wrote:

      only because I am forced to run it through a painfully awful "security" code scanner.

      ...and because you are working for a company that doesn't know what they are doing. Or perhaps an individual up the authority chain that doesn't.

      M Offline
      M Offline
      Memtha
      wrote on last edited by
      #47

      > working for a company that doesn't know what they are doing Close. The company is very good, but the client is... government. Need I say more? Some battles just aren't worth the effort. We had to teach the "security lead" how to use git to get the zip and upload it to the scanning service they have forced on us. It's not even the government personnel that chose the scanner, it's a rival contractor that loves to tout the sheer number of "vulnerabilities" that "they" "addressed" by forcing us to add try/catch/throw on every single method.

      J 1 Reply Last reply
      0
      • J jschell

        mischasan wrote:

        because it is superfast for solving complex problems, and surprisingly straightforward.

        Right up until someone asks for the studies that demonstrates those statements using something besides benchmarks (that are often coded well in one language and then so poorly done in other languages that one suspects that they were written that way deliberately.) But to be fair I am certain I have seen that claim about every language and based, when based on anything at all, on the same sort of lopsided benchmarks.

        M Offline
        M Offline
        mischasan
        wrote on last edited by
        #48

        "Superfast for solving problems" -- superfast for the solver to formulate. Sorry if that it sounds like, "superfast execution time". Building systems in APL for Rank Xerox, I sometimes completed and ran a solution in the course of a short conversation; so we could get on with the conclusion from its result. Occasionally (rarely) was its speed of execution an issue.

        1 Reply Last reply
        0
        • H honey the codewitch

          I love this language except when it's used cryptically. You can produce more incomprehensible code with C++ than I think you can in any other major language. I'm poring over C code right now - C really isn't that much better, but fortunately you can do less with it. The code is evil. It's absolutely terrible to read, almost as if they were *trying* to hide intent. Porting it to C++ is my fresh hell. I love this language, but would it kill people to write readable code, or at least comment it with something *helpful*? Anyway, I guess what I'm saying is C++ is both my favorite and least favorite language. It's weird like that.

          Real programmers use butterflies

          B Offline
          B Offline
          bmarstella
          wrote on last edited by
          #49

          I feel like if you can't program it in C/C++ then you don't really understand it. If the C/C++ answer is obvious then the others are trivial.

          H 1 Reply Last reply
          0
          • B bmarstella

            I feel like if you can't program it in C/C++ then you don't really understand it. If the C/C++ answer is obvious then the others are trivial.

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #50

            Yeah, but that's not what I was talking about. More I'm talking about things like this.

            if(pin_d1>31) {
            b |= (((pins_h>>((pin_d1-32)&31))&1)<<1);
            } else if(pin_d1>-1) {
            b |= (((pins_l>>(pin_d1))&1)<<1);
            }
            if(pin_d2>31) {
            b |= (((pins_h>>((pin_d2-32)&31))&1)<<2);
            } else if(pin_d2>-1) {
            b |= (((pins_l>>(pin_d2))&1)<<2);
            }
            if(pin_d3>31) {
            b |= (((pins_h>>((pin_d3-32)&31))&1)<<3);
            } else if(pin_d3>-1) {
            b |= (((pins_l>>(pin_d3))&1)<<3);
            }
            if(pin_d4>31) {
            b |= (((pins_h>>((pin_d4-32)&31))&1)<<4);
            } else if(pin_d4>-1) {
            b |= (((pins_l>>((pin_d4)&31))&1)<<4);
            }
            if(pin_d5>31) {
            b |= (((pins_h>>((pin_d5-32)&31))&1)<<5);
            } else if(pin_d5>-1) {
            b |= (((pins_l>>(pin_d5))&1)<<5);
            }
            if(pin_d6>31) {
            b |= (((pins_h>>((pin_d6-32)&31))&1)<<6);
            } else if(pin_d6>-1) {
            b |= (((pins_l>>(pin_d6))&1)<<6);
            }
            if(pin_d7>31) {
            b |= (((pins_h>>((pin_d7-32)&31))&1)<<7);
            } else if(pin_d7>-1) {
            b |= (((pins_l>>(pin_d7))&1)<<7);
            }

            How many of these if statements will be compiled into the binary? You can't know that just by looking at it, assuming this is C++. In this case, none will, because they all evaluate constexpr values. But those can be buried under templates, for example, and then the answer non-obvious.

            Real programmers use butterflies

            1 Reply Last reply
            0
            • J jschell

              charlieg wrote:

              but to be honest, that can be done in any language.

              Err..no it can't. I had a C program that had assembly code in a text literal. I would cast it to a function and the call it. Pseudo code for that was something like the following

              char* code = "\xCC\xFF...";
              typedef int* myfunct(int i)
              int result = (myfunct)(code)(45);

              If I hadn't put a lot of comments around that, including the exact assembly, then a maintenance programmer, even an experienced one, would have spent a lot of time figuring that out.

              C Offline
              C Offline
              charlieg
              wrote on last edited by
              #51

              I'm sorry, but what is your point? You have special code, you knew it was special code, so you made it real obvious what you were doing. :confused:

              Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

              1 Reply Last reply
              0
              • P Peter_in_2780

                If you've got a system that supports dc, try this:

                dc -e '2p3p[dl!d2+s!%0=@l!l^!<#]s#[s/0ds^]s@[p]s&[ddvs^3s!l#x0<&2+l.x]ds.x'

                Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                R Offline
                R Offline
                Rage
                wrote on last edited by
                #52

                That's a prime post !

                Do not escape reality : improve reality !

                1 Reply Last reply
                0
                • J jschell

                  Gary R. Wheeler wrote:

                  I am now responsible for a piece of code that's been part of our business for over thirty years...Function prototypes weren't used. Header files didn't define the functions or data in the corresponding .C source file. There were...

                  So at least 1992. So yes that was par for the course for C code then. Things like prototypes sort of came about probably associated with C++ (perhaps not entirely but for the same reason that C++ added them.) Someone used to the the older style would not have used them. Globals were something that any C app would be using. Single char variable names were common.

                  Gary R. Wheeler wrote:

                  a group of #define's he'd added before #include <windows.h> which changed the definition of a number of values in the Windows headers which his comment (one of the few) claimed "Microsoft got wrong".

                  Could not speak specifically to that but as I recall there were a lot of problems with the early Microsoft C++. I know for a fact that for years after the ANSI C++ spec was released the Microsoft scored very poorly on implementing it. That was back when people could actually post comparisons of software without getting sued.

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #53

                  In some circumstances what you're saying could be true. This code was adapted to Windows in the early 2000's, so function prototyping was the norm. No excuse there.

                  jschell wrote:

                  Could not speak specifically to that but as I recall there were a lot of problems with the early Microsoft C++. I know for a fact that for years after the ANSI C++ spec was released the Microsoft scored very poorly on implementing it. That was back when people could actually post comparisons of software without getting sued.

                  This is a case where BK was redefining constants for arguments to and return values from Windows API functions, thereby guaranteeing they would not work as documented. BK was an asshole.

                  Software Zen: delete this;

                  1 Reply Last reply
                  0
                  • L Lost User

                    How long do I need to wait for it to finish? :confused:

                    P Offline
                    P Offline
                    Peter_in_2780
                    wrote on last edited by
                    #54

                    Well, after about 24 hours on an ancient and very slow laptop, it hit this milestone:

                    99999847
                    99999931
                    99999941
                    99999959
                    99999971
                    99999989
                    100000007
                    100000037
                    100000039
                    100000049
                    100000073
                    100000081
                    100000123
                    100000127
                    100000193
                    100000213
                    100000217
                    100000223

                    I took pity on the poor beast shortly afterwards. ;P :laugh:

                    Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                    1 Reply Last reply
                    0
                    • H honey the codewitch

                      I love this language except when it's used cryptically. You can produce more incomprehensible code with C++ than I think you can in any other major language. I'm poring over C code right now - C really isn't that much better, but fortunately you can do less with it. The code is evil. It's absolutely terrible to read, almost as if they were *trying* to hide intent. Porting it to C++ is my fresh hell. I love this language, but would it kill people to write readable code, or at least comment it with something *helpful*? Anyway, I guess what I'm saying is C++ is both my favorite and least favorite language. It's weird like that.

                      Real programmers use butterflies

                      S Offline
                      S Offline
                      Stefan_Lang
                      wrote on last edited by
                      #55

                      From 1985 to 2010, any decent run-of-the-mill-general-purpose coding standard worked pretty well for C and C++. But since C++11, every batch of new features also added more tools that were easy to misuse against the spirit if not the letter of said guidelines. Nowadays, the only way to maintain good code with modern C++ is using modern standards following Clean-Code / SOLID principles. I've found the most important thing is keeping classes and functions small: just one purpose is the key. The best way to find out if your function or class is small enough is thinking about a name that describes it well: if a good description requires an 'or' or 'and' or 'then', then your class or function tries to fulfil more than one purpose and should be split!

                      GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                      H 1 Reply Last reply
                      0
                      • S Stefan_Lang

                        From 1985 to 2010, any decent run-of-the-mill-general-purpose coding standard worked pretty well for C and C++. But since C++11, every batch of new features also added more tools that were easy to misuse against the spirit if not the letter of said guidelines. Nowadays, the only way to maintain good code with modern C++ is using modern standards following Clean-Code / SOLID principles. I've found the most important thing is keeping classes and functions small: just one purpose is the key. The best way to find out if your function or class is small enough is thinking about a name that describes it well: if a good description requires an 'or' or 'and' or 'then', then your class or function tries to fulfil more than one purpose and should be split!

                        GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                        H Offline
                        H Offline
                        honey the codewitch
                        wrote on last edited by
                        #56

                        "draw::text<>" has one purpose in my draw class in GFX, and has multiple overloads, the implementation of which spans several functions and one entire private header+cpp file. Because it renders truetype text. Even after factoring the function is half a screen on my display. I agree with you in principle, but in practice I can't code that way. I have some wiring issues in my head that affect my short term memory, and if I over-factor I forgot how to navigate all the layers and calls. In some respects my condition can be debilitating. This is not one of those areas, but it does mean I have to adjust my approach. Cognitive load on the other hand, I can take for days. So give me a long function, as long as its purpose is singular. But I understand that this is less than ideal, because I code professionally, and have coded on teams, from PM to lead to QA. That's one reason I'm not a stickler for industry wide standards. I think a good coder can pick up a standard someone else uses, as long as that someone was consistent, and it's not awful - like there's sense to it. I mean, I have to consider myself and that I'm probably not the only one coding with a handicap of sorts. As far as C++11 and beyond, I agree with you. But also I'm going to be difficult here - the introduction of variadic template arguments and things like that which facilitate metaprogramming and the metaprogramming itself creates its own kind of maintenance monster. When you get used to reading "metaprogrammed" C++ it gets easier, but it's still a beast. I've had to reimplement a lot of what the STL hides at points because I target frameworks where the STL is partial if at all, and I don't know which parts are necessarily available, so I understand the sausage making therein. On the other hand, you can do so much with it. Opening a dialogue with the compiler using your code, so that it can shape the generated code is just ... no other coding is like that. It sets C++ apart, and allows you to do some truly amazing things. In GFX I allow you to define pixels with arbitrary binary layouts and color formats. It then lets you manipulate all the individual color channels and if everything is const, it all resolves const. That means if you use a predefined color like "hot_pink" (an X11 standard color) it will resolve to a single scalar const value at compile time. You can even get the compiler to color blend and convert color formats (from like Y'UV to RGBA or BGR) All that with C++14 and a somewhat byzantine header file (linked if you'r

                        1 Reply Last reply
                        0
                        • M Memtha

                          > working for a company that doesn't know what they are doing Close. The company is very good, but the client is... government. Need I say more? Some battles just aren't worth the effort. We had to teach the "security lead" how to use git to get the zip and upload it to the scanning service they have forced on us. It's not even the government personnel that chose the scanner, it's a rival contractor that loves to tout the sheer number of "vulnerabilities" that "they" "addressed" by forcing us to add try/catch/throw on every single method.

                          J Offline
                          J Offline
                          jschell
                          wrote on last edited by
                          #57

                          Memtha wrote:

                          but the client is... government. Need I say more?

                          lol - nope.

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


                          • Login

                          • Don't have an account? Register

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