"Variables" tutorial available (Windows, mingw/msvc)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alf P. Steinbach

    "Variables" tutorial available (Windows, mingw/msvc)

    A few days ago I posted an "Hello, world!" tutorial, discussed in <url:
    http://groups.google.n o/groups?threadm= 41ba4c0a.768690 78@news.individ ual.net>.

    As I wrote then:

    <quote>
    because there seems to be a lack of post-standard _correct_
    tutorials: <url: http://home.no.net/dubjai/win32cpptut/>.
    </quote>

    This is the follow up, part 02, discussing variables (the directory
    referred above contains two documents, part 01 and part 02).

    I aim at the complete newbie, but as the earlier debate showed, even for
    these fundamental topics there were things to be learned also for far
    more experienced C++ folks.

    I hope I haven't committed too many errors of my own ( ;-) ), and look
    forward to corrections -- just not "it's too long", every word counts.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
  • Tim Love

    #2
    Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

    alfps@start.no (Alf P. Steinbach) writes:
    [color=blue]
    >A few days ago I posted an "Hello, world!" tutorial, discussed in <url:
    >http://groups.google.n o/groups?threadm= 41ba4c0a.768690 78@news.individ ual.net>.[/color]
    [color=blue]
    >As I wrote then:[/color]
    [color=blue]
    ><quote>
    > because there seems to be a lack of post-standard _correct_
    > tutorials: <url: http://home.no.net/dubjai/win32cpptut/>.
    ></quote>[/color]

    To put Word docs online to deal with a lack of online post-standard
    documentation seems odd to me.

    Comment

    • Alf P. Steinbach

      #3
      Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

      * Tim Love:[color=blue]
      > alfps@start.no (Alf P. Steinbach) writes:
      >[color=green]
      > >A few days ago I posted an "Hello, world!" tutorial, discussed in <url:
      > >http://groups.google.n o/groups?threadm= 41ba4c0a.768690 78@news.individ ual.net>.[/color]
      >[color=green]
      > >As I wrote then:[/color]
      >[color=green]
      > ><quote>
      > > because there seems to be a lack of post-standard _correct_
      > > tutorials: <url: http://home.no.net/dubjai/win32cpptut/>.
      > ></quote>[/color]
      >
      > To put Word docs online to deal with a lack of online post-standard
      > documentation seems odd to me.[/color]

      Yes, it would be (there _is_ no lack of online post-standard
      documentation, but there is an apparent lack of online tutorials).

      I use Word just for my convenience as writer; feel free to generate PDF
      and/or XHTML or whatever -- just include a reference to the original
      which might be updated.

      For part 01 someone suggested (don't know how seriously) he could
      convert to proper HTML, but until someone does, I've reacted to your
      feedback by simply also posting Word-generated HTML versions, tested in
      Firefox. It works, sort of. But it's not easy on the eye... ;-)

      --
      A: Because it messes up the order in which people normally read text.
      Q: Why is it such a bad thing?
      A: Top-posting.
      Q: What is the most annoying thing on usenet and in e-mail?

      Comment

      • Thomas Hansen

        #4
        Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

        Page 7, line "Welcome to C++, Målfrid Sæbo!" should probably be
        "Welcome to C++, Malfrid Sabo!" since you're trying to show that æøå
        changes...?!?

        BTW!
        Why don't you make a complete book and make it public?
        GPL maybe?!?
        There are other good books GPL licensed, but none about C++ I think...
        That would be GREAT since many people can't afford the prices that the
        (good) C++ books are costing and as a consequence therefor buy CRAPPY
        books and ends up writing CRAPPY code...!!
        Also this would probably "force" schools to use YOUR book instead of
        some crappy old junk book teaching all the wrong things...

        And also I think in such a chapter it would be apropriate to maybe
        introduce command line arguments...?
        So maybe instead of reading string from cin parse some command line
        arguments and "spit out"...
        Might be it's too early to introduce com. line params., but I think not
        since you may "push" parts of the understanding forward (pointers,
        arrays etc...)

        There's a good class in SmartWin (I believe you know where to find it
        ;) which parses command line params...

        BTW2!
        Let me know when you finish it if you're going "public" (I think you
        know what email address I've got ;) since I would love to host it at
        the SmartWin website...
        SmartWin draws alot of attention from C++ newbies since it's
        syntactically very easy so having a beginners book about the language
        there too would be awesome!!

        ..t

        Comment

        • Thomas Hansen

          #5
          Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

          page 14...
          "C++ has a bunch of different assignment operators:"

          List them all!
          Don't leave the readers in vain...
          The reader won't care about the list in the first readthrough, but
          afterwards when he need a special assignment operator he'll remember
          "that book had a list about here..."...

          ..t

          Comment

          • Thomas Hansen

            #6
            Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

            also page 14...
            Tell about the difference of:
            ++x;
            and:
            x++;
            Maybe like:
            Code:
            #include <ostream>
            int main()
            {
            int x = 5;
            std::cout << x << std::endl;
            std::cout << ++x << std::endl;
            std::cout << x << std::endl;
            std::cout << x++ << std::endl;
            std::cout << x << std::endl;
            }
            Yet again, this will be "overkill" for a newbie, but when he needs the
            info he'll use the book as a reference...

            Also you should probably bring up the "for( int x; x < 5; x++ )"
            misunderstandin g...
            A lot of programming gurus (from e.g. Java camp) I've met have gotten
            this one wrong and thinks that the increment part happens BEFORE the
            body of the loop...
            I know you're trying to keep a structure in the book where "branching"
            probably comes in the chapter AFTER this one, but still it might be
            good to at least point to a page in the book or use a footnote about
            the issue since it's more "post/pre inc/decr operator" related then
            "looping" related...


            also:
            "OK, what next? I don't know, but probably an overview of built-in
            types and operations."
            First of all I would have covered all built in types in this chapter,
            second I would jump to LOOPS!
            Now the reader is Querious, keep him there by showing him some FUN
            stuff...

            (I remember the days of...)
            10 CLS
            20 PRINT "Thomas"
            30 GOTO 20

            ....Those were the chapters making it worthwile to read books about
            programming....

            And btw...
            Very good initiative!
            When I started C++ I searched the net for a good tutorial and basically
            all I found sucked!
            This made it MUCH harder for me to learn the language then it would
            have been if I had a good tutorial (or bought a good book... ;) )

            ..t

            Comment

            • Stephan Brönnimann

              #7
              Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

              I did send you the HTML file together with a CSS stylesheet.
              Never got the e-mail I've send to you privately?
              If so send an email to broeni[skip until @...]@hotmail.com.
              Or: should I publish temporarly on my website?

              regards,
              Stephan Brönnimann
              broeni@osb-systems.com

              Open source rating and billing engine for
              communication networks.

              Comment

              • Alf P. Steinbach

                #8
                Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

                * Thomas Hansen:[color=blue]
                >
                > Page 7, line "Welcome to C++, M=E5lfrid S=E6bo!" should probably be
                > "Welcome to C++, Malfrid Sabo!" since you're trying to show that =E6=F8=E5
                > changes...?!?[/color]

                Nope. I'm not typing those examples in the word processor.

                I'm copying them, copy/paste, from my console window so they're
                100% accurate for at least _one_ actual Windows setup.

                Exception: some places I've changed the filenames afterwards, and just
                hope I haven't introduced any errors that way.

                Depending on the setup of Windows non-English letters might appear
                differently: differently when typed, and when displayed as output from a
                program.

                Norwegian æ, Æ, å and Å are however part of the original IBM PC English
                character code (code page 437). It just lacked ø and Ø, which meant
                that for years without end we had to struggle with various custom
                encodings resulting in ø and Ø often being rendered as | and \, or as ¢
                and ¥, respectively. This ended with the introduction of the Windows
                ANSI character code (code page 1252), which is/was based on an early
                ANSI draft of what later became ISO Latin-1, the character code I'm
                using right here and which is still the most common one on the Usenet
                and WWW. For that particular example which involved a round-trip with
                no other conversion than the console window's own conversion, æÆåÅ will
                typically not be affected, because AFAIK all common Western narrow
                character codes that are typical for console Windows have those
                characters. However, if the program had tried to open a file with a
                name provided by the user, then the user's typing would be in e.g. code
                page 437, but in the program and vis-a-vis the Windows API (used at
                bottom by C++ file handling) the filename would be interpreted according
                to code page 1252, and _all_ of æÆøØåÅ would be affected (no such file).


                [snip][color=blue]
                > And also I think in such a chapter it would be apropriate to maybe
                > introduce command line arguments...?[/color]

                Thanks for the suggestion.

                Yes it is a problem.

                But that requires at minimum indexing, and probably loops to be useful,
                which I think is premature at that point (dealing with variables
                for the first time, and having to master a lot of seemingly arbitrary &
                cryptic tool usage details, having only made "Hello, world!" earlier).

                --
                A: Because it messes up the order in which people normally read text.
                Q: Why is it such a bad thing?
                A: Top-posting.
                Q: What is the most annoying thing on usenet and in e-mail?

                Comment

                • Alf P. Steinbach

                  #9
                  Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

                  * Thomas Hansen:[color=blue]
                  > page 14...
                  > "C++ has a bunch of different assignment operators:"
                  >
                  > List them all!
                  > Don't leave the readers in vain...
                  > The reader won't care about the list in the first readthrough, but
                  > afterwards when he need a special assignment operator he'll remember
                  > "that book had a list about here..."...
                  >
                  > .t[/color]

                  Good point.

                  Will do.

                  I thought it was enough to provide a general rule, but now I see that
                  that rule should be followed by its concrete result: a table listing all
                  of the assignment operators.



                  Btw., page numbers seem to depend on e.g. font and page size, it's my
                  page 13 -- the Bad Luck page! ;-)

                  --
                  A: Because it messes up the order in which people normally read text.
                  Q: Why is it such a bad thing?
                  A: Top-posting.
                  Q: What is the most annoying thing on usenet and in e-mail?

                  Comment

                  • Alf P. Steinbach

                    #10
                    Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

                    * =?iso-8859-1?q?Stephan_Br= F6nnimann?=:[color=blue]
                    > I did send you the HTML file together with a CSS stylesheet.
                    > Never got the e-mail I've send to you privately?
                    > If so send an email to broeni[skip until @...]@hotmail.com.
                    > Or: should I publish temporarly on my website?[/color]

                    I got it an hour or two ago (I think). Thanks very much. I replied to
                    your mail then.

                    The mail account is my web-based Usenet mail account so I don't
                    check it very often.

                    I'll send you a mail from my regular account... ;-)

                    It looked great in FireFox, just some details I saw after replying to
                    your mail: the special characters arrow -> and left triangle <| were
                    translated to something and ordinary "<". Right arrow is HTML
                    "&rarr;" or "→". Left triangle (used for end-of-code) I don't
                    know, but perhaps just a left arrow instead, "&larr;" or "←"
                    (which corresponds very nicely with usual rendering of Ctrl Z used as
                    end-of-file in Windows text files)?

                    Your website is perhaps best because you can more easily update
                    changes.

                    Can I put your HTML version in the same directory as the Word files
                    (one of my web sites)?

                    --
                    A: Because it messes up the order in which people normally read text.
                    Q: Why is it such a bad thing?
                    A: Top-posting.
                    Q: What is the most annoying thing on usenet and in e-mail?

                    Comment

                    • Stephan Brönnimann

                      #11
                      Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)


                      Alf P. Steinbach wrote:
                      [snip][color=blue]
                      > [snip][color=green]
                      > > And also I think in such a chapter it would be apropriate to maybe
                      > > introduce command line arguments...?[/color]
                      >
                      > Thanks for the suggestion.
                      >
                      > Yes it is a problem.
                      >
                      > But that requires at minimum indexing, and probably loops to be[/color]
                      useful,[color=blue]
                      > which I think is premature at that point (dealing with variables
                      > for the first time, and having to master a lot of seemingly arbitrary[/color]
                      &[color=blue]
                      > cryptic tool usage details, having only made "Hello, world!"[/color]
                      earlier).[color=blue]
                      >[/color]

                      I'd not introduce command line arguments now:
                      many poeple don't know the POSIX function getopt(...),
                      and I guess it would be a good idea to provide a wrapper
                      base class around it in the tutorial. See

                      for an example.

                      regards,
                      Stephan Brönnimann
                      bro...@osb-systems.com

                      Open source rating and billing engine for
                      communication networks.

                      Comment

                      • Alf P. Steinbach

                        #12
                        Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

                        * =?iso-8859-1?q?Stephan_Br= F6nnimann?=:[color=blue]
                        >
                        > Alf P. Steinbach wrote:
                        > [snip][color=green]
                        > > [snip][color=darkred]
                        > > > And also I think in such a chapter it would be apropriate to maybe
                        > > > introduce command line arguments...?[/color]
                        > >
                        > > Thanks for the suggestion.
                        > >
                        > > Yes it is a problem.
                        > >
                        > > But that requires at minimum indexing, and probably loops to be[/color]
                        > useful,[color=green]
                        > > which I think is premature at that point (dealing with variables
                        > > for the first time, and having to master a lot of seemingly arbitrary[/color]
                        > &[color=green]
                        > > cryptic tool usage details, having only made "Hello, world!"[/color]
                        > earlier).[color=green]
                        > >[/color]
                        >
                        > I'd not introduce command line arguments now:
                        > many poeple don't know the POSIX function getopt(...),
                        > and I guess it would be a good idea to provide a wrapper
                        > base class around it in the tutorial. See
                        > http://dev.robotbattle.com/~cvsuser/...v2/trunk/src/=
                        > utils.hpp?view= 3Dmarkup
                        > for an example.[/color]

                        Thank you for that suggestion.

                        What about <url: http://www.boost.org/doc/html/program_options .html>?

                        --
                        A: Because it messes up the order in which people normally read text.
                        Q: Why is it such a bad thing?
                        A: Top-posting.
                        Q: What is the most annoying thing on usenet and in e-mail?

                        Comment

                        • Alf P. Steinbach

                          #13
                          Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

                          * Thomas Hansen:[color=blue]
                          > also page 14...
                          > Tell about the difference of:
                          > ++x;
                          > and:
                          > x++;
                          > Maybe like:
                          > [code][/color]

                          Was already there, a whole section devoted to it: the last one.


                          [color=blue]
                          > Also you should probably bring up the "for( int x; x < 5; x++ )"
                          > misunderstandin g...
                          > A lot of programming gurus (from e.g. Java camp) I've met have gotten
                          > this one wrong and thinks that the increment part happens BEFORE the
                          > body of the loop...[/color]

                          Not much of programming gurus, then: it's the same in Java as in C++.

                          I think that must be a misunderstandin g peculiar to a given project
                          group or firm (or educational institution...) .

                          I've never encountered it, neither as a lecturer nor as a consultant.


                          [snip][color=blue]
                          > also:
                          > "OK, what next? I don't know, but probably an overview of built-in
                          > types and operations."
                          > First of all I would have covered all built in types in this chapter,
                          > second I would jump to LOOPS!
                          > Now the reader is Querious, keep him there by showing him some FUN
                          > stuff...
                          >
                          > (I remember the days of...)
                          > 10 CLS
                          > 20 PRINT "Thomas"
                          > 30 GOTO 20
                          >
                          > ...Those were the chapters making it worthwile to read books about
                          > programming....[/color]

                          You got your wish!

                          Well, not quite, I've decided to just give some interesting examples of
                          counter-based loops, continuing the counting theme, and then (if I have
                          time before the New Year), in what will become the fourth part, some
                          loop-based picture generation to illustrate use of libraries.

                          Many others (including myself in earlier writings) also seem to think
                          that going from variables to loops is a good idea -- perhaps because
                          it _is_?

                          [color=blue]
                          > And btw...
                          > Very good initiative!
                          > When I started C++ I searched the net for a good tutorial and basically
                          > all I found sucked!
                          > This made it MUCH harder for me to learn the language then it would
                          > have been if I had a good tutorial (or bought a good book... ;) )[/color]

                          Thanks.

                          Btw., the URL is now <url: http://home.no.net/dubjai/win32cpptut/html/>,
                          but right now when I'm writing this the server is down (very seldom
                          happens, but).

                          --
                          A: Because it messes up the order in which people normally read text.
                          Q: Why is it such a bad thing?
                          A: Top-posting.
                          Q: What is the most annoying thing on usenet and in e-mail?

                          Comment

                          • Buster

                            #14
                            Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

                            Alf P. Steinbach wrote:
                            [color=blue]
                            > I hope I haven't committed too many errors of my own ( ;-) ), and look
                            > forward to corrections -- just not "it's too long", every word counts.[/color]

                            One big error I noticed:
                            [color=blue]
                            > But consider
                            >
                            > x = 0;
                            > x = (x + 7) + (x = 5);[/color]

                            [...]
                            [color=blue]
                            > It’s not as bad as the undefined behavior, UB, we have encountered
                            > twice, where the program in theory could crash or hang or willy-nilly
                            > overwrite files on your harddisk, whatever. This is merely an
                            > unspecified result – the standard doesn’t say which of the two results
                            > – but it’s bad enough.[/color]

                            I'm afraid it is undefined behaviour, since x is modified twice without
                            an intervening sequence point. That's quite separate from your point
                            about unspecified order of evaluation.

                            Here's an example with an unspecified result but no undefined behaviour:

                            int f (int & x)
                            {
                            return x += 7;
                            }

                            int g (int & x)
                            {
                            return x = 5;
                            }

                            int x (0);
                            x = f (x) + g (x); // 12 or 17?

                            Sorry that's a little complicated but only the function-call sequence
                            point seems to be any use in constructing an example, since the others
                            are more tightly tied up with order of evaluation. Perhaps this would
                            be easier to explain:

                            int f (int x)
                            {
                            static int y = 1;
                            int result = x * y;
                            ++ y;
                            return result;
                            }

                            int x = f (10) + f (100); // 210 or 120?

                            --
                            Regards,
                            Buster

                            Comment

                            • Thomas Hansen

                              #15
                              Re: &quot;Variables &quot; tutorial available (Windows, mingw/msvc)

                              > Not much of programming gurus, then: it's the same in Java as in C++.

                              There was (off course) a bug in my sample...
                              I ment this:
                              for( int x=0; x < 10; ++x )
                              {
                              foo();//
                              }

                              The point here is that since people have read that the pre increment
                              operator increments its variable before the expression is evaluated
                              most people tend to believe that the above will work different then
                              this:
                              for( int x=0; x < 10; x++ )
                              and that the first one will increment the variable before the body of
                              the loop is executed for the first time...
                              In fact I did believe so too for my first year of C++ programming...
                              This is a point of confusion for many either newbies or people from
                              other camps then the C++ camp...
                              And I can truly understand why it feels natural to believe...

                              But you're true regarding that it's the same in Java, but I figure if
                              you ask people on this group too at least say 10-20 % would believe it
                              worked the way it doesn't work...

                              ..t

                              ..t

                              Comment

                              Working...