02
Sat, Nov
2 New Articles

The Wheels Are Turning

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

We've turned into a culture in which writing code that's already been written has become standard operating procedure. It's no wonder the adoption of subprocedures, while increasing in recent months, has been slow at best.

In virtually every shop I visit, people claim they would rather use a tool than write their own version of a routine, but in practice, even when such a tool is available, they write their own version anyway--effectively reinventing the wheel. Maybe it's boredom or too much free time.

Yes, this hypocritical practice is becoming disturbing. We say we want to use routines that are already written and proven to work, yet when push comes to shove, many programmers sit down and start writing routines from scratch. Oh sure, there's code "stealing" that occurs, but that's been a part of programming since the beginning and is to be expected. It is the rewriting of routines that are readily available as "canned" in-house libraries of stuff or even low-cost, third-party packages that is confusing to me.

When I wrote the CodeStudio editor (a Windows-based editor to replace SEU), I wrote it in C++. It was common practice for me to look for prewritten routines to do certain things; if I couldn't find it, I wrote it. For example, the "tabbed dialog box" (now common in Windows XP and other platforms) was not available as a native interface under Windows 3.x or early Windows 95 implementations, so I developed one. Later, when everyone moved to 32-bit Windows platforms, I migrated my own code to the native interfaces. Of course, my implementation was "better" (tongue in cheek), but why use my code when native interfaces were more than good enough?

Another thing I needed was "tooltips," those little yellow pop-up windows that appear over a toolbar icon when you move the mouse over them. Originally, this feature was not included in the standard set of interfaces, so I started to write one. But then I found a company that already wrote a similar interface that also had a lot of extra features--not that I needed those features, but they were cool nonetheless. So rather than reinvent the wheel, I purchased this "tooltip control" from the vendor and incorporated it into my application.

Instead of spending a month or so tweaking tooltips in my application, I worked on adding a Procedure Wizard to the package. Which one do you think added more value to the package? Tooltips or a Procedure Wizard that allows you to generate the source code for a procedure and its prototype? Needless to say, I continue to use the Procedure Wizard to this day.

My point is that we have to weigh the cost of spending time reinventing compelling but irrelevant routines in our code versus using an in-house library of prewritten routines or a third-party solution. It is pointless for all 600,000 iSeries installations to, for example, write a routine that creates a user space or convert a value from and to hexadecimal notation.

Why not use something that has already been written? If it's an in-house routine that isn't coded very well, then I understand attempting to reinvent the wheel. If it's a third-party solution, it had better be well-written.

I think some of the problem stems from the myriad examples on the Internet. Many of us are now in the habit of asking for free example code via email and online forums. Many times, they take that example code and present it as their own to their employer, thus effectively being paid for someone else's work. But that situation will have to wait for another article.

In other situations, people are presented with "free" solutions off the Internet. If they get a solution from someone else, they often take it, modify it, and get it to work the way they want. But if it's available as a third-party solution, they rarely go to their boss and ask to purchase that solution. Instead, they will spend time rewriting the same solution. Often, their labor costs as much as or more than the third-party solution and rarely is as well-written.

Even if a third-party solution is available, programmers often think that their employer is paying them to write code, so why not have their employer pay them to write the solution? In other words, they personalize the cost of the third-party solution. This, in the iSeries market, is the absolute wrong thing to do.

Some people will also compare the cost of a third-party package to that of a PC package. This is also an invalid comparison. PC software is typically priced on a per-user basis. It just so happens that per-user also means per-PC. Do the math and see if iSeries software is really much more expensive than PC-based solutions.

Let's look at a hard example of the cost of rolling your own. Of course, salaries for programmers vary widely throughout North America, but for the sake of argument and easy math, let's say that programmers everywhere make $1,500 per week (gross pay), or $78,000 per year. This means that each day a programmer works on something, the company pays $400 for those services. That includes the programmer's $300 base salary, plus the typical one-third overhead for benefits and whatnot. This comes to about $50 per hour. And remember, your company is paying $50 an hour for your time even when you are perusing online news articles, checking sports scores, reading informational articles like this one, planning your vacation, talking on the phone, or visiting with a colleague.

So at $50 an hour, how long would it take an average programmer to write a program that creates a user space? There is an API for it, so you will call the API. There are at least two free CRTUSRSPC (create user space) utilities on the Internet, but one of those free ones requires that you pay an annual magazine subscription to get the free code. There are also CRTUSRSPC CL commands included with TAATOOLS and RPG xTools. So if you own either of those, you can use them. But remember, we want to reinvent the wheel here to prove a point.

I was able to create an RPG IV program that creates a user space in QTEMP, including setting the auto-extend attribute on, which is required by most OS/400 APIs. The program took about 60 lines of code and about 90 comment lines. I did use prototypes to call the QUSCRTUS and QUSCUSAT APIs, which I know most people don't bother using. But I found free versions of the prototypes for these APIs on the www.rpgiv.com/downloads Web site. Since I found them, they are mine, and I can say that I wrote them. Right? (Well, actually I did write them, but let's forget about that for now.)

So how long will it take the average programming to write this Create User Space routine? I would say anywhere from 4 to 16 hours. If the programmer isn't all that experienced with APIs, getting it to work flawlessly could take 20 to 24 hours. The programmer might also spend an extra half day to an entire day trying to figure out why you have to specify both the REPLACE and the ERROR parameters on the QUSCRTUS when you only want the REPLACE parameter. So let's agree on it being a 20-hour task.

That's $50 an hour for 20 hours, or $1000, for just one simple CRTUSRSPC program.

OK, now suppose you want to create a list of field names in that user space. Is that another $1000? Probably not. It could be less, but it could also be much more. To transverse the output from a "list" API in a user space is an intriguing programming challenge at best. I would guess that, with all the nonproductive time added in, it takes one or two weeks to build the CRTUSRSPC program, add in the part to create a list of fields in that user space, and then retrieve the fields into some usable format.

So that means a simple "give me a list of field names" routine could cost your company an average of 60 hours, or $3000.

Below is the code for the CRTUSRSPC program, so you don't have to reinvent that wheel.

     H Copyright('2005 - Robert Cozzi, Jr.')
     OPTION(*SRCSTMT)
      *********************************************************
      **  This program illustrates the API way to create
      **  a *USRSPC object with the auto-extend attribute.
      **  It creates a specific *USRSPC in QTEMP but can easily 
      **  be modified to create one of any name in any library.
      *********************************************************
      **  The alternative to using all this code is to call
      **  the RPG xTools CrtUsrSpace procedure.
      **  With RPG xTools, all you would have to code is the following:
      **
      **  (NOTE: The compiler directives are used here
      **         to avoid compiling this statement.)
      /IF DEFINED(NOTDEFINED)
     C                   callp     CrtUsrSpace('QTEMP/SAMPLE')
      /ENDIF


      ** Include the API Error Data Structure from QSYSINC
      /INCLUDE QSYSINC/QRPGLESRC,QUSEC

      *********************************************************
      ** C R E A T E  U S E R  S P A C E  -  Prototype
      *********************************************************
     D QUSCRTUS        PR                  ExtPgm('QUSCRTUS')
     D  UserSpace                    20A   Const
     D  ExtAttr                      10A   Const
     D  nSize                        10I 0 Const
     D  InitValue                     1A   Const
     D  PubAuth                      10A   Const
     D  szTextDesc                   50A   Const
     D  Replace                      10A   Const
      /IF       defined(*V5R1M0)
     D  apiError                           LikeDS(QUSEC) OPTIONS(*NOPASS)
      /ELSE
     D  apiError                           Like(QUSEC) OPTIONS(*NOPASS)
      /ENDIF
     D  bSysDomain                   10A   Const OPTIONS(*NOPASS)

      *********************************************************
      ** C H A N G E  U S E R  S P A C E   A T T R  –  Prototype
      *********************************************************
     D QUSCUSAT        PR                  ExtPgm('QUSCUSAT')
     D  RtnLibName                   10A
     D  UsrSpace                     20A   Const
     D  USAttr                       64A   OPTIONS(*VARSIZE)
      /IF   defined(*V5R1M0)
     D  apiError                           LikeDS(QUSEC) OPTIONS(*NOPASS)
      /ELSE
     D  apiError                           Like(QUSEC) OPTIONS(*NOPASS)
      /ENDIF

     D USA_SIZE        C                   Const(1)
     D USA_INITVALUE   C                   Const(2)
     D USA_AUTOEXT     C                   Const(3)
     D USA_TFRSIZE     C                   Const(4)


     D chgAttr         DS
     D  nKeyCount                    10I 0 Inz
     D  UsrSpaceAttr                       Like(usKeyAttr) Dim(5)

      **  Auto extend attribute is set to *ON
     D ExtAttr         S             10A   Inz('COZZI')


      **  Auto extend attribute is set to *ON
     D bAutoExt        S              1A   Inz('1')

      **  Replace(*YES | *NO)
     D szReplace       S             10A   Inz('*NO')

     D usKeyAttr       DS
     D   nKey                        10I 0
     D   nDataSize                   10I 0
     D   szKeydata                   10A

     D UserSpace       S             20A
     D UserSpaceSize   S             10I 0 Inz(32766)
     D rtnLib          S             10A

     C                   eval      *INLR = *ON

     C                   clear                   QUSEC
      /IF  defined(*V5R1M0)
     C                   eval      QUSEC.QUSBPRV = %size(QUSEC)
      /ELSE
     C                   eval      QUSBPRV = %size(QUSEC)
      /ENDIF
      **  Identify the user space name to be created.
     C                   eval      %subst(Userspace:1:10) = 'SAMPLE'
     C                   eval      %subst(UserSpace:11:10) = 'QTEMP'

      **  Create the user space and initialize it to Hex '00'
      **  This value is supposed to be faster than X'40' or other values.
     C                   callp     QUSCRTUS(UserSpace : ExtAttr : UserSpaceSize
     C                                    : X'00' : '*ALL' : 'Cozzi made this.'
     C                                    : szReplace : QUSEC)

      **  If no errors occurred, change the User Space Attr to AutoExtend.
      /IF  defined(*V5R1M0)
     C                   if        QUSEC.QUSBAVL = 0
      /ELSE
     C                   if        QUSBAVL = 0
      /ENDIF
     C                   clear                   usKeyAttr
     C                   eval      nKey = USA_AUTOEXT
     C                   eval      nDataSize = %size(bAutoExt)
     C                   eval      szKeydata = bAutoExt
     C                   eval      nKeyCount = 1
     C                   eval      usrspaceAttr(1) = usKeyAttr
      **  Call the QUSCUSAT (Change User Space Attr) API to modify the
      **  user space attribute(s). Note that the API returns
      **  the library in which the User Space exists. This is because
      **  *CURLIB or *LIBL may be specified as the user space's library.
     C                   callp     QUSCUSAT(rtnLib : UserSpace : chgAttr :
     C                                      QUSEC)
     C                   endif
     C
     C                   return

What Would You Do with $3000?

The question is, why waste $3000 reinventing the wheel? Certainly, as an employee, you don't truly think spending $3000 on these kinds of results is worth it, do you? I don't.

During those 60 hours, you could have inserted a /COPY or two and called a routine to do what you wanted to do. Then, after that two minute period, you could continue to do what the company is really paying you for: writing application code that solves problems or automates function--you know, things the company actually needs.

Using a prewritten in-house library of routines or a third-party package of tools could save you $2998.33 over doing it yourself. Where'd I get that $2998.33 figure? It's the difference between two minutes at the $50 base hourly rate and nearly 60 hours at the $50 base hourly rate.

Of course, you also have to add in the cost of the third-party package, if you go that route. Let's assume most are priced at about $1000 to make things simple. So on the first project alone, you won't save $2998.33; you will only save $1998.33. But after that, you're on your way to consistently saving money for your company by getting projects completed while using rewritten routines that do cool things for you. And after all, isn't that what they are paying you for?

Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. He, along with others, speaks at and runs the highly-popular RPG World conference for RPG programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: