Hello, world in GNU Cobol

The Lounge
2013-10-26
2013-11-04
  • Brian Tiffin

    Brian Tiffin - 2013-10-26

    Hello, everyone.

    What should be in a GNU Cobol helloworld.cob file?

    We have the simple DISPLAY "Hello, world" version.

    But, really, should it not be modeled on something like

    GNU    >>SOURCE FORMAT IS FIXED
    Cobol *> ***************************************************************
          *> Purpose:   Say hello to GNU Cobol
    Hello *> Tectonics: cobc -x hello.cob
    money *> ***************************************************************
           identification division.
           program-id. hello.
    
    DATA   data division.
           working-storage section.
           01 hello                pic $$$$,$$$,$$$,$$$,$$$,$$$.99.
           01 world                pic s9(18)v99 value zero.
    
           01 people               pic Z,ZZZ,ZZZ,ZZ9.
           01 persons              pic 9(10) value 7182044470.
    
           01 each                 pic 9(5)v99 value 26202.42.
    
          *> ***************************************************************
    CODE   procedure division.
    
           multiply persons by each giving world
               on size error
                 display "We did it.  We broke the world bank" end-display
           end-multiply
    
           move world to hello
           move persons to people
    
           display "Hello, world" end-display
           display " " end-display
           display
               "On September 27th, 2013, according to UN estimates:" 
           end-display
           display "You were home to some " people  " people," end-display
           display " with an estimated worth of " hello end-display
    
           goback.
           end program hello.
    

    giving

    Hello, world
    
    On September 27th, 2013, according to UN estimates:
    You were home to some 7,182,044,470 people,
     with an estimated worth of     $188,186,945,661,617.40
    

    Or is that overly complicated for Hello?

    Any suggestions on simplification, while still pointing out that COBOL is designed to count the world's pennies?

    Cheers,
    Brian

     
    Last edit: Brian Tiffin 2013-10-27
  • Luke Smith

    Luke Smith - 2013-10-28

    Me thinks it's a bit too much for HelloWorld. Maybe call it BigWorld so that it and the simple HelloWorld can be put in samples at the same time?

     
  • Brian Tiffin

    Brian Tiffin - 2013-10-28

    Yeah, I agree Luke. And someone on LinkedIn called it wrong, the population estimate needing to be to the second precision, which I didn't mark.

    Cheers,
    Brian

     
    • Simon Sobisch

      Simon Sobisch - 2013-10-28

      So I guess you upload both in contrib/samples/HelloWorld ?
      Simon

       
      • Brian Tiffin

        Brian Tiffin - 2013-11-04

        Done

        Cheers,
        Brian

         

Log in to post a comment.