💻
Budgie
  • Introduction
  • Syntax
    • Comments
    • Strings
    • Variables
    • Math
      • String Conversions
    • Arrays and Lists
      • Sorting
    • Dictionaries
    • Enums
    • Classes
      • Member Variables
      • Member Functions
      • Interfaces
      • Static Variables
      • Static Functions
    • Standalone Functions
      • Main
    • Lambdas
    • Exceptions
    • Files
    • Imports
    • Unsupported Commands
  • Projects
  • Internals
  • Languages
  • Omissions
Powered by GitBook
On this page

Was this helpful?

  1. Syntax
  2. Classes

Static Functions

As with static variables, Budgie syntax for static functions behaves almost identically to the member equivalents. The only difference is that accessing them takes in the class name instead of an instance reference.

class start : Utilities
    static function declare start : public GetLongest string words { array type : string }
        variable : longest string

        for each start : words word string
            if start : { operation : { string length : word } (greater than) { string length : longest } }
                operation : longest equals word
            if end
        for each end

        static function : public Utilities log word

        return : longest
    static function declare end

    static function declare start : public log void word string
        print : { concatenate : ("Logging: ") word }
    static function declare end
class end

In C#:

using System;

class Utilities
{
    public static string GetLongest(string[] words)
    {
        string longest;

        foreach (string word in words)
        {
            if (word.Length > longest.Length)
            {
                longest = word;
            }
        }

        Utilities.Log(word);

        return longest;
    }

    public static void Log(string word)
    {
        Console.WriteLine("Logging: " + word);
    }
}

In Python:

class Utilities:
    @staticmethod
    def get_longest(words):
        for word in words:
            if len(word) > len(longest):
                longest = word

        Utilities.log(word)

        return longest

    @staticmethod
    def log(word):
        print("Logging: " + word)
PreviousStatic VariablesNextStandalone Functions

Last updated 5 years ago

Was this helpful?