This commit is contained in:
JesperSchulz 2021-11-08 15:53:12 +00:00
parent 158b902b20
commit cb4e8e2194
131 changed files with 3191 additions and 3076 deletions

View file

@ -2,19 +2,19 @@
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<meta name=generator content="Hugo 0.89.0">
<meta name=generator content="Hugo 0.89.1">
<meta name=description content>
<title>Argument Table :: BC AL Help</title>
<link href=/css/nucleus.css?1636104707 rel=stylesheet>
<link href=/css/fontawesome-all.min.css?1636104707 rel=stylesheet>
<link href=/css/featherlight.min.css?1636104707 rel=stylesheet>
<link href=/css/perfect-scrollbar.min.css?1636104707 rel=stylesheet>
<link href=/css/auto-complete.css?1636104707 rel=stylesheet>
<link href=/css/theme.css?1636104707 rel=stylesheet>
<link href=/css/theme-blue.css?1636104707 rel=stylesheet>
<link href=/css/variant.css?1636104707 rel=stylesheet>
<link href=/css/print.css?1636104707 rel=stylesheet media=print>
<script src=/js/jquery.min.js?1636104707></script>
<link href=/css/nucleus.css?1636386789 rel=stylesheet>
<link href=/css/fontawesome-all.min.css?1636386789 rel=stylesheet>
<link href=/css/featherlight.min.css?1636386789 rel=stylesheet>
<link href=/css/perfect-scrollbar.min.css?1636386789 rel=stylesheet>
<link href=/css/auto-complete.css?1636386789 rel=stylesheet>
<link href=/css/theme.css?1636386789 rel=stylesheet>
<link href=/css/theme-blue.css?1636386789 rel=stylesheet>
<link href=/css/variant.css?1636386789 rel=stylesheet>
<link href=/css/print.css?1636386789 rel=stylesheet media=print>
<script src=/js/jquery.min.js?1636386789></script>
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
</head>
<body data-url=/navpatterns/1-patterns/argument-table/>
@ -32,9 +32,9 @@ BC AL Help . dev
<input data-search-input id=search-by type=search placeholder=Search...>
<span data-search-clear><i class="fas fa-times"></i></span>
</div>
<script src=/js/lunr.min.js?1636104707></script>
<script src=/js/auto-complete.js?1636104707></script>
<script src=/js/search.js?1636104707></script>
<script src=/js/lunr.min.js?1636386789></script>
<script src=/js/auto-complete.js?1636386789></script>
<script src=/js/search.js?1636386789></script>
</div>
<div class=highlightable>
<ul class=topics>
@ -200,12 +200,16 @@ BC AL Help . dev
<div class=wrapper>
<nav id=TableOfContents>
<ul>
<li><a href=#bad-example-1>Bad example 1</a></li>
<li><a href=#bad-example-2>Bad example 2</a></li>
</ul>
<li><a href=#argument-table-pattern>Argument table pattern</a>
<ul>
<li><a href=#good-example-1>Good example 1</a></li>
<li><a href=#good-example-2>Good example 2</a></li>
<li><a href=#abstract>Abstract</a></li>
<li><a href=#problem>Problem</a></li>
<li><a href=#solution>Solution</a></li>
<li><a href=#downsides>Downsides</a></li>
<li><a href=#nav-usages>NAV Usages</a></li>
<li><a href=#related-patterns>Related Patterns</a></li>
</ul>
</li>
</ul>
</nav>
</div>
@ -215,23 +219,23 @@ BC AL Help . dev
</div>
<main id=body-inner>
<h1>Argument Table</h1>
<h1 id=argument-table-pattern>Argument table pattern</h1>
<p><em>Originally By Nikola Kukrika and Waldo</em></p>
<h1 id=abstract>Abstract</h1>
<h2 id=argument-table-pattern>Argument table pattern</h2>
<p><em>Originally By Nikola Kukrika and waldo</em></p>
<h3 id=abstract>Abstract</h3>
<p>The Argument Table pattern is used to provide an extension point for adding new arguments without changing the signature. By grouping multiple arguments into a table the code becomes more readable (function signature and the usage of the function).</p>
<p><a href=0218.Argument-Table-image.png><img src=0218.Argument-Table-image.png alt=" "></a></p>
<h1 id=problem>Problem</h1>
<h3 id=problem>Problem</h3>
<p>In CAL overloading function signature is not supported. It is also not possible to provide default values for the function arguments.</p>
<p>When an argument needs to be added to the function, the existing function needs to be extracted to a new method with an additional argument and the original function will call new method. This will cause an upgrade problem in the future, since the entire body of the method is replaced.</p>
<p>Second commonly occurring problem is option duplication. In order to pass options often they are duplicated in the signature.</p>
<p>The last problem that can be solved is high number of arguments. Functions with a high number of arguments are hard to understand. Having arguments grouped within the table with a meaningful name will improve readability and make code easier to understanding.</p>
<p>Few examples of the bad implementations are as illustrated here:</p>
<h2 id=bad-example-1>Bad example 1</h2>
<h4 id=bad-example-1>Bad example 1</h4>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-AL data-lang=AL><span style=color:#66d9ef>PROCEDURE</span> FillInVATReturnData@<span style=color:#ae81ff>1200001</span><span style=color:#f92672>(</span><span style=color:#66d9ef>VAR</span> DeclarationID@<span style=color:#ae81ff>1200000</span> : <span style=color:#66d9ef>Code</span> [<span style=color:#ae81ff>20</span>];<span style=color:#66d9ef>VAR</span> LineID@<span style=color:#ae81ff>1200001</span> : <span style=color:#66d9ef>Code</span> [<span style=color:#ae81ff>20</span>];<span style=color:#66d9ef>VAR</span> PeerID@<span style=color:#ae81ff>1200002</span> : <span style=color:#66d9ef>Code</span> [<span style=color:#ae81ff>20</span>]; <span style=color:#66d9ef>VAR</span> DocumentNo@<span style=color:#ae81ff>1200003</span>: <span style=color:#66d9ef>Code</span>[<span style=color:#ae81ff>20</span>]; <span style=color:#66d9ef>VAR</span> NumberOfCopies@<span style=color:#ae81ff>1200007</span>: <span style=color:#66d9ef>Integer</span>; <span style=color:#66d9ef>VAR</span> Uploaded@<span style=color:#ae81ff>1200004</span> : <span style=color:#66d9ef>Boolean</span>; <span style=color:#66d9ef>VAR</span> Correction@<span style=color:#ae81ff>1200005</span> : <span style=color:#66d9ef>Boolean</span>; <span style=color:#66d9ef>VAR</span> HasValidationErr@<span style=color:#ae81ff>1200006</span> : <span style=color:#66d9ef>Boolean</span><span style=color:#f92672>)</span>;
</code></pre></div><p><strong>Call</strong></p>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-AL data-lang=AL>FillInVATReturnData<span style=color:#f92672>(</span>NoSeries, NextLineID, CustomerID, DocumentNo, SingleCopy, ???, ??, <span style=color:#f92672>....</span>, <span style=color:#f92672>...)
</span></code></pre></div><p>In this example the code is hard to read and understand. Adding an additional argument will require refactoring of the existing function. Each time a new argument is added a new function will be created.</p>
<h2 id=bad-example-2>Bad example 2</h2>
<h4 id=bad-example-2>Bad example 2</h4>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-AL data-lang=AL><span style=color:#66d9ef>LOCAL</span> <span style=color:#66d9ef>PROCEDURE</span> GetTableSyncSetupW1@<span style=color:#ae81ff>3</span><span style=color:#f92672>(</span>OldTableId@<span style=color:#ae81ff>1002</span> : <span style=color:#66d9ef>Integer</span>; <span style=color:#66d9ef>VAR</span> UpgradeTableId@<span style=color:#ae81ff>1001</span> : <span style=color:#66d9ef>Integer</span>; <span style=color:#66d9ef>VAR</span> TableUpgradeMode@<span style=color:#ae81ff>1000</span> : <span style=color:#e6db74>&#39;Check, Copy, Move, Force&#39;</span><span style=color:#f92672>) </span>: <span style=color:#66d9ef>Boolean</span>;
<span style=color:#66d9ef>BEGIN</span>
<span style=color:#66d9ef>CASE</span> OldTableId <span style=color:#66d9ef>OF</span>
@ -247,13 +251,13 @@ BC AL Help . dev
<span style=color:#66d9ef>EXIT</span><span style=color:#f92672>(</span>TRUE<span style=color:#f92672>)</span>;
<span style=color:#66d9ef>END</span>;
</code></pre></div><p>In this example each time a new argument is added all function calls will have to be updated. Option is duplicated in the signature, which will cause issues if a new option is defined or the existing options are renamed.</p>
<h1 id=solution>Solution</h1>
<h3 id=solution>Solution</h3>
<p>By grouping the arguments within the table it is possible to add additional argument and reuse it where it is needed without changing the signature.</p>
<p>Multiple parameters are grouped within the single object with a meaningful name so the code becomes more readable.</p>
<p>It is possible to assign default values and to have the code validation.</p>
<p>Argument table should preferably be a temporary table since the implementation is simpler.</p>
<p>The examples of usages addressing problems shown above are:</p>
<h2 id=good-example-1>Good example 1</h2>
<h4 id=good-example-1>Good example 1</h4>
<p>New table</p>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-AL data-lang=AL>TAB <span style=color:#ae81ff>50003</span> VAT Return Data
<span style=color:#66d9ef>PROCEDURE</span> FillInVATReturnData@<span style=color:#ae81ff>1200001</span><span style=color:#f92672>(</span><span style=color:#66d9ef>VAR</span> VATReturnData@<span style=color:#ae81ff>1200000</span> : <span style=color:#66d9ef>Record</span> <span style=color:#ae81ff>50003</span><span style=color:#f92672>)</span>;
@ -264,7 +268,7 @@ VATReturnData<span style=color:#f92672>.</span>Uploaded <span style=color:#f9267
FillInVATReturnData<span style=color:#f92672>(</span>VATReturnData<span style=color:#f92672>)</span>;
</code></pre></div><p>By introducing an argument table, code is much more readable since there is a single argument for a function. It is easy to see which arguments are passed in and which are modified in a function.</p>
<h2 id=good-example-2>Good example 2</h2>
<h4 id=good-example-2>Good example 2</h4>
<p>Good example</p>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-AL data-lang=AL><span style=color:#66d9ef>PROCEDURE</span> GetTableSyncSetupW1@<span style=color:#ae81ff>3</span><span style=color:#f92672>(</span><span style=color:#66d9ef>VAR</span> TableSynchSetup@<span style=color:#ae81ff>1000</span> : <span style=color:#66d9ef>Record</span> <span style=color:#ae81ff>2000000135</span><span style=color:#f92672>)</span>;
<span style=color:#66d9ef>BEGIN</span>
@ -273,12 +277,12 @@ FillInVATReturnData<span style=color:#f92672>(</span>VATReturnData<span style=co
SetTableSyncSetup<span style=color:#f92672>(</span><span style=color:#66d9ef>DATABASE</span>::&#34;Payment Export Data&#34;,<span style=color:#ae81ff>0</span>,TableSynchSetup<span style=color:#f92672>.</span>Mode::Force<span style=color:#f92672>)</span>;
<span style=color:#66d9ef>END</span>;
</code></pre></div><p>Option definition is not encapsulated within the table. Arguments are grouped and we can add additional arguments without the need to change the signature.</p>
<h1 id=downsides>Downsides</h1>
<h3 id=downsides>Downsides</h3>
<p>You need to create one more table</p>
<p>Complex types can&rsquo;t be embedded as fields in tables (cannot have a record field type etc).</p>
<h1 id=nav-usages>NAV Usages</h1>
<h3 id=nav-usages>NAV Usages</h3>
<p>Upgrade Codeunits</p>
<h1 id=related-patterns>Related Patterns</h1>
<h3 id=related-patterns>Related Patterns</h3>
<p>Posting Routine, Select behavior: Setting fields on existing records in order not to change the signatures.</p>
<footer class=footline>
</footer>
@ -292,12 +296,12 @@ FillInVATReturnData<span style=color:#f92672>(</span>VATReturnData<span style=co
<div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px>
<div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div>
</div>
<script src=/js/clipboard.min.js?1636104707></script>
<script src=/js/perfect-scrollbar.min.js?1636104707></script>
<script src=/js/perfect-scrollbar.jquery.min.js?1636104707></script>
<script src=/js/jquery.svg.pan.zoom.js?1636104707></script>
<script src=/js/featherlight.min.js?1636104707></script>
<script src=/js/modernizr.custom-3.6.0.js?1636104707></script>
<script src=/js/relearn.js?1636104707></script>
<script src=/js/clipboard.min.js?1636386789></script>
<script src=/js/perfect-scrollbar.min.js?1636386789></script>
<script src=/js/perfect-scrollbar.jquery.min.js?1636386789></script>
<script src=/js/jquery.svg.pan.zoom.js?1636386789></script>
<script src=/js/featherlight.min.js?1636386789></script>
<script src=/js/modernizr.custom-3.6.0.js?1636386789></script>
<script src=/js/relearn.js?1636386789></script>
</body>
</html>