VerseWiki
VerseWiki
  • Table of Contents
  • Import Expressions
  • 01. Common Naming Patterns
  • 02. Names
  • 03. Formatting
  • 04. Functions
  • 05. Failure Checks
  • 06. Encapsulation
  • 07. Events
  • 08. Concurrency
  • 09. Attributes
  • 10. Constructors
  • 11. Class & Specifiers
  • 12. Math
  • 13. Containers
  • 📘Fortnite Digest
  • 📗Unreal Engine Digest
  • 📕Verse Digest
  • EG: Onboarding Guide
  • EG: Verse Programming
  • EG: Language Reference
  • EG: Official API
  • EG: Verse Scripting
  • EG: Dev Community
  • EG: Community Snippets
  • View on Github Wiki
Powered by GitBook
On this page
  • 4.1 Implicit return by default
  • 4.2 GetX functions should be
  • 4.3 Prefer Extension Methods to Single Parameter Functions

Was this helpful?

04. Functions

4.1 Implicit return by default

  • Functions return their last expression value. Use that as an implicit return.

    Sqr(X:int):int =
    
         X * X # Implicit return
  • If using any explicit returns, all returns in the function should be explicit.

4.2 GetX functions should be

  • Getters or functions with similar semantics that may fail to return valid values should be marked <decides><transacts> and return a non-option type. The caller should handle potential failure.

    GetX()<decides><transacts>:x
  • An exception is functions that need to unconditionally write to a var. Failure would roll the mutation back, so they need to use logic or option for their return type.

4.3 Prefer Extension Methods to Single Parameter Functions

  • Use extension methods instead of a function with a single typed parameter.

Doing this helps Intellisense. By typing

  • MyVector.Normalize() instead of Normalize(MyVector)

it can suggest names with each character of the method name you type. For example:

 (Vector:vector3).Normalize<public>():vector3

Do not:

  Normalize<public>(Vector:vector3):vector3

Previous03. FormattingNext05. Failure Checks

Last updated 1 year ago

Was this helpful?