Standalone Functions
It's common to use functions or methods that have no logical connection as members of classes. Dynamic languages with first-class functions such as JavaScript and Python typically declare these as standalone functions declare stored as regular variables. Static languages with class-based files such as C# and Java typically declare these as static methods within static classes.
Declaring Standalone Functions
Budgie unifies the two with the concept of a standalone function
. These functions, similar to static functions, are referenced in Budgie code as members of some standalone container, which becomes a static class in static languages but goes away in dynamic languages.
Declaring a standalone function requires placing it within a group of them, similar to a static class declaration.
standalone functions declare start
takes a single parameter as the name of the group in PascalCase, which will become the class name in static languages.It may take in the
export
keyword before the name of the group to indicate the group being available to import in other files.standalone functions declare end
closes the group and takes no parameters.standalone function declare start
takes in eitherpublic
orprivate
to indicate its availability outside of the group, the function name in PascalCase, return type, and any number of (name, type) pairs of parameters.standalone function declare end
closes a function and takes no parameters.
Calling standalone functions with standalone function
takes in the name of the group in PascalCase, the privacy of the command, the name of the method in PascalCase, then any parameters.
In C#:
In Python:
Importing Standalone Functions
The import standalone functions
command must be used after the use
in import declarations. Different languages will import either the container group (static class) or individual functions. It takes in the name of the group in PascalCase followed by any number of standalone function names in PascalCase to import.
In C#:
In Python:
Last updated