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. Fluent in C++

Fluent in C++

Scheduled Pinned Locked Moved The Lounge
c++databaseperformance
28 Posts 10 Posters 2 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.
  • L Lost User

    An empty destructor is almost as scary as an empty catch block :-) I just hope that they will one day add reflection. It has been under consideration more than once, but never made it into the standard.

    The language is JavaScript. that of Mordor, which I will not utter here
    This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
    "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #5

    That empty destructor isn't actually empty - I just didn't post the contents. There's more going on in this class and I've just stripped it down for brevity.

    This space for rent

    F L 2 Replies Last reply
    0
    • P Pete OHanlon

      That empty destructor isn't actually empty - I just didn't post the contents. There's more going on in this class and I've just stripped it down for brevity.

      This space for rent

      F Offline
      F Offline
      Florian Rappl
      wrote on last edited by
      #6

      Yes, sure. Any reason for not using constructor initializer? Such direct assignments are where they shine!

      L P 2 Replies Last reply
      0
      • P Pete OHanlon

        That empty destructor isn't actually empty - I just didn't post the contents. There's more going on in this class and I've just stripped it down for brevity.

        This space for rent

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #7

        It's not a bad thing to keep classes as stateless as possible. So much less that has to be memory managed or made thread safe. An empty destructor would mean that the class is very safe in that respect, but it's not a good idea to try to reach this at all cost.

        The language is JavaScript. that of Mordor, which I will not utter here
        This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
        "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

        1 Reply Last reply
        0
        • F Florian Rappl

          Yes, sure. Any reason for not using constructor initializer? Such direct assignments are where they shine!

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #8

          When debugging, I like to have all my eggs in one basket. A single destructor where everything is in one spot makes it harder to overlook something instead of when the initialisation is distributed all over the place. For clarity and readability, I think there should be exactly one way of doing something. If not, choose one and stick to it. This way there are less surprises for those who look at your code for the first time.

          The language is JavaScript. that of Mordor, which I will not utter here
          This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
          "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

          1 Reply Last reply
          0
          • F Florian Rappl

            Yes, sure. Any reason for not using constructor initializer? Such direct assignments are where they shine!

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #9

            It is, but I'm not that worried about this at the moment. I will refactor later on, but right now I'm using this to log out the device status and options so while I'm locking this down I'm staying old school.

            This space for rent

            1 Reply Last reply
            0
            • P Pete OHanlon

              So, as some of the longer term viewers may know, I used to be a C++ developer; way back in the mists of time. I loved C++ and then the new girl came to town and seduced me with her wiles. No longer would I put up with manual memory management, iterating over for statements when I could use the seductive foreach. Well, I have recently started getting quite heavily back into C++ using the newer additions to the language such as auto and for (auto index : my_vector) as a foreach. The features that are available now are great and C++ really has matured. So much so that I'm using it to write some drone software. I'm a big fan of fluent interfaces so I thought I'd play around and see how they work in C++ to see if I still want to keep with the new C++ and damn it, it's so straightforward.

              #pragma once
              #include <librealsense/rs.hpp>

              class RealSenseStream
              {
              public:
              explicit RealSenseStream(rs::device* device)
              {
              this->device = device;
              }
              ~RealSenseStream()
              {
              }

              RealSenseStream &WithDepth(rs::preset preset)
              {
              device->enable_stream(rs::stream::depth, preset);
              return *this;
              }

              RealSenseStream &WithColor(rs::preset preset)
              {
              device->enable_stream(rs::stream::color, preset);
              return *this;
              }

              private:
              rs::device* device;
              };

              This space for rent

              M Offline
              M Offline
              megaadam
              wrote on last edited by
              #10

              Glad to see you enjoy the new goodies. In my previous job, elephanting legacy forced us to stick with C++03. X| for(auto index: my_vector) is cool. for(const auto& index: my_vector) even more so! And, today we do not have to use pointers in containers any more. :cool:

              ... such stuff as dreams are made on

              D 1 Reply Last reply
              0
              • M megaadam

                Glad to see you enjoy the new goodies. In my previous job, elephanting legacy forced us to stick with C++03. X| for(auto index: my_vector) is cool. for(const auto& index: my_vector) even more so! And, today we do not have to use pointers in containers any more. :cool:

                ... such stuff as dreams are made on

                D Offline
                D Offline
                den2k88
                wrote on last edited by
                #11

                C++98 a la VS6. In 2016.

                DURA LEX, SED LEX GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani

                M 1 Reply Last reply
                0
                • D den2k88

                  C++98 a la VS6. In 2016.

                  DURA LEX, SED LEX GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani

                  M Offline
                  M Offline
                  megaadam
                  wrote on last edited by
                  #12

                  Please forgive my curiosity. You have been in that place for quite some time (I think), do you ever consider a switch?

                  ... such stuff as dreams are made on

                  D 1 Reply Last reply
                  0
                  • M megaadam

                    Please forgive my curiosity. You have been in that place for quite some time (I think), do you ever consider a switch?

                    ... such stuff as dreams are made on

                    D Offline
                    D Offline
                    den2k88
                    wrote on last edited by
                    #13

                    Almost 5 years, 9 months as a (paid) intern, 3 years as apprentice and then finally hired for good. I am considering a switch, for a number of reasosn, mostly for the low pay for the job I do but the working environment has its faults that are grating on my nerves after all this time. Its 4 years and a half that we have to upgrade to VS2008, I started using it but was forced every effing time to reimport all the changes in the VS6 project and fix the effing code because several things present and accepted in VS2008 fail under VS6. I stopped due to frustration.

                    DURA LEX, SED LEX GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani

                    1 Reply Last reply
                    0
                    • P Pete OHanlon

                      So, as some of the longer term viewers may know, I used to be a C++ developer; way back in the mists of time. I loved C++ and then the new girl came to town and seduced me with her wiles. No longer would I put up with manual memory management, iterating over for statements when I could use the seductive foreach. Well, I have recently started getting quite heavily back into C++ using the newer additions to the language such as auto and for (auto index : my_vector) as a foreach. The features that are available now are great and C++ really has matured. So much so that I'm using it to write some drone software. I'm a big fan of fluent interfaces so I thought I'd play around and see how they work in C++ to see if I still want to keep with the new C++ and damn it, it's so straightforward.

                      #pragma once
                      #include <librealsense/rs.hpp>

                      class RealSenseStream
                      {
                      public:
                      explicit RealSenseStream(rs::device* device)
                      {
                      this->device = device;
                      }
                      ~RealSenseStream()
                      {
                      }

                      RealSenseStream &WithDepth(rs::preset preset)
                      {
                      device->enable_stream(rs::stream::depth, preset);
                      return *this;
                      }

                      RealSenseStream &WithColor(rs::preset preset)
                      {
                      device->enable_stream(rs::stream::color, preset);
                      return *this;
                      }

                      private:
                      rs::device* device;
                      };

                      This space for rent

                      K Offline
                      K Offline
                      Kirill Illenseer
                      wrote on last edited by
                      #14

                      Indeed, modern C++ ist an elegant language. It has one huge flaw though: It's legacy. I, for example, can write elegant code in modern C++, but several of my coworkers can't. Some even brush me off with "I've learned it like that in the 60s and I won't learn anything new". Some even treat the C++-compiler as a C-compiler and write plain C, bluntly ignoring all the wonders of std::string or array. This makes me think that C++ still isn't ready for prime-time. The standard needs to deprecate all this legacy stuff and throw warnings all over the place if someone refuses to dig into the last 50 years of CS progression. If C++ starts doing that, I'll take it seriously. Until then, I'll stick to C# (unless I'm on a ressource-contrained embedded target).

                      H 1 Reply Last reply
                      0
                      • P Pete OHanlon

                        So, as some of the longer term viewers may know, I used to be a C++ developer; way back in the mists of time. I loved C++ and then the new girl came to town and seduced me with her wiles. No longer would I put up with manual memory management, iterating over for statements when I could use the seductive foreach. Well, I have recently started getting quite heavily back into C++ using the newer additions to the language such as auto and for (auto index : my_vector) as a foreach. The features that are available now are great and C++ really has matured. So much so that I'm using it to write some drone software. I'm a big fan of fluent interfaces so I thought I'd play around and see how they work in C++ to see if I still want to keep with the new C++ and damn it, it's so straightforward.

                        #pragma once
                        #include <librealsense/rs.hpp>

                        class RealSenseStream
                        {
                        public:
                        explicit RealSenseStream(rs::device* device)
                        {
                        this->device = device;
                        }
                        ~RealSenseStream()
                        {
                        }

                        RealSenseStream &WithDepth(rs::preset preset)
                        {
                        device->enable_stream(rs::stream::depth, preset);
                        return *this;
                        }

                        RealSenseStream &WithColor(rs::preset preset)
                        {
                        device->enable_stream(rs::stream::color, preset);
                        return *this;
                        }

                        private:
                        rs::device* device;
                        };

                        This space for rent

                        A Offline
                        A Offline
                        Anna Jayne Metcalfe
                        wrote on last edited by
                        #15

                        Welcome back to the codeface! ;) C++ 14 is amazing, and a very different language from the one I had to use until a few years ago. We had the pleasure of meeting Bjarne at the ACCU Conference a few years back when C++ 11 first landed, and his enthusiasm for the future of the language was infectious. I'm a big fan of std::shared_ptr, auto, range based loops and std::thread. All have (and still are) simplifying our code significantly. Then of course there are move semantics and rvalue references, which can dramatically improve performance. But more is coming - C++ 17[^] is nearly done (though sadly without the modules proposal[^], despite it already being implemented in Clang) and C++ 20 is being planned.

                        Anna (@annajayne) Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                        P 1 Reply Last reply
                        0
                        • A Anna Jayne Metcalfe

                          Welcome back to the codeface! ;) C++ 14 is amazing, and a very different language from the one I had to use until a few years ago. We had the pleasure of meeting Bjarne at the ACCU Conference a few years back when C++ 11 first landed, and his enthusiasm for the future of the language was infectious. I'm a big fan of std::shared_ptr, auto, range based loops and std::thread. All have (and still are) simplifying our code significantly. Then of course there are move semantics and rvalue references, which can dramatically improve performance. But more is coming - C++ 17[^] is nearly done (though sadly without the modules proposal[^], despite it already being implemented in Clang) and C++ 20 is being planned.

                          Anna (@annajayne) Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #16

                          It's a vastly different language to the one I knew. As I have the advantage of writing from scratch, I have the advantage of not having to deal with legacy and cruft. It's a liberating experience.

                          This space for rent

                          A 1 Reply Last reply
                          0
                          • K Kirill Illenseer

                            Indeed, modern C++ ist an elegant language. It has one huge flaw though: It's legacy. I, for example, can write elegant code in modern C++, but several of my coworkers can't. Some even brush me off with "I've learned it like that in the 60s and I won't learn anything new". Some even treat the C++-compiler as a C-compiler and write plain C, bluntly ignoring all the wonders of std::string or array. This makes me think that C++ still isn't ready for prime-time. The standard needs to deprecate all this legacy stuff and throw warnings all over the place if someone refuses to dig into the last 50 years of CS progression. If C++ starts doing that, I'll take it seriously. Until then, I'll stick to C# (unless I'm on a ressource-contrained embedded target).

                            H Offline
                            H Offline
                            Herbie Mountjoy
                            wrote on last edited by
                            #17

                            This sounds like me. I was once quite proficient in C++ but then I got into C# and simply haven't updated my C++ at all. Last time I used it was in 2003 I think. The latest versions look so different and have so many new features that I would really have to study hard to catch up.

                            We're philosophical about power outages here. A.C. come, A.C. go.

                            1 Reply Last reply
                            0
                            • P Pete OHanlon

                              So, as some of the longer term viewers may know, I used to be a C++ developer; way back in the mists of time. I loved C++ and then the new girl came to town and seduced me with her wiles. No longer would I put up with manual memory management, iterating over for statements when I could use the seductive foreach. Well, I have recently started getting quite heavily back into C++ using the newer additions to the language such as auto and for (auto index : my_vector) as a foreach. The features that are available now are great and C++ really has matured. So much so that I'm using it to write some drone software. I'm a big fan of fluent interfaces so I thought I'd play around and see how they work in C++ to see if I still want to keep with the new C++ and damn it, it's so straightforward.

                              #pragma once
                              #include <librealsense/rs.hpp>

                              class RealSenseStream
                              {
                              public:
                              explicit RealSenseStream(rs::device* device)
                              {
                              this->device = device;
                              }
                              ~RealSenseStream()
                              {
                              }

                              RealSenseStream &WithDepth(rs::preset preset)
                              {
                              device->enable_stream(rs::stream::depth, preset);
                              return *this;
                              }

                              RealSenseStream &WithColor(rs::preset preset)
                              {
                              device->enable_stream(rs::stream::color, preset);
                              return *this;
                              }

                              private:
                              rs::device* device;
                              };

                              This space for rent

                              E Offline
                              E Offline
                              englebart
                              wrote on last edited by
                              #18

                              All of the input and output operators in old, old C++ offered fluent interfaces. cin >> x >> y; cout << setw(10) << x << setw(12) << y << endl; Ignoring references, you can always just

                              return this;

                              at the end of a function which requires code like:

                              variable->f1(args1)->f2(args2)->f3(args3);

                              P 1 Reply Last reply
                              0
                              • E englebart

                                All of the input and output operators in old, old C++ offered fluent interfaces. cin >> x >> y; cout << setw(10) << x << setw(12) << y << endl; Ignoring references, you can always just

                                return this;

                                at the end of a function which requires code like:

                                variable->f1(args1)->f2(args2)->f3(args3);

                                P Offline
                                P Offline
                                Pete OHanlon
                                wrote on last edited by
                                #19

                                I'm happy enough with what I've got now.

                                This space for rent

                                1 Reply Last reply
                                0
                                • P Pete OHanlon

                                  It's a vastly different language to the one I knew. As I have the advantage of writing from scratch, I have the advantage of not having to deal with legacy and cruft. It's a liberating experience.

                                  This space for rent

                                  A Offline
                                  A Offline
                                  Anna Jayne Metcalfe
                                  wrote on last edited by
                                  #20

                                  It certainly is. :) Thought of coming along to the ACCU Conference? There's a strong C++ track (and sometimes even a C++ Pub Quiz with free beer...) there.

                                  Anna (@annajayne) Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                                  P 1 Reply Last reply
                                  0
                                  • A Anna Jayne Metcalfe

                                    It certainly is. :) Thought of coming along to the ACCU Conference? There's a strong C++ track (and sometimes even a C++ Pub Quiz with free beer...) there.

                                    Anna (@annajayne) Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                                    P Offline
                                    P Offline
                                    Pete OHanlon
                                    wrote on last edited by
                                    #21

                                    It depends how serious I get with this drone software. The more I'm playing around with this, the more I love working with drones and I can see me going further with it.

                                    This space for rent

                                    A 1 Reply Last reply
                                    0
                                    • P Pete OHanlon

                                      It depends how serious I get with this drone software. The more I'm playing around with this, the more I love working with drones and I can see me going further with it.

                                      This space for rent

                                      A Offline
                                      A Offline
                                      Anna Jayne Metcalfe
                                      wrote on last edited by
                                      #22

                                      Sounds cool. Have fun!

                                      Anna (@annajayne) Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                                      P 1 Reply Last reply
                                      0
                                      • A Anna Jayne Metcalfe

                                        Sounds cool. Have fun!

                                        Anna (@annajayne) Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                                        P Offline
                                        P Offline
                                        Pete OHanlon
                                        wrote on last edited by
                                        #23

                                        I'll be writing this up and posting video footage so you will be able to take a look at least at some of the code. It's really cool stuff.

                                        This space for rent

                                        A 1 Reply Last reply
                                        0
                                        • P Pete OHanlon

                                          I'll be writing this up and posting video footage so you will be able to take a look at least at some of the code. It's really cool stuff.

                                          This space for rent

                                          A Offline
                                          A Offline
                                          Anna Jayne Metcalfe
                                          wrote on last edited by
                                          #24

                                          Look forward to it :)

                                          Anna (@annajayne) Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                                          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