50

Function definition in various programming languages

//JavaScript/PHP

function myfunc()
{

}

//Swift

func myfunc()
{

}

//Kotlin

fun myfunc()
{

}

//Rust

fn myfunc()
{

}

//Next...

f myfunc()
{

}

Comments
  • 2
    What's your point?

    ...and welcome to devRant!
  • 3
    The abbreviations are getting out of hand
  • 6
    It did get better from "public static void main() {}"

    To "pub fn main() {}" Or "pub fn foo() i32 {}"

    Welcome to devRant!!!
  • 13
    // Unix shell

    myFunc() {

    }
  • 2
  • 16
    Please please please attach your curlies 😭
  • 2
    @Root Haha, i can't edit it.
  • 3
    Could you not press return so often pls?
  • 1
    @daintycode nope.
  • 0
    @Pogromist k. was just askin.
  • 1
    VB :
    Scope Function MyFunction () As Datatype
    End Function
  • 3
    JS inside a class
    myfunc() {}
  • 4
    Assembly:

    :function_name
    ret
  • 6
    Then we got python

    def myFunc:

    Note how the term "function" is not used here at all xP
  • 0
    fn pig(){
    // Deadmau5
    }
  • 2
    Also JS:
    () => {}

    Even cleaner if you have one argument and the function only consists of a return statement:

    x => x * 2
  • 4
    public static void main()
    1 2 3 4

    1- Access permission/visibility

    2- Static means not being tied to an object instantiation, its a class method rather than an object method.

    3- Return type

    4- method name

    Not a single wasted "function/fun/fn/def" or whatever ....

    @byte
  • 0
    @IllSlapU Mismatched and clashing colors, patterns, and fabrics is a "style," too, I suppose. Both evoke eye-bleeding, and for the same reasons.
  • 1
    @azous I don't do OOP regularly now a days, and the languages I use have a unique way of implementing it.
    I was giving my example for Go and Rust as they have a new syntax style and I've used these languages.

    So 'static' might not be used, but Go syntax allows to join function to structs as methodes
    Eg: func (a *aStruct) method() {}
    Or Rust:
    impl a_struct A{
    pub fn method() {}
    }
    And as there is no proper concept of class no need to specify static, just add them to the package/module and they are 'static' as per OOP definition.

    The 'pub' in Rust is the same as access and everything else is private by default
    Go does it by syntax, functions starting with caps are public all other private

    The name is present in all cases

    The return type is written after the function name and no need to specify 'void' type
    Go: func getInt() int {}
    Rust: fn getInt() i32 {}
  • 2
    Yeah, Go has some awesome designs @byte
  • 1
    @Root Maybe colon symbol placed after function name?
  • 0
  • 1
    @Root
    Assembly:

    function_name:
    ret
  • 1
    @Pogromist depends on the assembler.
    I've used some whose labels were prefixed with a bang.
  • 0
Add Comment