. as an alternative to m_

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Becke

    . as an alternative to m_

    I know this isn't the place for suggestions, but I just need to vent. Why
    dont c++ compilers let us use . as way of saying "this->", and hence an
    alternative for m_

    struct foo {
    int a;
    void bar(int a){
    .a = a;
    }
    };


  • Victor Bazarov

    #2
    Re: . as an alternative to m_

    Chris Becke wrote:
    I know this isn't the place for suggestions, but I just need to vent. Why
    dont c++ compilers let us use . as way of saying "this->", and hence an
    alternative for m_
    >
    struct foo {
    int a;
    void bar(int a){
    .a = a;
    }
    };
    IMHO, 'this->' (or, if you define "self" as "(*this)", 'self.') is
    actually more readable than the dot. I would actually prefer to see
    this-or m_ than the dot. Besides, 'a' is such a dumb name for a
    variable; sorry if that offends you.

    The reason is that it doesn't buy enough (or anything, really) and it
    complicates the grammar, most likely.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask

    Comment

    • Chris Becke

      #3
      Re: . as an alternative to m_

      its more complicated htan nothing but it is unambiguous - so not that much
      more complicated methinks.

      And, a was chosen to be dumb :P Its just a sample for illustration purposes
      afterall.

      I think . like this has a neat symmetry.

      You could write an external function

      void bar(foo & s, int a){
      s.a = a;
      }

      or a member function (as before).

      void foo:bar(int a){
      .a = a;
      }

      I don't know. Written like that its a rather logical extension.

      "Victor Bazarov" <v.Abazarov@com Acast.netwrote in message
      news:g79o9o$o3o $1@news.datemas .de...
      Chris Becke wrote:
      >I know this isn't the place for suggestions, but I just need to vent. Why
      >dont c++ compilers let us use . as way of saying "this->", and hence an
      >alternative for m_
      >>
      >struct foo {
      > int a;
      > void bar(int a){
      > .a = a;
      > }
      >};
      >
      IMHO, 'this->' (or, if you define "self" as "(*this)", 'self.') is
      actually more readable than the dot. I would actually prefer to see
      this-or m_ than the dot. Besides, 'a' is such a dumb name for a
      variable; sorry if that offends you.
      >
      The reason is that it doesn't buy enough (or anything, really) and it
      complicates the grammar, most likely.
      >
      V
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask

      Comment

      • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

        #4
        Re: . as an alternative to m_

        On 2008-08-05 16:25, Chris Becke wrote:
        I know this isn't the place for suggestions, but I just need to vent. Why
        dont c++ compilers let us use . as way of saying "this->", and hence an
        alternative for m_
        >
        struct foo {
        int a;
        void bar(int a){
        .a = a;
        }
        };

        Because it is less verbose and thus less good. If the time saved by
        typing "." instead of "this->" is significant it means you are not
        thinking enough before you start coding.

        Besides, using cryptic characters to mean different things leads to
        pearl syntax, which can easily be confused with cussing.

        --
        Erik Wikström

        Comment

        • red floyd

          #5
          Re: . as an alternative to m_

          On Aug 5, 7:25 am, "Chris Becke" <chris.be...@gm ail.comwrote:
          I know this isn't the place for suggestions, but I just need to vent. Why
          dont c++ compilers let us use . as way of saying "this->", and hence an
          alternative for m_
          >
          struct foo {
            int a;
            void bar(int a){
              .a = a;
            }
          >
          };
          >
          Because you don't need m_? Because you don't need this->? Because
          having a member function parameter named the same as a member variable
          is suboptimal code?

          struct foo {
          int a;
          void bar(int a_) {
          a = a_;
          }
          };

          What's the problem?

          Comment

          • Matthias Buelow

            #6
            Re: . as an alternative to m_

            Chris Becke wrote:
            void foo:bar(int a){
            .a = a;
            }
            What is more annoying is that the following doesn't work:

            void foo::bar(int a)
            : a(a)
            { /* ... */ }

            Instead, you have to use something like

            void foo::bar(int a_)
            : a(a_)
            { /* ... */ }

            There's no point in that, it's simply fkuced-up scoping rules.

            Comment

            • Matthias Buelow

              #7
              Re: . as an alternative to m_

              void foo::bar(int a)
              : a(a)
              Err, make that foo::foo of course.

              Comment

              • Rolf Magnus

                #8
                Re: . as an alternative to m_

                Matthias Buelow wrote:
                Chris Becke wrote:
                >
                > void foo:bar(int a){
                > .a = a;
                > }
                >
                What is more annoying is that the following doesn't work:
                >
                void foo::bar(int a)
                : a(a)
                { /* ... */ }
                But it does.
                Instead, you have to use something like
                >
                void foo::bar(int a_)
                : a(a_)
                { /* ... */ }
                No, you don't have to.

                Comment

                • Matthias Buelow

                  #9
                  Re: . as an alternative to m_

                  Rolf Magnus wrote:
                  >void foo::bar(int a)
                  > : a(a)
                  >
                  But it does.
                  Err. When did this creep in? I remember getting errors when I tried that.

                  Comment

                  • Victor Bazarov

                    #10
                    Re: . as an alternative to m_

                    Matthias Buelow wrote:
                    Chris Becke wrote:
                    >
                    > void foo:bar(int a){
                    > .a = a;
                    > }
                    >
                    What is more annoying is that the following doesn't work:
                    >
                    void foo::bar(int a)
                    : a(a)
                    { /* ... */ }
                    It does, actually. Have you even tried?
                    >
                    Instead, you have to use something like
                    >
                    void foo::bar(int a_)
                    : a(a_)
                    { /* ... */ }
                    >
                    There's no point in that, it's simply fkuced-up scoping rules.
                    I suggest you actually try it before putting your foot in your mouth.

                    V
                    --
                    Please remove capital 'A's when replying by e-mail
                    I do not respond to top-posted replies, please don't ask

                    Comment

                    • Victor Bazarov

                      #11
                      Re: . as an alternative to m_

                      Matthias Buelow wrote:
                      Rolf Magnus wrote:
                      >
                      >>void foo::bar(int a)
                      >> : a(a)
                      >But it does.
                      >
                      Err. When did this creep in? I remember getting errors when I tried that.
                      You must have really good memory. I don't remember ever getting any
                      errors in that situation. Of course, nothing beats getting a false
                      impression of the "fkuced-up scoping rules" like using a buggy compiler.

                      V
                      --
                      Please remove capital 'A's when replying by e-mail
                      I do not respond to top-posted replies, please don't ask

                      Comment

                      • Matthias Buelow

                        #12
                        Re: . as an alternative to m_

                        Victor Bazarov wrote:
                        You must have really good memory. I don't remember ever getting any
                        errors in that situation. Of course, nothing beats getting a false
                        impression of the "fkuced-up scoping rules" like using a buggy compiler.
                        This is really puzzling me now. I've been using that "workaround " for
                        quite some time and have always been mildly annoyed that I had to do it
                        that way. Well, good to know now it isn't necessary. :)

                        Comment

                        • kwikius

                          #13
                          Re: . as an alternative to m_


                          "Victor Bazarov" <v.Abazarov@com Acast.netwrote in message
                          news:g79o9o$o3o $1@news.datemas .de...
                          Besides, 'a' is such a dumb name for a variable; sorry if that offends
                          you.
                          Whats wrong with a? Nothing wrong with a. I always use a for all my
                          variables. Stand up for a I say !

                          regards
                          Andy Little


                          Comment

                          • acehreli@gmail.com

                            #14
                            Re: . as an alternative to m_

                            On Aug 5, 9:30 am, Rolf Magnus <ramag...@t-online.dewrote:
                            Matthias Buelow wrote:
                            What is more annoying is that the following doesn't work:
                            >
                            void foo::bar(int a)
                              : a(a)
                            { /* ... */ }
                            >
                            But it does.
                            >
                            Instead, you have to use something like
                            >
                            void foo::bar(int a_)
                              : a(a_)
                            { /* ... */ }
                            >
                            No, you don't have to.
                            The problem is when we get in to the constructor body, where 'a'
                            starts referring to the argument, not the member. :( So

                            a = 42;

                            doesn't change the object.

                            Ali

                            Comment

                            • Victor Bazarov

                              #15
                              Re: . as an alternative to m_

                              kwikius wrote:
                              "Victor Bazarov" <v.Abazarov@com Acast.netwrote in message
                              news:g79o9o$o3o $1@news.datemas .de...
                              >
                              > Besides, 'a' is such a dumb name for a variable; sorry if that offends
                              >you.
                              >
                              Whats wrong with a? Nothing wrong with a. I always use a for all my
                              variables. Stand up for a I say !
                              I don't like 'a',
                              I don't like 'k',
                              No, I don't like them! Non, nein, nay!

                              I can write 'i',
                              I do use 'Pi',
                              Or 'z', or 'x', or even 'y'.

                              But spare me 'p',
                              Or 'l', or 'c'.
                              They don't say 'nuff, do you agree?

                              :-)

                              V
                              --
                              Please remove capital 'A's when replying by e-mail
                              I do not respond to top-posted replies, please don't ask

                              Comment

                              Working...