ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

FREE vs FIXED RPG

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • FREE vs FIXED RPG

    I'm a dinosaur and probably the only RPG programmer left that doesn't think /FREE RPG is easier to read. In the past few months I've been tasked to fix some code left over by a consultant. The code is half FREE and half FIXED in many places and very hard for me to read.

    One of the things I've done to help me with my task is get rid of the /FREE and get it back to FIXED. It's clean now.

    I'm guessing /FREE is great in the hands of a true artist where everything is indented clean, but still, it still looks like a mess to me. Way back in the day when I coded BASIC and everything I did was free format, I had the same issues

    Before I changed the FREE backed to fixed I tried aligning everything but what a hassle that was.

    I don't have a smart editor that will align my code. Everything is green screen for me and this leads to code everywhere.

    Here is an example of what I mean. I think the fixed format is cleaner and easier to read than the FREE version.

    Code:
    *********************************************************************
     *****            Get Last Month                                 *****
     *********************************************************************
                                                                          
    C     GetDate       BegSr                                             
     /Free                                                                
                            //Convert UDate to YMD & Subtract 1 Day       
                TodayDt = %Date(UDate) - %Days(1);                        
                PrvMth  = %Dec(TodayDt);                                  
     /End-Free                                                            
    C                   Move      PrvMth        LastMth                   
    C                   EndSr                                             
    
    Versus
    
     *-------------------------------------------------------------------------------------------
     *                Get Last Month                                                              
     *-------------------------------------------------------------------------------------------
    C     GetDate       BegSr                                                                     
    C                   eval      TodayDt = %Date(UDate) - %Days(1)                               
    C                   eval      PrvMth  = %Dec(TodayDt)                                         
    C                   Move      PrvMth        LastMth                                           
    C                   EndSr                                                                     
      * -------------------------------------------------------------------------------------------
    I'm fairly certain that I will probably jump languages or retire before I ever accept /FREE in my daily routine.

  • #2
    Re: FREE vs FIXED RPG

    Once you start using the chains without those klists and SQL
    you will never go back!!!!!!!!


    Code:
     //--------------------------------------------------------      
     // WRITTEN - Nov 99th 9999                                      
     // AUTHOR  - xxxxxxxxx xxxxxxxxxxxxxxxxx                        
     //                                                              
     // PROGRAM DESCRIPTION                                          
     //   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
     //--------------------------------------------------------      
                                                                     
      //                                                                               
      // Variable Definition                                                           
      //                                                                               
                                                                                       
    d LastMonth       s              6  0                                              
                                                                                       
     /Free                                                                             
                                                                                       
       //--------------------------------------------------------                      
       // MAIN PROGRAM                                                                 
       //--------------------------------------------------------                      
                                                                                       
            exsr  $getdate;                                                             
                                                                                       
            *inlr = *on;                                                               
       //--------------------------------------------------------                      
       // $getdate - get the yesterdays date                                           
       //--------------------------------------------------------                      
            begsr $getdate;                                                            
                                                                             
             // Not exactly sure what your trying to do without 
             // seeing your d specs but . . . . 
    
             LastMonth = %uns(%char(%date() - %days(1):*ymd0));                
                                                                             
            endsr;                                                           
                                                                             
     /End-Free
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: FREE vs FIXED RPG

      Jamie - You are so right. With /free format SQL now it's a beautiful thing. SQL saves you all sorts of coding and looping and breaking. Seeing what you are actually CHAINing with instead of hunting down the KLIST is also great.
      Your friends list is empty!

      Comment


      • #4
        Re: FREE vs FIXED RPG

        To a certain extent, I must agree with rpgKnight.
        In the early 80's, I loved COBOL, but hated the long names, (this_is_my_field_name_with_x_chars1), and also hated having to define the WS Section. mmm... come to think of it, maybe I actually hated COBOL. lol.

        What I loved about RPG is that is was fast to develop. Naturally, at the same time I also thought 6 chars too short. But the trend in RPG has moved a lot toward a programming style that it now looks a lot like COBOL.

        While free is pretty cool, if standards are not enforced, it can become a nightmare to read... but that can be said about just about any programming language if written by cowboys.
        Regards

        Kit
        http://www.ecofitonline.com
        DeskfIT - ChangefIT - XrefIT
        ___________________________________
        There are only 3 kinds of people -
        Those that can count and those that can't.

        Comment


        • #5
          Re: FREE vs FIXED RPG

          Hi,

          try to do the following Statements in fixed format:

          Code:
           /Free
                Chain (Key1: Key2: Key3: Key4) MyFileF FileDS;
                Update MyFileF %Fields(Fld1: Fld2: Fld17: Fld23);
                Eval-Corr(H) DS1 = DS2;
                XML-Into(E) MyOutDS 
                          %XML(’cpyA.xml’ : ’doc=file path=mydir/mysubdir1/mysubsubdir/';
           /End-Free
          Beginning with release V5R2 new enhancements are made for free format. If there are fixed format altivernatives (such as for Eval-Corr or XML-Into) it is not possible to use the full functionality in fixed format). Have a look at Eval-Corr(H), this cannot be specified in fixed format. Sure you can remove the (H)-Extender, but then your numeric fields are not half-adjusted and must be rounded manually.

          BTW standard must have also be enforced for classic RPG with short names. How otherwise to distinguish between workfields, parameter fields, fields from display files and printer files. How to know which file was updated, if the format name has nothing to do with the file name (I just recently saw: File XXXX, File YYYY both with the same format name!). You have to know what a 4 character abbreviation mean.

          Birgitta
          Last edited by B.Hauser; December 13, 2007, 01:44 AM.

          Comment


          • #6
            Re: FREE vs FIXED RPG

            IU am usually a promoter of everything free format within RPG, there is always an exception.

            As demonstrated in RPGKnights post..placing Free Format code in the middle of fixed format routines like this is @#%@#%@#%@#% ugly.

            If you need to add a couple of lines, why not keep to the same format as the program is written. Adding a new subroutine, or sub-procedure? fine do it in free format. Rewritting the whole program? also fine.
            But placing two or three lines of free format here there and everywhere within fixed format code, just makes it look a mess and actually turns others away from the free format code.
            You don't stop playing games because you get old, You get old because you stop playing games!

            Comment


            • #7
              Re: FREE vs FIXED RPG

              Another point to consider...
              if your site is running multiple boxes with differing OS versions, some programs using newer opcodes, bifs, etc. may not function.
              Regards

              Kit
              http://www.ecofitonline.com
              DeskfIT - ChangefIT - XrefIT
              ___________________________________
              There are only 3 kinds of people -
              Those that can count and those that can't.

              Comment


              • #8
                Re: FREE vs FIXED RPG

                I'm a dinosaur and probably the only RPG programmer left that doesn't think /FREE RPG is easier to read.
                You are not the only one. I know quite a number of RPG pgmrs who think fixed is easier to read. I also find it easier. Probably becuase I've been doing RPG more than 30 years, and its what I am used to.

                One of the things I've done to help me with my task is get rid of the /FREE and get it back to FIXED
                Despite what I just said, I would never got that far !

                And, as noted by others, there are some very good advantages. I often use it for UPDATE (with %fields option) and almost always with embedded SQL. The KList doesn't bother me much, I just click on the klist in the outline and I can see the definition.

                So I will prob get there someday, but since I do 80% maintenance, and everything is already fixed, I won't change fixed to all-free very soon.

                BTW - use a "smart" editor like lpex. It does automatic indentation for you, and free is easier to read when you have lots of IF levels.
                Also, the outline view finds where-is-that-field used question, so reduces the need for scanning the code looking for a field name.

                Comment


                • #9
                  Re: FREE vs FIXED RPG

                  Yes I have to go with everything that has been said.

                  I do alot of maintenance as well which is all fixed LE. But any new stuff I write is Free. I get frustrated sometimes when I bring code from one box to another only to find out the OS is older and now I have to undo some free code (like Klists).

                  Mixing free and fixed together is real messy. Either leave it fixed or make it 100% free. Personally I'd like to see more free format type (D specs, begin/end procedures).

                  Mine is all green screen but I am going to go looking for the lpex editor and try it. I do have WSDC and try it but I don't always have connectivity from my notebook to client's iSeries so I have to stick to green screen. (just learned that lpex IS the WSDC)

                  Maintaining/enhancing packaged software you have to stick to the same type of coding when possible. I juts can't go off and convert a program to free because on the next release it would be very messy.

                  30 years of working with RPG and I still get a kick out of the doing new things with new style code.
                  Last edited by Billw; December 13, 2007, 07:29 AM.
                  Bill
                  "A good friend will bail you out of jail,
                  A true friend would be sitting beside you saying,
                  'Wow, that was fun.'"

                  Comment


                  • #10
                    Re: FREE vs FIXED RPG

                    I'm a dinosaur and probably the only RPG programmer left that doesn't think /FREE RPG is easier to read.

                    You are not the only one. I know quite a number of RPG pgmrs who think fixed is easier to read. I also find it easier. Probably becuase I've been doing RPG more than 30 years, and its what I am used to.
                    IMO it's not that Free format is easier to read or Fixed Format is better, it's the fact that people look at Free Format code and decide that it's too different from the fixed format they are used to.

                    At times they have to look twice at free format code to work out what the code actually means compared to the Fixed Format altenative. But in my experience once they get used to it, Free Format is easily more readable than anything you can do in the fixed format of RPG
                    You don't stop playing games because you get old, You get old because you stop playing games!

                    Comment


                    • #11
                      Re: FREE vs FIXED RPG

                      My 2 cents;

                      I have only been involved in the 400 / ISeries ...... ( whatever) for 9 years. The single biggest thing that I have found about people involved with the platform is the unwillingness to learn and accept a new way of doing things. Why is that? All we do all day is make and change things but so many of us are unwilling to change. Hey this current gig is getting away from System/36 and the hard coding here is on an epic scale.

                      I love /free. But yes it can be just as uggly as fixed depending on the style of the numerious number of developers involved. Just start using it.
                      Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

                      Comment


                      • #12
                        Re: FREE vs FIXED RPG

                        I'm with you - /free is harder to get a handle on if you've been around RPG for a while (I started programming in RPG on the IBM 360/20). Back then everyone felt COBOL was the way to go, then PL1 was supposed to be the best thing.....now the majority of focus is back to RPG. I still remember the good old days when if you wanted output in RPG other than straight detail or total, you had to branch into total time (L0) and then back out! It was fun then! And only having 8k and then 16k storage to run the puppies in!

                        Comment


                        • #13
                          Re: FREE vs FIXED RPG

                          I'm in a place where I would love to program in /free. Most of my programs are brand new from scratch. But the other guys here are using fixed. Like you dinos the one here has been doing it this same way for eons. Coming from the C/C++ and now Java background I really would like to use /free. I just don't feel like getting yelled at when someone has to look at my code.

                          So I'm stuck in fixed. Boooooo
                          Your future President
                          Bryce

                          ---------------------------------------------
                          http://www.bravobryce.com

                          Comment


                          • #14
                            Re: FREE vs FIXED RPG

                            i coded using fixed format until like 2 years ago...i was determined to make the leap and i'm glad i did. at first yes there is a time to acclimate yourself to the "new" way of doing things...but it's well worth it. now when i see fixed-format i cringe! i don't necessarily use the 1000 byte long field names some use but i do use some longer names (i.e. custno becomes CustomerNumber) it IS more readable and easier for the person who will come behind you. but as far as the mixed fixed/free formats...yep it's ugly (that makes me cringe as well...) it's kinda like the military it's all or nothing...(no offense to any National Guards/Reserves...)
                            I'm not anti-social, I just don't like people -Tommy Holden

                            Comment


                            • #15
                              Re: FREE vs FIXED RPG

                              Bryce, I feel ya.

                              I would go with /free. If ya get grief from the fossils ask them where their horse and carriage is parked. If they say they don?t ask them why. The answer is the same reason to use /free and put the fixed at the same place the carriage and top hat manufactures are.

                              Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

                              Comment

                              Working...
                              X