Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Rants about auto
Qt 6.11 is out! See what's new in the release blog

Rants about auto

Scheduled Pinned Locked Moved C++ Gurus
25 Posts 6 Posters 21.3k Views 2 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.
  • JonBJ JonB

    My 2¢: when you have MyRidiculouslyLongClassNameWhichIDontWantToTypeInEachTimeSoIUseEvilAuto, try

    typedef MyRidiculouslyLongClassNameWhichIDontWantToTypeInEachTimeSoIUseEvilAuto Z;
    
    Z abc;
    

    :)

    VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #11

    @JonB First of all using Z = MyRidiculouslyLongClassNameWhichIDontWantToTypeInEachTimeSoIUseEvilAuto; because C++11 :)

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    JonBJ 1 Reply Last reply
    0
    • VRoninV VRonin

      @JonB First of all using Z = MyRidiculouslyLongClassNameWhichIDontWantToTypeInEachTimeSoIUseEvilAuto; because C++11 :)

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #12

      @VRonin
      Sigh, looks like my C knowledge is increasingly invalid :( But I don't see what's wrong with typedef here, I'm not using a template.
      BTW, I wouldn't really name it Z here, of course I'd use MRLCNWIDWTTIETSIUEA because it's much clearer what that means!

      VRoninV 1 Reply Last reply
      3
      • JonBJ JonB

        @VRonin
        Sigh, looks like my C knowledge is increasingly invalid :( But I don't see what's wrong with typedef here, I'm not using a template.
        BTW, I wouldn't really name it Z here, of course I'd use MRLCNWIDWTTIETSIUEA because it's much clearer what that means!

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #13

        @JonB said in Rants about auto:

        But I don't see what's wrong with typedef here

        Nothing, I was just taking the piss. they are equivalent with the only difference that the Z type can be a template with using while it can't with typedef.

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        JonBJ 1 Reply Last reply
        1
        • VRoninV VRonin

          @JonB said in Rants about auto:

          But I don't see what's wrong with typedef here

          Nothing, I was just taking the piss. they are equivalent with the only difference that the Z type can be a template with using while it can't with typedef.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #14

          @VRonin
          Oh, lol! Once I started reading up about this new using I suspected that now I was supposed to use that every time....

          With typedefs you can string them together for a nice extra level of confusion ;) So you write

          typedef int I, *PI;
          

          which makes me wonder: without you looking it up, if I write:

          typedef int *PI, T;
          

          is T type int or int *? :)

          kshegunovK 1 Reply Last reply
          0
          • JonBJ JonB

            @VRonin
            Oh, lol! Once I started reading up about this new using I suspected that now I was supposed to use that every time....

            With typedefs you can string them together for a nice extra level of confusion ;) So you write

            typedef int I, *PI;
            

            which makes me wonder: without you looking it up, if I write:

            typedef int *PI, T;
            

            is T type int or int *? :)

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #15

            @JonB said in Rants about auto:

            is T type int or int *?

            int.
            We are not JS devs, you know ... ;P

            Read and abide by the Qt Code of Conduct

            JonBJ 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @JonB said in Rants about auto:

              is T type int or int *?

              int.
              We are not JS devs, you know ... ;P

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #16

              @kshegunov
              Hmm. OK, then, could you please explain how the * binds in typedef int *PI, T;.

              Why is that typedef not int * for T? And if you wanted it to bind as int * for T (i.e. making it same as PI), how could you force that, e.g. something like (I'm sure it's not right):

              typedef (int *)PI, T
              

              P.S.

              We are not JS devs, you know

              Ummm, relevance? JS doesn't even have type declarations or pointers, so...?

              kshegunovK 1 Reply Last reply
              0
              • JonBJ JonB

                @kshegunov
                Hmm. OK, then, could you please explain how the * binds in typedef int *PI, T;.

                Why is that typedef not int * for T? And if you wanted it to bind as int * for T (i.e. making it same as PI), how could you force that, e.g. something like (I'm sure it's not right):

                typedef (int *)PI, T
                

                P.S.

                We are not JS devs, you know

                Ummm, relevance? JS doesn't even have type declarations or pointers, so...?

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #17

                @JonB said in Rants about auto:

                Why is that typedef not int * for T?

                Not 100% about the theory behind it, but it's like with initialization (I assume it's cause , has very low priority). Say you have:

                char * p, n;
                

                p is char *, but n is char.

                And if you wanted it to bind as int * for T (i.e. making it same as PI), how could you force that, e.g. something like (I'm sure it's not right):

                typedef int *PI, *T;
                

                Ummm, relevance? JS doesn't even have type declarations or pointers, so...?

                Simply an ill-concealed insult. :)

                PS:

                Simply an ill-concealed insult.

                https://www.destroyallsoftware.com/talks/wat

                Read and abide by the Qt Code of Conduct

                JonBJ ODБOïO 2 Replies Last reply
                4
                • kshegunovK kshegunov

                  @JonB said in Rants about auto:

                  Why is that typedef not int * for T?

                  Not 100% about the theory behind it, but it's like with initialization (I assume it's cause , has very low priority). Say you have:

                  char * p, n;
                  

                  p is char *, but n is char.

                  And if you wanted it to bind as int * for T (i.e. making it same as PI), how could you force that, e.g. something like (I'm sure it's not right):

                  typedef int *PI, *T;
                  

                  Ummm, relevance? JS doesn't even have type declarations or pointers, so...?

                  Simply an ill-concealed insult. :)

                  PS:

                  Simply an ill-concealed insult.

                  https://www.destroyallsoftware.com/talks/wat

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #18

                  @kshegunov

                  typedef int *PI, *T;

                  That is cheating! You know it. You know that I know it can be done that way, that wasn't the question. I want the *s to be included in the "base" part of the typedef I am declaring, so that I can write like:

                  typedef (int **********) PI, PI2_same_as_PI, *PI3_one_extra_pointer;
                  

                  I don't want to repeat the *s, and I don't want to declare a separate, intermediate typedef to achieve it.

                  As you say, thinking about the typedef just like a list-of-variables declaration, I guess it cannot be done? The *s just aren't a part of the "base" type being declared, they belong only to each type-name/variable being declared individually? And this is why we tend/are encouraged to write char *p and not char* p in C.

                  As for the JS. I know I am a cheerleader for C compared to C++, but I have never said I am a fanboi for all the JS stuff I have had to write over the years.

                  kshegunovK 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @kshegunov

                    typedef int *PI, *T;

                    That is cheating! You know it. You know that I know it can be done that way, that wasn't the question. I want the *s to be included in the "base" part of the typedef I am declaring, so that I can write like:

                    typedef (int **********) PI, PI2_same_as_PI, *PI3_one_extra_pointer;
                    

                    I don't want to repeat the *s, and I don't want to declare a separate, intermediate typedef to achieve it.

                    As you say, thinking about the typedef just like a list-of-variables declaration, I guess it cannot be done? The *s just aren't a part of the "base" type being declared, they belong only to each type-name/variable being declared individually? And this is why we tend/are encouraged to write char *p and not char* p in C.

                    As for the JS. I know I am a cheerleader for C compared to C++, but I have never said I am a fanboi for all the JS stuff I have had to write over the years.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #19

                    @JonB said in Rants about auto:

                    I don't want to repeat the *s, and I don't want to declare a separate, intermediate typedef to achieve it.

                    Then you're out of luck.

                    And this is why we tend/are encouraged to write

                    That's just style. I write spaces on both sides:

                    char * p;
                    char ** p;
                    

                    and so on.

                    I know I am a cheerleader for C compared to C++

                    That's like being cheerleader for FORTRAN against C. ;)

                    but I have never said I am a fanboi for all the JS stuff I have had to write over the years.

                    Granted. I was just making fun of JS devs. ;P

                    Read and abide by the Qt Code of Conduct

                    JonBJ 1 Reply Last reply
                    0
                    • kshegunovK kshegunov

                      @JonB said in Rants about auto:

                      I don't want to repeat the *s, and I don't want to declare a separate, intermediate typedef to achieve it.

                      Then you're out of luck.

                      And this is why we tend/are encouraged to write

                      That's just style. I write spaces on both sides:

                      char * p;
                      char ** p;
                      

                      and so on.

                      I know I am a cheerleader for C compared to C++

                      That's like being cheerleader for FORTRAN against C. ;)

                      but I have never said I am a fanboi for all the JS stuff I have had to write over the years.

                      Granted. I was just making fun of JS devs. ;P

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #20

                      @kshegunov
                      The declaration layout is just style, but I meant that char *p instead of char* p makes clear how C type declarations with * actually bind, relevant if you have a list of them (char *p, *q better than char* p, *q).

                      1 Reply Last reply
                      1
                      • kshegunovK kshegunov

                        @JonB said in Rants about auto:

                        Why is that typedef not int * for T?

                        Not 100% about the theory behind it, but it's like with initialization (I assume it's cause , has very low priority). Say you have:

                        char * p, n;
                        

                        p is char *, but n is char.

                        And if you wanted it to bind as int * for T (i.e. making it same as PI), how could you force that, e.g. something like (I'm sure it's not right):

                        typedef int *PI, *T;
                        

                        Ummm, relevance? JS doesn't even have type declarations or pointers, so...?

                        Simply an ill-concealed insult. :)

                        PS:

                        Simply an ill-concealed insult.

                        https://www.destroyallsoftware.com/talks/wat

                        ODБOïO Offline
                        ODБOïO Offline
                        ODБOï
                        wrote on last edited by
                        #21

                        Hi,
                        @kshegunov said in Rants about auto:

                        https://www.destroyallsoftware.com/talks/wat

                        Can please someone tell me what environment is using Gary Bernhardt in that video ?

                        JonBJ kshegunovK 2 Replies Last reply
                        0
                        • ODБOïO ODБOï

                          Hi,
                          @kshegunov said in Rants about auto:

                          https://www.destroyallsoftware.com/talks/wat

                          Can please someone tell me what environment is using Gary Bernhardt in that video ?

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #22

                          @LeLev
                          He is not using a special "environment" or IDE. He's just using a terminal/console, then running a Ruby/JS command-line interpreter which allows you type in statements to evaluate.

                          1 Reply Last reply
                          4
                          • ODБOïO ODБOï

                            Hi,
                            @kshegunov said in Rants about auto:

                            https://www.destroyallsoftware.com/talks/wat

                            Can please someone tell me what environment is using Gary Bernhardt in that video ?

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #23

                            I believe it's zsh that he uses, otherwise Jon's right, he just starts the interpreters from the command line.

                            Read and abide by the Qt Code of Conduct

                            JonBJ 1 Reply Last reply
                            2
                            • kshegunovK kshegunov

                              I believe it's zsh that he uses, otherwise Jon's right, he just starts the interpreters from the command line.

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #24

                              @kshegunov
                              And the relevance of it being specifically zsh is... what? :) You just looking for extra points? ;-)

                              kshegunovK 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @kshegunov
                                And the relevance of it being specifically zsh is... what? :) You just looking for extra points? ;-)

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on last edited by
                                #25

                                @JonB said in Rants about auto:

                                And the relevance of it being specifically zsh is... what?

                                Environment of the interpreter.

                                You just looking for extra points?

                                Yep! Gimme, gimme!

                                Read and abide by the Qt Code of Conduct

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt
                                • Unsolved