Sublime Deslimer: Refactoring with Confidence using RDi - Edmund Reinhardt - RDi architect - Gateway/400 Group

Page created by Thelma Clark
 
CONTINUE READING
Sublime Deslimer: Refactoring with Confidence using RDi - Edmund Reinhardt - RDi architect - Gateway/400 Group
Sublime Deslimer:
Refactoring with Confidence
         using RDi

   Edmund Reinhardt – RDi architect

                                      © 2018 IBM Corporation
Sublime Deslimer: Refactoring with Confidence using RDi - Edmund Reinhardt - RDi architect - Gateway/400 Group
Why does it matter if code is slimy
•   Could kill your company
     – Cautionary tale of Sword Inc
     – Was the market dominating C debugger in the 80s
     – But were never successful in getting a C++ debugger out
     – Went bankrupt as a result
     – Code was rushed to be first to market
     – Never time to clean up
     – And then when the C++ requirement came up,
         • Took too long to update code
         • Code was buggy and performed poorly

Some anecdotes and thoughts learned from Robert Martin in Clean Code

                                                 © 2018 IBM Corporation
Sublime Deslimer: Refactoring with Confidence using RDi - Edmund Reinhardt - RDi architect - Gateway/400 Group
How does code get slimy
•   In the beginning the code is clean and it is easy to enhance
•   Over time the code gets messy but no time to fix

                                   Productivity over time
             100

              90

              80

              70

              60

              50

              40

              30

              20

              10

               0
                   0   1   2   3     4     5     6    7       8      9      10       11   12

                                                            © 2018 IBM Corporation
Sublime Deslimer: Refactoring with Confidence using RDi - Edmund Reinhardt - RDi architect - Gateway/400 Group
Business IMPACT

•   This creates a gap between business plans and breaks promises to customers and loses profit

                                        Projected Plan vs Real Productivity
                      100

                      90

                      80

                      70

                      60

                      50

                      40

                      30

                      20

                      10

                       0
                            0   1   2   3    4        5         6       7           8   9   10   11   12

                                                 Productivity       Business Plan

                                                    © 2018 IBM Corporation
Sublime Deslimer: Refactoring with Confidence using RDi - Edmund Reinhardt - RDi architect - Gateway/400 Group
Mythical Man Month MAKES it WORSE
•   “adding manpower to a late software project makes it later” - Frederick Brooks Jr
•   The old software is teaching the new programmers. And so even after the learning curve is conquered,
    productivity is still steadily declining.
•   But in the mean time the cost is going up as a step function

                                                                                Plan vs Productivity vs Cost
                                                         100
                        Theoretical                       90
                                                          80
                        Productivity after                70
                        adding people                     60
                                                          50
                                                          40
                                                          30
                                                          20
                                                          10
                                                           0
                                                                0       1   2    3     4     5      6    7     8        9   10   11   12

                                                                                     Productivity       Business Plan

                                                                                                        Cost

                                               © 2018 IBM Corporation
Sublime Deslimer: Refactoring with Confidence using RDi - Edmund Reinhardt - RDi architect - Gateway/400 Group
The big redesign in the sky

•    Solution according to programmers
       – The ones who know – unlike the managers
•    Need to start over – green field
•    In the absence of solid test suite, all of the requirements locked in old code
•    But in the mean time, need a solution for customers
•    One team repairing the old system while “Seal Team 6” writes new
•    Xenos paradox
•    If rewrite involves a new platform then it is not a tortoise being chased
       – Rather a Ferrari out of gas being pushed by its driver
•    Bottom line: Cannot run away from your bad code

                                                     © 2018 IBM Corporation
Sublime Deslimer: Refactoring with Confidence using RDi - Edmund Reinhardt - RDi architect - Gateway/400 Group
Solution: Refactoring
•   Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal
    structure without changing its external behavior. Its heart is a series of small behavior preserving
    transformations. Each transformation (called a 'refactoring') does little, but a sequence of
    transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to
    go wrong. The system is also kept fully working after each small refactoring, reducing the chances that
    a system can get seriously broken during the restructuring.
      – Martin Fowler at refactoring.com as cited in: Lawrence Bernstein, C. M. Yuhas (2005) Trustworthy
        Systems Through Quantitative Software Engineering. p. 266

                                                   © 2018 IBM Corporation
Goal of Software
•   Communicate
      – (a) with computers
      – (b) with humans
•   “Any fool can write code that a computer can understand. Good programmers write code that humans
    can understand.”
      – Martin Fowler 2009
•   “Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures
    the designer's intent but rather is full of crisp abstractions and straightforward lines of control.” - Grady
    Booch
•    ”Clean code can be read, and enhanced by a developer other than its original author. It has unit and
    acceptance tests. It has meaningful names” – David Thomas

                                                    © 2018 IBM Corporation
Excuses

 •   My manager/customer can’t wait – so I have no time and have to rush this
 •   I can always go back and clean it later

 •   Yeah right! When is the last time you went back and cleaned it later?

                                               © 2018 IBM Corporation
Names

• Names are critical to

  – Revealing the programmer’s intent

  – Making the code read like prose

• That’s why RDi made renaming the first refactoring that we
  are making available
• Since the tool makes renaming easy and error-free there is
  no excuse to tolerate cryptic or out-of-date names any more

                              © 2018 IBM Corporation
11

     Rename ILE RPG Declaration Refactoring

       •   RPG refactoring was the highest voted RFE in 2016
       •   Refactoring is the process of changing code without changing the function of the code. The
           purpose of refactoring is to make the code more readable and maintainable.
       •   Rename refactoring allows the user to rename all and only the symbols in an ILE RPG file that
           are related to the user-defined name containing the cursor or selection.
       •   This works for any user-defined name including file, record format, standalone variables, data
           structures, subfields, procedures.
       •   It works within fixed, free and fully free (**FREE) source.

                                                   © 2018 IBM Corporation
12

     Rename Refactoring – Invocation

         •Place the cursor or select the name to rename in the Remote Systems LPEX editor.

         •Either right click or pull down the Source menu and select Refactor->Rename, or press
         Alt+Shift+R.
         •If the name is not a valid user-defined name, the Source->Refactor->Rename will be disabled
                                                 © 2018 IBM Corporation
13

     Rename Refactoring – Specify new name

       •   After selecting the menu item, a dialog will appear prompting for the new name.
       •   The OK and Preview buttons will only enable once the new name is different than the old
           one.
       •   Click OK to complete the process, click Preview to preview the changes that will occur, or
           select Force preview and then OK to ensure that the changes are previewed.
            – If you select Force preview, this option will become the default for the next time that you
               use the wizard.

                                                    © 2018 IBM Corporation
14

     Rename Refactoring – Preview

     • The initial preview panel shows how many references there are to the declaration that you
       want to rename in an informational message.

     • If there are issues with the rename, warning or fatal messages will be shown. If fatal
       messages, only Back and Cancel buttons are available.

                                                  © 2018 IBM Corporation
15

     Rename Refactoring – Preview

         •   Preview shows the changes that will be made before you apply them to the editor.

                                                © 2018 IBM Corporation
16

     Rename Refactoring – Preview

      •   Expand the list of previewed changes to work with changes individually. Clear the checkbox if
          you do not want a specific change to be performed.

                                                   © 2018 IBM Corporation
17

     Rename Refactoring

     •   Click OK to update the editor.
     • Use Undo if you want to revert the changes.

     •   Limitations
          – /COPY members are not updated.
          – Code that is excluded by /IF /ELSE statements will not be renamed.
          – Only renames within a line are supported
     •   Documentation available at:
         https://www.ibm.com/support/knowledgecenter/SSAE4W_9.5.1/com.ibm.etools.iseries.rse.doc/topics/refactor.html

                                                         © 2018 IBM Corporation
Rename with confidence!
•   Much more sophisticated than find/replace
•   Detects
     – Overflowing fixed columns

         The renamed "qual.p(y):qual.b" will overflow positions 12-25 of line 16 :
         " C [q.p(y):q.b ]scan        x:q.q(q.b) q.q(q.b)            10 “

     – Same name as external definitions

     – When RPG language makes it ambiguous (EXTNAME parm is a literal)

                                                 © 2018 IBM Corporation
Qualified Subfields

                      © 2018 IBM Corporation
Example: Hex converter

                         © 2018 IBM Corporation
Catching up to 1994
•   Clearly your first goal will be get to ILE RPG
     – Can always use CVTRPGSRC or partner tools from ARCAD or Linoma

    Hurray!, 10 character names, no indentation, still in fixed form jail
                                                        © 2018 IBM Corporation
Convert to free form

Hurray! Indented free form, lots of room for long names, but who is going to make them long?
                                                  © 2018 IBM Corporation
AAS (e-config) - PID 5733-AC1

          Convert fixed RPGLE to modern RPG Free Form

                                                           Before and after –
                                                           Modernization of source code using
                                                           ARCAD RPG Converter

                                                           Now conveniently available through
                                                           AAS (e-config) –
                                                           PID 5733-AC1

                                  © 2018 IBM Corporation
Free form necessary but not sufficient
•   While converting to free form ILE, now communicates the structure
      – Especially if you fix indentation using Ctrl-Shift-F (in RDi)
•   It does not fix the names
•   If your code is like well-written prose you will not need comments
•   For example why have

•   When you could have
•   Not only is the comment less informative than the code
•   But every call reads like well-written prose
     – Well almost – we have to convert to procedure to avoid the EXSR

                                                © 2018 IBM Corporation
Using RDi to refactor slimy code (names)

                              © 2018 IBM Corporation
Naming rules
•   Choose your names thoughtfully
•   Communicate your intent
•   Avoid disinformation
•   Pronounceable names
•   Avoid Encodings
•   Choose parts of speech well
     – Variables are nouns
     – Subroutines/Procedures are verbs
     – Indicators/Procedures returning indicator are predicates like is or has

                                                 © 2018 IBM Corporation
Length of Names - Scope rule

  •   If in tiny scope, use short names
  •   If in large/global scope, use long names
  •   Opposite for Procedures

                                                 © 2018 IBM Corporation
What makes your code slimy

 •   Stench
      – you can tell how bad the code is by the expression on the face of the
         programmer who pulls it up on the screen
 •   Rigidity = The tendency of a system to resist change
      – Requires many changes to many different places to make
         improvement
 •   Fragility
      – Malfunctions in many unpredictable ways when a simple change is
         made
 •   Inseparability
      – When the various parts of that system cannot be independently reused
         in another system
 •   Opacity = cannot understand the intent by reading the code
 •   Example
      – The 1 line change that wasn’t
                                             © 2018 IBM Corporation
Refactoring – Procedures and Scope

                            © 2018 IBM Corporation
When a name is not just a name

                            © 2018 IBM Corporation
Software Engineering Principles
•   Use modern language
     – Move to ILE and move to free form
•   Use modern tools
     – An IDE can help you understand and transform your code intelligently
     – We trust computers to help diagnose cancer, detect fraud, catch criminals, do taxes
         • Surely it can help us understand/transform computer programs
•   Make your code understandable
     – Nomenclature
     – Structure
•   Make your code verifiable
     – Test driven development
     – See tomorrows talk 31CA Test Driven Development – best practices applied to IBM i
         • at 8AM in Salon A

                                                © 2018 IBM Corporation
More Refactoring with RDi – step by step – Ted Holt

•   https://www.itjungle.com/2018/04/16/guru-rdi-and-refactoring/

•   https://www.itjungle.com/2018/05/07/guru-refactoring-into-routines/

•   Check them out!

                                                 © 2018 IBM Corporation
For More Information:

               Some Links You Need                                                   Twitter         #Hashtags
IBM i Home Page:
www.ibm.com/systems/i                                                                                    #IBMi30
                                                                                                     #PowerSystems
IBM 30th Anniversary                                                                @IBMSystems            #IBMi
http://ibmi30.mybluemix.net/                                                        @COMMONug            #IBMAIX
                                                                                   @IBMChampions        #POWER8
IBM Systems Magazine IBM i Edition:                                                @IBMSystemsISVs   #LinuxonPower
http://ibmsystemsmag.com/ibmi/                                                        @IBMiMag       #OpenPOWER
                                                                                    @ITJungleNews    #HANAonPower
Support Life Cycle:                                                                  @SAPonIBMi      #ITinfrastructure
https://www-01.ibm.com/software/support/ibmi/lifecycle/                              @SiDforIBMi      #OpenSource
                                                                                                      #HybridCloud
License Topics:                                                                                          #BigData
https://www-01.ibm.com/support/docview.wss?uid=nas8N1022087

                                                          © 2018 IBM Corporation
For More Information:

                          Blogs
IBM Blogs:
• IBM Systems Magazine You and i (Steve Will)                          http://ibmsystemsmag.com/blogs/you-and-i/
• IBM Systems Magazine i-Can (Dawn May)                                http://ibmsystemsmag.com/blogs/i-can/
• IBM Systems Magazine: Open your i (Jesse Gorzinski)                  http://ibmsystemsmag.com/blogs/open-your-i/
• IBM DB2 for i (Mike Cain)                                            http://db2fori.blogspot.co.uk/
• IBM DB2 Web Query for i (Doug Mack)                                  http://db2webqueryi.blogspot.co.uk/
IBM Champion’s Blogs:
• IBM Systems Magazine: iDevelop (Jon Paris and Susan Gantner)         http://ibmsystemsmag.com/blogs/idevelop/
• IBM Systems Magazine: iTalk with Tuoy                                http://ibmsystesmag.com/ibmi/trends/italk-with-tuohy/

                                                     © 2018 IBM Corporation
You can also read