DavidFeldhoff / al-codeactions

MIT License
17 stars 8 forks source link

[Improvement] Extract to Procedure could avoid var for paramater variables #157

Open pri-kise opened 1 year ago

pri-kise commented 1 year ago

If I have an eventsubscriber with some code and extract this code to a procedure all variables are added as var paramter. Although the orginial event subscriber parameter (e.g. SalesHeader : Record SalesHeader is only passed by value.

[EventSubscriber(ObjectType::Table, Database::"Gen. Journal Line", 'OnAfterCopyGenJnlLineFromSalesHeader', '', false, false)]
local procedure GenJournalLine_OnAfterCopyGenJnlLineFromSalesHeader(SalesHeader: Record "Sales Header"; var GenJournalLine: Record "Gen. Journal Line")
begin
    DoMagic(SalesHeader, GenJournalLine);
end;
//local procedure DoMagic(var SalesHeader: Record "Sales Header"; var GenJournalLine: Record "Gen. Journal Line") // Current Behaviour

//>> Improvement
local procedure DoMagic(SalesHeader: Record "Sales Header"; var GenJournalLine: Record "Gen. Journal Line") // Current Behaviour
//<< Improvement
begin
   if SalesHeader
end;

If possible in this specific scenario the parameter could be created without var in my opinion.

DavidFeldhoff commented 1 year ago

Hi, you're right. I made it first time this way to make sure that nothings broken afterwards, but I do know that it's not perfect. But for changing something in that extract procedure logic I need some time to focus on it as it's not that easy. So thanks for creating that issue to make me once more aware of it, but I have to see when I find enough time to dig into it. Most probably I can't find that time in the next weeks.

pri-kise commented 1 year ago

No hurry. I'm really happy with your extension right now. I only wanted to track this here. I searched for other issues, that describe this and didn't find any similiar one.