Streamlined Method Parameter Declarations

In the pursuit of efficient coding practices, 4D developers commonly configure compilation path settings to enhance syntax and typing checks, thereby minimizing errors during code execution in compile mode. Let’s see how #DECLARE method prototypes will gain time and code security.

Usually, when opting for compilation path setting like ‘Process and interprocess variables are typed’ or ‘All variables are typed’, 4D developers needed to declare method parameters a second time in a ‘compiler_’ method.

However, with the introduction of 4D v20 R4, this additional step becomes a thing of the past. Parameters declared in a #DECLARE method prototype no longer necessitate a redundant declaration in a ‘compiler_’ method.

Declaring method parameters in a #DECLARE prototype now gives the same benefits as for class functions. That makes the legacy method parameter declaration deprecated.

An advantage of this enhancement is that existing code remains unaffected. Parameters declared in ‘compiler_’ methods continue to be recognized. If a parameter is declared in a ‘compiler_’ method and a method prototype, no error is triggered as long as their types align. However, a divergence in types now results in an error, contributing to improved code security.

As method parameters declared in prototypes no longer demand a second declaration in a ‘compiler_’ method, the ‘generate typing’ action in the compile dialog exclusively adds parameters declared outside the prototype.

To facilitate a smooth transition to using method prototypes, the latest update introduces warnings in two scenarios:

  • When parameters are declared both in a method’s body and its prototype.
  • When a method is called with more parameters than those declared in its prototype.

This feature will save you time and enhance code quality by proactively preventing runtime errors in compiled mode.

Avatar
• Product Owner •Damien Fuzeau has joined the 4D Product team in February 2019. As a Product Owner, he is in charge of writing user stories, then translating them to functional specifications. His job also entails making sure that the feature implementations delivered are meeting the customer needs.Damien is graduated from the University of Nantes in software engineering. He spent more than 23 years in its former company, first as developer (discovering 4D in 1997), and later as engineering manager and software architect. This company is a 4D OEM partner and deployed 4D based business softwares for thousands users, on hundreds servers. So, Damien is used to 4D development and deployment in a multi-language context.