Forum Stats

  • 3,781,172 Users
  • 2,254,486 Discussions
  • 7,879,604 Comments

Discussions

Reducing line of code from package body.

Satyam Rai
Satyam Rai Member Posts: 6
edited Dec 10, 2015 11:32AM in SQL & PL/SQL

Hi All,

I have a question regarding a package which contains around 10 procedure. As I have declared all procedure in package specification, and in package body so it has become very lengthy around 700

lines of code.

Now I am using concept of private procedure to reduce some lines from package specification but still its look quite lengthy. Is there any process or idea by which I can reduce lines even from Package Body? Please provide syntax as well. Can I separately create those procedures and call inside the package body? 

Tagged:
BrunoVromanFrank Kulash
«1

Answers

  • Unknown
    edited Dec 10, 2015 9:44AM

    >. Can I separately create those procedures and call inside the package body?

    I give up.

    Can you?

    Most competent PL/SQL programmer could do so.

    What exactly will be the benefit from doing so?

    Will any one be able to measure any difference after you do so?

    Do you have a solution that is in search of a problem?

  • Frank Kulash
    Frank Kulash Member, Moderator Posts: 41,379 Red Diamond
    edited Dec 10, 2015 9:54AM

    Hi,

    Satyam Rai wrote:
    
    Hi All,
    
    I have a question regarding a package which contains around 10 procedure. As I have declared all procedure in package specification, and in package body so it has become very lengthy around 700
    lines of code.
    Now I am using concept of private procedure to reduce some lines from package specification but still its look quite lengthy. Is there any process or idea by which I can reduce lines even from Package Body? Please provide syntax as well. Can I separately create those procedures and call inside the package body? 
    

    Sorry, without seeing your code, I can't suggest any changes.

    If you have 700 lines of code in the package spec, then maybe there's too much in the package.  Perhaps it should be divided into 2 or more separate packages.

  • John Spencer
    John Spencer Member Posts: 8,567 Bronze Crown
    edited Dec 10, 2015 9:51AM

    A package is intended to hold a group of functionally related units of code.  For example, you might have a package form employee maintenance in an HR application.  It would contain procedures to hire and employee, terminate an employee, change an employee's department etc.  As such, it needs to have whatever code is required to do those jobs. 

    If that means that there are 30 or 3 procedure in the package spec then that is what is required.  Similarly, the package body needs to have at least the procedures defined in the spec plus, in most cases, other helper procedures that do parts of the job but are not callable externally.  In packages that I have written, they vary from having one procedure in the spec and hundreds in the body to having 40 in the spec and 40 in the body.  There is no "right" number for the number of procedure n the spec or the body.

    Not exposing procedures in the package spec if they are not intended to be called externally is a good practice, but the private procedures a re still needed.  Moving those out of the package to implement as standalone procedures is wrong.  It can cause all sorts of issues for dependencies and future maintenance,

    John

    BrunoVroman
  • Nimish Garg
    Nimish Garg Member Posts: 3,185 Gold Trophy
    edited Dec 10, 2015 9:55AM
    Can I separately create those procedures and call inside the package body? 
    

    Yes you can  !!!


    Why do you want to reduce package size. Anyways you can divide the package into 2 or more packages as Frank said, probably divide them is some logical ways i.e. as per their funcationality


  • BrunoVroman
    BrunoVroman Member Posts: 1,848 Silver Crown
    edited Dec 10, 2015 10:10AM

    Hello,

    note that IMHO 700 lines is really not much, you could have dozens of thousands of lines... I think that what has to be in a package or not is not guided by the length of code. You might have a look at Steven Feueurstein's column in the issue of January 2015 of Oracle Magazine : When Packages Need to Loose Weight

    Best regards,

    Bruno Vroman.

  • Chris Hunt
    Chris Hunt Member Posts: 2,066 Gold Trophy
    edited Dec 10, 2015 10:23AM

    Well, you could tote your package body into your text editor of choice, replace all carriage returns with spaces and presto! Your package has one line of code.

    That's only slightly less sensible than your question.

    • Put things into a package if they're logically related (you may interpret this relationship as strictly or as loosely as you like).
    • Only make procedures/functions public if they need to be called from outside the package
    • Don't worry about "lines of code"
    Frank Kulash
  • Unknown
    edited Dec 10, 2015 10:24AM

    Regardless of how the code is packaged, the total number of lines of code will remain approximately the same.

    You remind me of the following story.

    A guy orders a pizza.

    The order taker asks him does he want it cut into 12 or 6 pieces.

    The guy responds to please cut it into 6 pieces because he is not very hungry & could never eat 12 pieces.

  • EdStevens
    EdStevens Member Posts: 28,600 Gold Crown
    edited Dec 10, 2015 10:33AM
    Satyam Rai wrote:
    
    Hi All,
    
    I have a question regarding a package which contains around 10 procedure. As I have declared all procedure in package specification, and in package body so it has become very lengthy around 700
    lines of code.
    Now I am using concept of private procedure to reduce some lines from package specification but still its look quite lengthy. Is there any process or idea by which I can reduce lines even from Package Body? Please provide syntax as well. Can I separately create those procedures and call inside the package body? 
    

    700 lines of code for an entire package isn't much.  Why do you think it needs to be reduced.  If you try to break up the package into multiple packages just to reduce lines of code, you need to consider the impact on all the application code that references the procedures in that package.   I remember reading an article recently about 'breaking the contract' when you change the interface of a package.  I can't find it now and don't remember the author, though I think I was Tom Kyte.

  • Frank Kulash
    Frank Kulash Member, Moderator Posts: 41,379 Red Diamond
    edited Dec 10, 2015 10:42AM

    Hi,

    Chris Hunt wrote:
    
    Well, you could tote your package body into your text editor of choice, replace all carriage returns with spaces and presto! Your package has one line of code.
    ...
    

    Good idea, but watch out for line-ending comments

    ...
    PROCEDURE  proc_a;  -- Comment
    ...
    

    should be changed to

    ...
    PROCEDURE  proc_a;  /* Comment */
    ...
    
  • Sven W.
    Sven W. Member Posts: 10,534 Gold Crown
    edited Dec 10, 2015 10:52AM

    Comments should be deleted. After all they have no true meaning!

This discussion has been closed.