SlideShare a Scribd company logo
1 of 4
Subject: Programming Guidelines
Author: Ramesh Joshi
Purpose
The purpose of this document is to record the guidelines I use for programming. The guidelines are a result of the advice
and suggestions given to me by my programming Gurus, best practices recommended by the authors of various
programming books that I have read since 1980 when I was studying for the Diploma in Computer Management, and my
own experience in the IT field since 1982.
I do most of the programming in RPG and COBOL, so the guidelines are for these two languages. I recommend these
guidelines to my students when I teach them RPG and COBOL.
Guidelines
1. Write the code for humans first: Nowadays, the cost of machine time is a lot less than the cost of programmer time.
Studies have shown that on an average, a program in a Business Application is modified by nine programmers other
than the original author, before the program becomes obsolete or is re-written. Therefore, the program should be
made as simple to understand as possible. Studies have also shown that for majority of the modifications, it takes
more time for a programmer not familiar with that program to understand the existing code than it takes to modify
it after the code has been understood. Many of the subsequent guidelines are based on this principle – Write the
code for humans first.
2. Write one subroutine per file per IO operation: A typical Business Application program contains IO operations, for
example, in RPG, op-codes READ, READP, WRITE, UPDATE, CHAIN, SETLL etc. For each file used in the program, code
only one subroutine for each type of IO. For example, for a direct access to a record, code the CHAIN instruction only
once in the program in a subroutine named GetFilename, where the Filename part of the subroutine name should
be the actual file name. For example, if the file name is STUDENTS, the subroutine names should be GetSTUDENTS
(Chain), PosToSTUDENTS (SETLL / SETGT), WrtSTUDENTS, and UpdSTUDENTS. READ is a bit different, and has been
explained later.
3. Have only one Entry Point and one Exit Point: The program should have a single entry point and a single exit point.
Each subroutine in the program also should have a single entry point and a single exit point. Never jump to any
instruction that is outside the subroutine.
4. Avoid GOTO: The only acceptable GOTO in an RPG program is to its own ENDSR and that too, only if LEAVESR is not
supported by the compiler. In COBOL, to its “EXIT” para. (See COBOL programming standards for the information
about “EXIT” para.)
5. Write structured, top-down code: A typical Business Application program contains many files and corresponding IO
operations. The IO operations are “routine stuff” if you have followed the guidelines for IO subroutines. You can
(and should) create an IO routine for a file by copying corresponding routine already written for another file, and
then make file name / field name changes. Place all the IO routines in a program at the bottom of the program. In
the main code, “Exsr GetSTUDENTS” is enough for another programmer (even if he / she is not familiar with the IO
routine guidelines mentioned above) to understand that a record from the STUDENTS file would be made available
to the program by that subroutine. As a thumb rule, reading the top 25% of the C-specs (Procedure Division in
COBOL) should clarify 75% of the program’s functionality to a programmer who is not familiar with the program.
6. Use meaningful names: Try to make the variable names and the subroutine names as meaningful as possible. Use
mixed case, which is easier to read for most human beings. For example, use ValidateDate instead of VLDDAT;
FoundStudent instead of indicator 99. Minimize the use of indicators 1-99.
7. Use Prefix keyword in RPG: When using files in RPG, use a distinct prefix for each database file. For input-only files,
use prefixes F1, F2, and so on. For files used in other modes, use prefixes FZ, FY, FX, and so on. You may have to
write extra code when you do this (Eval, Move etc.) when you want to move the value in the file’s field to
somewhere else, but it will save time of the maintenance programmer. I personally know the havoc caused by the
“automatic population of multiple fields having the same name” in an organization.
8. Write small subroutines: A subroutine should ideally fit on a single screen, that is, it should ideally be <= 30 lines.
Studies have shown that it is easier for programmers to understand a piece of code if the entire code is in front of
their eyes. Avoid coding conditional statements where the IF is in the heaven, the ELSE is on the earth, and the
ENDIF is in the hell. If a subroutine is exceeding two screenfuls, it generally contains multiple functions, which should
be placed in separate subroutines and merely executed from the current subroutine.
9. Avoid using “and” and “or” together in a single condition: Combining “and” and “or” in a single condition makes
the code difficult to understand. The compiler may not interpret it the way you are thinking. So, split the condition.
It is better to write some additional code now than to make the maintenance programmer look up the manual when
an issue is reported by an end user when the application is Live.
10. Write comments and include examples to explain complex code: The original programmer generally has the benefit
of documentation (program specs, or functional specs, or emails etc.) and personal discussions with the Business
Representative, which help him / her to understand the functionality. The maintenance programmers generally do
not have that advantage. They have to rely on the code itself. Including comments and examples in the source code
can go a long way in improving the readability of the program.
11. Copy input parameters to program’s own variables: When the parameters are being passed by reference, copy the
input parameters to the program’s own variables to avoid the risk of accidentally changing their values.
12. Initialize return parameters: Initialize the return parameters before passing them to a called program.
13. Write four / five subroutines for reading records from a file: Many times, a program in a Business Application needs
to read records from a file, select some records, and then process selected records. The actual processing of a
selected record is the primary function of the program – reading the file and skipping unwanted records is
incidental.
Many times, a program may be processing some range. For example, a program may print reminders to be mailed to
customers who owe more than $1000. And for the sake of convenience of mailing, the accounts department may
print the letters for customers with names in the range A to I in the first week, J to R in the second week, and S to Z
in the third week. The program for printing the letters may be using a file keyed on Customer Name. So, in the first
week, the program should, ideally, stop processing after it encounters the first customer record starting with J –
should not just keep reading and skipping records beyond I. Similarly, in the second week, it should directly start
processing the records from J – should not read and skip records from A to I.
Let me explain the recommended five subroutines with an example. The fifth one is optional – to be used if the file is
not to be processed from the beginning, that is, when positioning within the file is required using, for example,
SETLL, SETGT in RPG or START in COBOL. The following code snippets should make the concept clear. (The
subroutine that checks logical end of file is empty in the code snippet. In the AR letters example mentioned above, it
would contain the code to set the EndOfFile variable to “Y” if the Customer Name read from the file is greater than
the To Customer Name accepted from the screen.)
*=================================================================*
* Files
*-----------------------------------------------------------------*
FSTUDENTSL2IF E K DISK PREFIX(F1)
F RENAME(STUDENTS:F1FMT) .
.
.
*=================================================================*
* Switches
*-----------------------------------------------------------------*
D ValidF1 S 1A
D F1End S 1A
.
*=================================================================*
* Build Work File (F2/FZ)
*-----------------------------------------------------------------*
C BuildTmpFile BEGSR
C EVAL RexWritten = *Zero
C EXSR ReadF1
C DOW RexWritten < RexToBeWritten and
C F1End = 'N'
C EXSR BuildFZ
C EVAL RexWritten = RexWritten + 1
C EXSR ReadF1
C ENDDO
*
* Records to be written will normally be equal to the
* number of rows on the screen, that is, MaxScrLines.
*
* However, when building the Work File (F2/FZ) for the first
* time, an extra record needs to be written. The routine
* 'ProcPosTo' takes care of this by setting :
*
* (RexToBeWritten = MaxScrLines + 1)
*
* Also, when processing "Repeat Option", all records in F1 are
* to be written to the Work File. The routine 'ProcRepeat'
* takes care of this by setting :
*
* (RexToBeWritten = *All'9')
*
* The following code sets RexToBeWritten for future additions
* to Work File.
*
C EVAL RexToBeWritten = MaxScrLines
C ENDSR
*=================================================================*
.
*=================================================================*
* Build Work File when Refresh required
*-----------------------------------------------------------------*
C RebldTmpFile BEGSR
C EXSR PosF1Refresh
C EVAL F1End = 'N'
C EVAL *In91 = *Off
C EXSR ReadF1
C DOW F1End = 'N'
C EXSR BuildFZ
C EXSR StoreRecNo
C EXSR ReadF1
C EXSR SetTmpKeyFrF1
C IF TmpKey > PrvLstKey
C LEAVE
C ENDIF
C ENDDO
C ENDSR
*=================================================================*
.
.
.
*=================================================================*
*
*-----------------------------------------------------------------*
C ReadF1 BEGSR
C EVAL ValidF1 = 'N'
C DOW ValidF1 <> 'Y'
C EXSR ReadF11
C ENDDO
C ENDSR
*=================================================================*
*
*-----------------------------------------------------------------*
C ReadF11 BEGSR
C EVAL ValidF1 = 'Y'
C READ F1FMT 91
C IF *In91 = *On
C EVAL F1End = 'Y'
C GOTO ReadF11X
C ENDIF
C EXSR CheckEOF1
C IF F1End = 'Y'
C GOTO ReadF11X
C ENDIF
C EXSR SelectF1
C ReadF11X ENDSR
*=================================================================*
* Check Logical End Of File
*-----------------------------------------------------------------*
C CheckEOF1 BEGSR
C CheckEOF1X ENDSR
*=================================================================*
*
*-----------------------------------------------------------------*
C SelectF1 BEGSR
C IF F1NUMBER < FRNUMBER or
C F1NUMBER > TONUMBER
C EVAL ValidF1 = 'N'
C GOTO SelectF1X
C ENDIF
C IF F1NAME < FRNAME or
C F1NAME > TONAME
C EVAL ValidF1 = 'N'
C GOTO SelectF1X
C ENDIF
C SelectF1X ENDSR
*=================================================================*
* Position File F1 for Refresh
*-----------------------------------------------------------------*
C PosF1Refresh BEGSR
C EVAL TmpKey = Prv1stKey
C EVAL F1NAME = TmpNAME
C EVAL F1NUMBER = TmpNUMBER
C F1Key SETLL F1FMT
C ENDSR
*=================================================================*
3
4
2
1
5

More Related Content

What's hot

computer languages
computer languagescomputer languages
computer languagesYasirali328
 
Ict - Programming
Ict - ProgrammingIct - Programming
Ict - Programmingaleeya91
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1Anil Polsani
 
Programming Languages An Intro
Programming Languages An IntroProgramming Languages An Intro
Programming Languages An IntroKimberly De Guzman
 
Standard java coding convention
Standard java coding conventionStandard java coding convention
Standard java coding conventionTam Thanh
 
Coding vs programming
Coding vs programmingCoding vs programming
Coding vs programmingAman Kumar
 
Chapter One
Chapter OneChapter One
Chapter Onebolovv
 
Compiler Design(Nanthu)
Compiler Design(Nanthu)Compiler Design(Nanthu)
Compiler Design(Nanthu)guest91cc85
 
Coding standards
Coding standardsCoding standards
Coding standardsMimoh Ojha
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and developmentAli Raza
 
An introduction to programming
An introduction to programmingAn introduction to programming
An introduction to programmingrprajat007
 
Language processor
Language processorLanguage processor
Language processorAbha Damani
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programmingThang Mai
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introductionRana Ehtisham Ul Haq
 

What's hot (20)

computer languages
computer languagescomputer languages
computer languages
 
Ict - Programming
Ict - ProgrammingIct - Programming
Ict - Programming
 
Cobol training class-1
Cobol training class-1Cobol training class-1
Cobol training class-1
 
Abcxyz
AbcxyzAbcxyz
Abcxyz
 
Programming Languages An Intro
Programming Languages An IntroProgramming Languages An Intro
Programming Languages An Intro
 
Standard java coding convention
Standard java coding conventionStandard java coding convention
Standard java coding convention
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
JAVA
JAVAJAVA
JAVA
 
Coding vs programming
Coding vs programmingCoding vs programming
Coding vs programming
 
Am4201257261
Am4201257261Am4201257261
Am4201257261
 
Chapter One
Chapter OneChapter One
Chapter One
 
Compiler Design(Nanthu)
Compiler Design(Nanthu)Compiler Design(Nanthu)
Compiler Design(Nanthu)
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Java
JavaJava
Java
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and development
 
An introduction to programming
An introduction to programmingAn introduction to programming
An introduction to programming
 
Presentation compiler design
Presentation compiler designPresentation compiler design
Presentation compiler design
 
Language processor
Language processorLanguage processor
Language processor
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 

Viewers also liked

Medida cautelar de la justicia hacia Claro por la denuncia de protectora
Medida cautelar de la justicia hacia Claro por la denuncia de protectoraMedida cautelar de la justicia hacia Claro por la denuncia de protectora
Medida cautelar de la justicia hacia Claro por la denuncia de protectoraMely Villarroel
 
Recruiting for profitability
Recruiting for profitabilityRecruiting for profitability
Recruiting for profitabilityMark Loscher
 
PARITARIA: Ultima propuesta del gobierno al SUTE
PARITARIA: Ultima propuesta del gobierno al SUTEPARITARIA: Ultima propuesta del gobierno al SUTE
PARITARIA: Ultima propuesta del gobierno al SUTEMely Villarroel
 
Proyecto Jorge Palero Fundavita
Proyecto Jorge Palero FundavitaProyecto Jorge Palero Fundavita
Proyecto Jorge Palero FundavitaMely Villarroel
 
Convenio Mercado de la terminal
Convenio Mercado de la terminal Convenio Mercado de la terminal
Convenio Mercado de la terminal Mely Villarroel
 
Discurso de Sturzenegger en la asociación de marketing bancario argentino
Discurso de Sturzenegger en la asociación de marketing bancario argentinoDiscurso de Sturzenegger en la asociación de marketing bancario argentino
Discurso de Sturzenegger en la asociación de marketing bancario argentinoGabriel Conte
 
Presentación de la Agenda Ciudadana por la Transparencia - Cali
Presentación de la Agenda Ciudadana por la Transparencia - CaliPresentación de la Agenda Ciudadana por la Transparencia - Cali
Presentación de la Agenda Ciudadana por la Transparencia - CaliTransparenciaporColombia
 
Nuevo DISC Index por Innermetrix
Nuevo DISC Index por InnermetrixNuevo DISC Index por Innermetrix
Nuevo DISC Index por Innermetrixorodney
 

Viewers also liked (9)

Medida cautelar de la justicia hacia Claro por la denuncia de protectora
Medida cautelar de la justicia hacia Claro por la denuncia de protectoraMedida cautelar de la justicia hacia Claro por la denuncia de protectora
Medida cautelar de la justicia hacia Claro por la denuncia de protectora
 
Recruiting for profitability
Recruiting for profitabilityRecruiting for profitability
Recruiting for profitability
 
PARITARIA: Ultima propuesta del gobierno al SUTE
PARITARIA: Ultima propuesta del gobierno al SUTEPARITARIA: Ultima propuesta del gobierno al SUTE
PARITARIA: Ultima propuesta del gobierno al SUTE
 
Proyecto Jorge Palero Fundavita
Proyecto Jorge Palero FundavitaProyecto Jorge Palero Fundavita
Proyecto Jorge Palero Fundavita
 
Convenio Mercado de la terminal
Convenio Mercado de la terminal Convenio Mercado de la terminal
Convenio Mercado de la terminal
 
Discurso de Sturzenegger en la asociación de marketing bancario argentino
Discurso de Sturzenegger en la asociación de marketing bancario argentinoDiscurso de Sturzenegger en la asociación de marketing bancario argentino
Discurso de Sturzenegger en la asociación de marketing bancario argentino
 
Presentación de la Agenda Ciudadana por la Transparencia - Cali
Presentación de la Agenda Ciudadana por la Transparencia - CaliPresentación de la Agenda Ciudadana por la Transparencia - Cali
Presentación de la Agenda Ciudadana por la Transparencia - Cali
 
OGSM Conciudadania
OGSM Conciudadania OGSM Conciudadania
OGSM Conciudadania
 
Nuevo DISC Index por Innermetrix
Nuevo DISC Index por InnermetrixNuevo DISC Index por Innermetrix
Nuevo DISC Index por Innermetrix
 

Similar to Programming Guidelines

Fundamentalsofprogrammingfinal 121011003536-phpapp02
Fundamentalsofprogrammingfinal 121011003536-phpapp02Fundamentalsofprogrammingfinal 121011003536-phpapp02
Fundamentalsofprogrammingfinal 121011003536-phpapp02thinesonsing
 
Fundamentals of programming final
Fundamentals of programming finalFundamentals of programming final
Fundamentals of programming finalRicky Recto
 
Mark asoi ppt
Mark asoi pptMark asoi ppt
Mark asoi pptmark-asoi
 
Margareth lota
Margareth lotaMargareth lota
Margareth lotamaggybells
 
Cs121 Unit Test
Cs121 Unit TestCs121 Unit Test
Cs121 Unit TestJill Bell
 
PCCF UNIT 2.pptx
PCCF UNIT 2.pptxPCCF UNIT 2.pptx
PCCF UNIT 2.pptxDivyaKS12
 
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshuunit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshuGauravRawat830030
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143alish sha
 
Fundamentals of programming final santos
Fundamentals of programming final santosFundamentals of programming final santos
Fundamentals of programming final santosAbie Santos
 
(D 15 180770107240)
(D 15 180770107240)(D 15 180770107240)
(D 15 180770107240)RaviModi37
 
Programming style guideline very good
Programming style guideline very goodProgramming style guideline very good
Programming style guideline very goodDang Hop
 
Signature AssignmentGrading GuideOPS571 Version 83S.docx
Signature AssignmentGrading GuideOPS571 Version 83S.docxSignature AssignmentGrading GuideOPS571 Version 83S.docx
Signature AssignmentGrading GuideOPS571 Version 83S.docxmaoanderton
 
Building of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingBuilding of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingPVS-Studio
 
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptxChapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptxrajinevitable05
 
PRG/420 ENTIRE CLASS UOP TUTORIALS
PRG/420 ENTIRE CLASS UOP TUTORIALSPRG/420 ENTIRE CLASS UOP TUTORIALS
PRG/420 ENTIRE CLASS UOP TUTORIALSSharon Reynolds
 
PCCF-UNIT 2-1 new.docx
PCCF-UNIT 2-1 new.docxPCCF-UNIT 2-1 new.docx
PCCF-UNIT 2-1 new.docxprakashvs7
 
PCCF UNIT 2 CLASS.pptx
PCCF UNIT 2 CLASS.pptxPCCF UNIT 2 CLASS.pptx
PCCF UNIT 2 CLASS.pptxvishnupriyapm4
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lineslokeshG38
 

Similar to Programming Guidelines (20)

Fundamentalsofprogrammingfinal 121011003536-phpapp02
Fundamentalsofprogrammingfinal 121011003536-phpapp02Fundamentalsofprogrammingfinal 121011003536-phpapp02
Fundamentalsofprogrammingfinal 121011003536-phpapp02
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Fundamentals of programming final
Fundamentals of programming finalFundamentals of programming final
Fundamentals of programming final
 
Mark asoi ppt
Mark asoi pptMark asoi ppt
Mark asoi ppt
 
Margareth lota
Margareth lotaMargareth lota
Margareth lota
 
Cs121 Unit Test
Cs121 Unit TestCs121 Unit Test
Cs121 Unit Test
 
PCCF UNIT 2.pptx
PCCF UNIT 2.pptxPCCF UNIT 2.pptx
PCCF UNIT 2.pptx
 
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshuunit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
 
Chap 2 structure of c programming dti2143
Chap 2  structure of c programming dti2143Chap 2  structure of c programming dti2143
Chap 2 structure of c programming dti2143
 
Fundamentals of programming final santos
Fundamentals of programming final santosFundamentals of programming final santos
Fundamentals of programming final santos
 
(D 15 180770107240)
(D 15 180770107240)(D 15 180770107240)
(D 15 180770107240)
 
Programming style guideline very good
Programming style guideline very goodProgramming style guideline very good
Programming style guideline very good
 
Signature AssignmentGrading GuideOPS571 Version 83S.docx
Signature AssignmentGrading GuideOPS571 Version 83S.docxSignature AssignmentGrading GuideOPS571 Version 83S.docx
Signature AssignmentGrading GuideOPS571 Version 83S.docx
 
Building of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingBuilding of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code logging
 
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptxChapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
 
PRG/420 ENTIRE CLASS UOP TUTORIALS
PRG/420 ENTIRE CLASS UOP TUTORIALSPRG/420 ENTIRE CLASS UOP TUTORIALS
PRG/420 ENTIRE CLASS UOP TUTORIALS
 
C++ publish copy
C++ publish   copyC++ publish   copy
C++ publish copy
 
PCCF-UNIT 2-1 new.docx
PCCF-UNIT 2-1 new.docxPCCF-UNIT 2-1 new.docx
PCCF-UNIT 2-1 new.docx
 
PCCF UNIT 2 CLASS.pptx
PCCF UNIT 2 CLASS.pptxPCCF UNIT 2 CLASS.pptx
PCCF UNIT 2 CLASS.pptx
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
 

Recently uploaded

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Recently uploaded (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Programming Guidelines

  • 1. Subject: Programming Guidelines Author: Ramesh Joshi Purpose The purpose of this document is to record the guidelines I use for programming. The guidelines are a result of the advice and suggestions given to me by my programming Gurus, best practices recommended by the authors of various programming books that I have read since 1980 when I was studying for the Diploma in Computer Management, and my own experience in the IT field since 1982. I do most of the programming in RPG and COBOL, so the guidelines are for these two languages. I recommend these guidelines to my students when I teach them RPG and COBOL. Guidelines 1. Write the code for humans first: Nowadays, the cost of machine time is a lot less than the cost of programmer time. Studies have shown that on an average, a program in a Business Application is modified by nine programmers other than the original author, before the program becomes obsolete or is re-written. Therefore, the program should be made as simple to understand as possible. Studies have also shown that for majority of the modifications, it takes more time for a programmer not familiar with that program to understand the existing code than it takes to modify it after the code has been understood. Many of the subsequent guidelines are based on this principle – Write the code for humans first. 2. Write one subroutine per file per IO operation: A typical Business Application program contains IO operations, for example, in RPG, op-codes READ, READP, WRITE, UPDATE, CHAIN, SETLL etc. For each file used in the program, code only one subroutine for each type of IO. For example, for a direct access to a record, code the CHAIN instruction only once in the program in a subroutine named GetFilename, where the Filename part of the subroutine name should be the actual file name. For example, if the file name is STUDENTS, the subroutine names should be GetSTUDENTS (Chain), PosToSTUDENTS (SETLL / SETGT), WrtSTUDENTS, and UpdSTUDENTS. READ is a bit different, and has been explained later. 3. Have only one Entry Point and one Exit Point: The program should have a single entry point and a single exit point. Each subroutine in the program also should have a single entry point and a single exit point. Never jump to any instruction that is outside the subroutine. 4. Avoid GOTO: The only acceptable GOTO in an RPG program is to its own ENDSR and that too, only if LEAVESR is not supported by the compiler. In COBOL, to its “EXIT” para. (See COBOL programming standards for the information about “EXIT” para.) 5. Write structured, top-down code: A typical Business Application program contains many files and corresponding IO operations. The IO operations are “routine stuff” if you have followed the guidelines for IO subroutines. You can (and should) create an IO routine for a file by copying corresponding routine already written for another file, and then make file name / field name changes. Place all the IO routines in a program at the bottom of the program. In the main code, “Exsr GetSTUDENTS” is enough for another programmer (even if he / she is not familiar with the IO routine guidelines mentioned above) to understand that a record from the STUDENTS file would be made available to the program by that subroutine. As a thumb rule, reading the top 25% of the C-specs (Procedure Division in COBOL) should clarify 75% of the program’s functionality to a programmer who is not familiar with the program. 6. Use meaningful names: Try to make the variable names and the subroutine names as meaningful as possible. Use mixed case, which is easier to read for most human beings. For example, use ValidateDate instead of VLDDAT; FoundStudent instead of indicator 99. Minimize the use of indicators 1-99.
  • 2. 7. Use Prefix keyword in RPG: When using files in RPG, use a distinct prefix for each database file. For input-only files, use prefixes F1, F2, and so on. For files used in other modes, use prefixes FZ, FY, FX, and so on. You may have to write extra code when you do this (Eval, Move etc.) when you want to move the value in the file’s field to somewhere else, but it will save time of the maintenance programmer. I personally know the havoc caused by the “automatic population of multiple fields having the same name” in an organization. 8. Write small subroutines: A subroutine should ideally fit on a single screen, that is, it should ideally be <= 30 lines. Studies have shown that it is easier for programmers to understand a piece of code if the entire code is in front of their eyes. Avoid coding conditional statements where the IF is in the heaven, the ELSE is on the earth, and the ENDIF is in the hell. If a subroutine is exceeding two screenfuls, it generally contains multiple functions, which should be placed in separate subroutines and merely executed from the current subroutine. 9. Avoid using “and” and “or” together in a single condition: Combining “and” and “or” in a single condition makes the code difficult to understand. The compiler may not interpret it the way you are thinking. So, split the condition. It is better to write some additional code now than to make the maintenance programmer look up the manual when an issue is reported by an end user when the application is Live. 10. Write comments and include examples to explain complex code: The original programmer generally has the benefit of documentation (program specs, or functional specs, or emails etc.) and personal discussions with the Business Representative, which help him / her to understand the functionality. The maintenance programmers generally do not have that advantage. They have to rely on the code itself. Including comments and examples in the source code can go a long way in improving the readability of the program. 11. Copy input parameters to program’s own variables: When the parameters are being passed by reference, copy the input parameters to the program’s own variables to avoid the risk of accidentally changing their values. 12. Initialize return parameters: Initialize the return parameters before passing them to a called program. 13. Write four / five subroutines for reading records from a file: Many times, a program in a Business Application needs to read records from a file, select some records, and then process selected records. The actual processing of a selected record is the primary function of the program – reading the file and skipping unwanted records is incidental. Many times, a program may be processing some range. For example, a program may print reminders to be mailed to customers who owe more than $1000. And for the sake of convenience of mailing, the accounts department may print the letters for customers with names in the range A to I in the first week, J to R in the second week, and S to Z in the third week. The program for printing the letters may be using a file keyed on Customer Name. So, in the first week, the program should, ideally, stop processing after it encounters the first customer record starting with J – should not just keep reading and skipping records beyond I. Similarly, in the second week, it should directly start processing the records from J – should not read and skip records from A to I. Let me explain the recommended five subroutines with an example. The fifth one is optional – to be used if the file is not to be processed from the beginning, that is, when positioning within the file is required using, for example, SETLL, SETGT in RPG or START in COBOL. The following code snippets should make the concept clear. (The subroutine that checks logical end of file is empty in the code snippet. In the AR letters example mentioned above, it would contain the code to set the EndOfFile variable to “Y” if the Customer Name read from the file is greater than the To Customer Name accepted from the screen.) *=================================================================* * Files *-----------------------------------------------------------------* FSTUDENTSL2IF E K DISK PREFIX(F1) F RENAME(STUDENTS:F1FMT) . . . *=================================================================*
  • 3. * Switches *-----------------------------------------------------------------* D ValidF1 S 1A D F1End S 1A . *=================================================================* * Build Work File (F2/FZ) *-----------------------------------------------------------------* C BuildTmpFile BEGSR C EVAL RexWritten = *Zero C EXSR ReadF1 C DOW RexWritten < RexToBeWritten and C F1End = 'N' C EXSR BuildFZ C EVAL RexWritten = RexWritten + 1 C EXSR ReadF1 C ENDDO * * Records to be written will normally be equal to the * number of rows on the screen, that is, MaxScrLines. * * However, when building the Work File (F2/FZ) for the first * time, an extra record needs to be written. The routine * 'ProcPosTo' takes care of this by setting : * * (RexToBeWritten = MaxScrLines + 1) * * Also, when processing "Repeat Option", all records in F1 are * to be written to the Work File. The routine 'ProcRepeat' * takes care of this by setting : * * (RexToBeWritten = *All'9') * * The following code sets RexToBeWritten for future additions * to Work File. * C EVAL RexToBeWritten = MaxScrLines C ENDSR *=================================================================* . *=================================================================* * Build Work File when Refresh required *-----------------------------------------------------------------* C RebldTmpFile BEGSR C EXSR PosF1Refresh C EVAL F1End = 'N' C EVAL *In91 = *Off C EXSR ReadF1 C DOW F1End = 'N' C EXSR BuildFZ C EXSR StoreRecNo C EXSR ReadF1 C EXSR SetTmpKeyFrF1 C IF TmpKey > PrvLstKey C LEAVE C ENDIF C ENDDO C ENDSR *=================================================================* . . .
  • 4. *=================================================================* * *-----------------------------------------------------------------* C ReadF1 BEGSR C EVAL ValidF1 = 'N' C DOW ValidF1 <> 'Y' C EXSR ReadF11 C ENDDO C ENDSR *=================================================================* * *-----------------------------------------------------------------* C ReadF11 BEGSR C EVAL ValidF1 = 'Y' C READ F1FMT 91 C IF *In91 = *On C EVAL F1End = 'Y' C GOTO ReadF11X C ENDIF C EXSR CheckEOF1 C IF F1End = 'Y' C GOTO ReadF11X C ENDIF C EXSR SelectF1 C ReadF11X ENDSR *=================================================================* * Check Logical End Of File *-----------------------------------------------------------------* C CheckEOF1 BEGSR C CheckEOF1X ENDSR *=================================================================* * *-----------------------------------------------------------------* C SelectF1 BEGSR C IF F1NUMBER < FRNUMBER or C F1NUMBER > TONUMBER C EVAL ValidF1 = 'N' C GOTO SelectF1X C ENDIF C IF F1NAME < FRNAME or C F1NAME > TONAME C EVAL ValidF1 = 'N' C GOTO SelectF1X C ENDIF C SelectF1X ENDSR *=================================================================* * Position File F1 for Refresh *-----------------------------------------------------------------* C PosF1Refresh BEGSR C EVAL TmpKey = Prv1stKey C EVAL F1NAME = TmpNAME C EVAL F1NUMBER = TmpNUMBER C F1Key SETLL F1FMT C ENDSR *=================================================================* 3 4 2 1 5