hello world

This is a discussion on hello world within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I always see something like this:: Code: // wrong, but it works! #include <iostream> int main() { std::cout<<"Hello, World!\n"; return ...

  1. #1
    Unregistered
    Guest

    hello world

    I always see something like this::
    Code:
    // wrong, but it works!
    #include <iostream>
    
    int main()
    {
      std::cout<<"Hello, World!\n";
      return 0;
    }
    Just for the record C++ is an Object Oriented Programming Language
    So why teach in a non-object oriented manner?

    Code:
    //this is more acceptable
    #include <iostream>
    
    
    class cProgram{
        public:
            cProgram(){ std::cout << "Hello, World!\n"; }
            ~cProgram(){ std::cout << "Good bye, World!\n"; }
    }
    
    cProgram myApp;
    
    int main()
    {
         return 0;
    }
    Its not much more complex than the first example.
    And well worth learning.

    Lets see some fance hello_world.cpp code.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Because for an absolute beginner who doesn't even know what "#include" does/means so why dump learning classes on them from right from the start?

  3. #3
    Unregistered
    Guest
    Why shouldn't you teach classes from the start?

    What book doesn't explain "hello world" line by line.
    cProgram could simpley be introduced, as a user defined type
    After all isn't that what it is?

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Read my post again. If you're dealing with a newbie who barely knows what a compiler on do you really think you should dump classes on them from the start? I love classes. I'd hate to write without them, but back when I didn't know the difference between an int and the function that was returning it, I'd have been completely lost if I tried to learn classes then. How can a person learn classes if they can't even define the variables and functions that would make up said classes? You have to crawl before you can walk.

  5. #5
    Unregistered
    Guest
    The point Iím trying to make is that the power of classes should be taken advantage of, from the start of ones venture into programming. As powerful as classes are, they should be included in every application in which their abilities can do task for the programmer.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    .. but isn't the first example code using classes anyway? Isn't std::cout part of a class? Why embed it in more unneccasry code?

    I dunno!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    Why??Because it is flat out ugly. C++ is not a pure object lang and thank good for that. And Hammer is right. You get all power of objects using cout anyway. The code you posted don't compile on my computer.
    Last edited by Barjor; 05-09-2002 at 01:31 PM.

  8. #8
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Code:
    //this is more acceptable
    #include <iostream>
    
    
    class cProgram{
        public:
            cProgram(){ std::cout << "Hello, World!\n"; }
            ~cProgram(){ std::cout << "Good bye, World!\n"; }
    }
    
    cProgram myApp;
    
    int main()
    {
         return 0;
    }
    And besides that... since you are not instantiating your object in main as a local variable, you would be wrong to teach that example anyway...

    A lot can be done without using classes... and yes.... you use objects anyway when you #include libs... one idea of objects is that you can utilize code that has already been written instead or rewriting it all yourself; though that isn't really true object oriented programming as C has always had that capability....
    Blue

  9. #9
    Unregistered
    Guest
    >>If you're dealing with a newbie who barely knows what a compiler on do you really think you should dump classes on them from the start? <<
    the answer is YES.
    Classes aare the VERY same thing as int, char, double, and even unsigned int.

    After all its a Hello World app. Your knowledge of programming is just starting.

    A perfect example is my nephew (he is 3) and counts to 50, knows all of his abc's and can almost tie his own shoes.

    Carry on a conversation very well, and understand most of what he is told.

    He learns this by being exposed to it.
    Not by having to wait.
    If you are getting started DONíT be lazy! Learn what you have to learn.
    Classes are Easy.


    They are simpley different types of data which one can use with others to arrange into more understandable formats.

    They NEED to be included into any helloworld.cpp.

  10. #10
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    why make hello world in a class just because c++ is more object oriented than c? use java for that.

  11. #11
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    Originally posted by Unregistered
    >>
    They NEED to be included into any helloworld.cpp.
    No that would be to miss use classes. If you want an all object lang use Java or C#.

  12. #12
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Re: hello world

    Originally posted by Unregistered
    I always see something like this::
    Code:
    // wrong, but it works!
    #include <iostream>
    
    int main()
    {
      std::cout<<"Hello, World!\n";
      return 0;
    }
    Just for the record C++ is an Object Oriented Programming Language
    So why teach in a non-object oriented manner?

    Code:
    //this is more acceptable
    #include <iostream>
    
    
    class cProgram{
        public:
            cProgram(){ std::cout << "Hello, World!\n"; }
            ~cProgram(){ std::cout << "Good bye, World!\n"; }
    }
    
    cProgram myApp;
    
    int main()
    {
         return 0;
    }
    Its not much more complex than the first example.
    And well worth learning.

    Lets see some fance hello_world.cpp code.

    Oh the irony this program doesn't even compile. just looking at the irony that's all.
    Last edited by incognito; 05-09-2002 at 02:35 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  13. #13
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    From one of the rational software books or something?

    // wrong, but it works!
    #include <iostream>

    int main()
    {
    std::cout<<"Hello, World!\n";
    return 0;
    }

    Even in this program your using objects. Your passing "Hello, World!\n" To global object std::cout opererator<<. Since you already have a class and object which abstracts the process of printing stuft on the screen, it's worthless creating one which just prints hello.

  14. #14
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    hey elchulo2002
    Do you like the "Direct X 7 in 24h" Book? I been looking at it but never got around to buy it. DO you have anything to recomend for Open GL?

  15. #15
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Originally posted by Barjor
    hey elchulo2002
    Do you like the "Direct X 7 in 24h" Book? I been looking at it but never got around to buy it. DO you have anything to recomend for Open GL?
    check for rather lenghty response on your pm.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The 7 New Wonders of the World
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 12-08-2006, 01:55 PM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  3. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 01:51 PM
  4. Too much to ask ?
    By deflamol in forum C Programming
    Replies: 2
    Last Post: 05-06-2004, 05:30 PM
  5. No More Technology After World War Three
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-20-2001, 08:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21