4D Blog

Home Product Coder-friendly syntax for class functions and methods

Coder-friendly syntax for class functions and methods

October 23, 2020

Product

Using $1, $2, and $n variables in your code not only makes the code less readable, it can also increase confusion since the human brain can find it difficult to remember what these variables correspond to. The solution is to create a variable with an understandable name and assign it the value of $1, $2, or $n.

4D v18 R5 has good news, you can now name your parameters when declaring:

  • a project method,
  • a trigger
  • a database method
  • a form method
  • a constructor of a class
  • a function of a class.

 

Let’s see how!

In 4D v18 R4, we showed you a new syntax to declare your variables:

var $name : Text
var $birthdate : Date
var $file : 4D.File

The new syntax for methods and functions is very similar.

New declaration for classes

After the name of the function, add your various input parameters separated by a semicolon in parenthesis:

Class Constructor($firstname : Text; $lastname : Text; $birthdate : Date)
 This.lastName:=$lastname
 This.firstName:=$firstname
 This.birthdate:=$birthdate

Function setAdress($streetNumber : Text; $streetName : Text; $city : Text)
 This.streetNumber:=$streetNumber
 This.streetName:=$streetName
 This.city:=$city

For the output parameter, just add the “->” symbol, then the name and type as the input parameter.

Function getFullname -> $fullname : Text
 $fullname:=This.firstName+" "+Upper(This.lastName)

Function sendMessage($text : Text) -> $message : Text
 $message:="@"+This.firstname+": "+$text

New declaration for methods

The same principle applies to methods with a new keyword: #DECLARE.

  • An example with a “highlightRow” project method:

#DECLARE($listboxName : Text; $rowNum : Integer)
LISTBOX SELECT ROW(*; $listboxName; $rowNum)

  • An example with the On Web Authentication database method:

#DECLARE($url : Text; $header : Text; \
  $BrowserIP : Text; $ServerIP : Text; \
  $user : Text; $password : Text) \
  ->$RequestAccepted : Boolean

$entitySelection:=ds.User.query("login=:1"; $user)
// Check hash password...
// ...

Debugger

The name of the parameter is also visible in the call chain pane of the debugger. Here’s an example with a class function:

Bonus

If you need an additional reason to use the new syntax, take a look at the image below. Yes! The declaration of the function is displayed in the status bar exactly as it is for 4D commands.

blank

Discuss

Tags Class, Code editor, Language, Programming, Project, v18 R5, v19

Latest related posts

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

Vanessa Talbot
Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy