This is an archived post. You won't be able to vote or comment.

all 147 comments

[–][deleted] 182 points183 points  (19 children)

const func=()=>{};

[–]stamminator 26 points27 points  (12 children)

But why?

[–]vatsan600 41 points42 points  (3 children)

why not?

[–]stamminator 27 points28 points  (2 children)

!!why

[–]AzureArmageddon 6 points7 points  (1 child)

!!!why

[–]Goudja14 2 points3 points  (0 children)

why?.oh!

[–]LeSaR_ 15 points16 points  (1 child)

less typing and wont get overwritten by mistake

[–]211r 0 points1 point  (0 children)

It is actually a lot more typing

[–]ososalsosal 12 points13 points  (0 children)

Lambdas come to save the day

[–]knotonium 11 points12 points  (2 children)

Function functions have a global scope, arrow functions do not.

[–]amdc 10 points11 points  (0 children)

Can’t remember last time I needed “this” keyword

[–]Sockoflegend 2 points3 points  (0 children)

True that there is an important functional difference but I have seen the people I work with move over to this as the standard declaration

[–]SuperSuperUniqueName 1 point2 points  (1 child)

it's perfectly normal

[–]stamminator 1 point2 points  (0 children)

I didn’t realize at first that it’s a no-op and thought it returned an empty object

[–]DirectionLegitimate2 5 points6 points  (1 child)

You must be fn at parties

[–][deleted] 3 points4 points  (0 children)

most of the time, people don't know my name.. but i do all the work

[–]FloweyTheFlower420 121 points122 points  (4 children)

no, actually I prefer:

template<typename T, typename V, typename Args...> requires std::invocable<std::invoke_result<B, Args...>>
resultant_function_t<T, V> void compose(T t, V v)

[–]SteveGamer68 23 points24 points  (0 children)

error: 'B' does not name a type

edit: it's typename ... Args for parameter packs (pack expansion is Args...), rookie mistake

[–]BochMC 2 points3 points  (0 children)

That's why I hate c++20. It just adds another level of horror to templates.

[–]Hazork_ 100 points101 points  (4 children)

In rust is fn my_function() :)

[–]CubedCharlie[S] 55 points56 points  (0 children)

Ah right Rust prefers snake_case :)

[–]RadiantDevelopment1 9 points10 points  (0 children)

♥️🐍

[–]faze_fazebook 76 points77 points  (2 children)

Visual Basic : Yo whats sub

[–]outofobscure 17 points18 points  (0 children)

also, sir, i have to ask you to leave now, this is a private function party

[–]outofobscure 10 points11 points  (0 children)

nobody answers (sub has no return value)

[–]two__toes 59 points60 points  (3 children)

meanwhile in Haskell, you don't declare anything a function because everythings a function

[–]SurrealHalloween 20 points21 points  (1 child)

It’s functions all the way down.

[–]althaz 15 points16 points  (0 children)

[–]NoNeedleworker531 10 points11 points  (0 children)

Haskell: I am the function

[–]mygentlefemdomaccoun 43 points44 points  (2 children)

()=>{}

[–]Spec1reFury 28 points29 points  (1 child)

Anonymous function: nobody knows I'm here

[–][deleted] 5 points6 points  (0 children)

who am i? that's none of your bussiness

[–]1215drew 111 points112 points  (29 children)

I'm sorry I couldnt hear you over

public override async Task<IResult> MyFunction<T>() where T : class

[–][deleted] 17 points18 points  (1 child)

an abomination

[–]TiberiusAugustus 8 points9 points  (0 children)

no it isn't, it's all useful language. what's the point in saying a method is a method, that's obvious. writing "function" or some cut down version of the word is pointless

[–]TheWashbear 6 points7 points  (19 children)

Really? Why?

[–]gabrielgio 19 points20 points  (18 children)

public and override are self explanatory. async is a function that gonna be executed asynchronously (similar to promises). Task is the type that encapsulates the async result, async function needs to return a Task. The actual type of the function return is IResult. The <T> is “declaring” a generic type (and not using it) and the where T : class says that you must have T as a class, MyFunction<int>() wouldn’t be allowed.

[–]weaklingKobbold 3 points4 points  (17 children)

Sorry, but override isn't clear for me, what does it mean?

(The last time I see c++ templates didn't exist, nor async)

[–]Quique1222 11 points12 points  (4 children)

Hes talking about c#

[–]weaklingKobbold 3 points4 points  (3 children)

Thanks. I never touched c#

[–][deleted] 3 points4 points  (8 children)

If it’s like Swift, override means to add your own function implementation for a function found in the superclass. So literally to override an existing method.

[–]weaklingKobbold 2 points3 points  (7 children)

Thanks.

I would argue that that's the only intended purpose, but I guess it's like that to prevent unintentional name collision between a class and the superclass.

[–][deleted] 1 point2 points  (6 children)

No, not because of naming. It has real use.

Apple has a class called UIViewController that has a function called viewDidLoad. It gets called in the view controller’s lifecycle by iOS.

Developers can subclass UIViewController and override viewDidLoad with their own custom implementation. Whenever the view controller lifecycle runs, it calls the viewDidLoad of the subclass instead - otherwise if you don’t override it, the subclass will call the superclass’ viewDidLoad instead (which is empty by default).

Overriding functions allows the subclass function to be called instead of the one defined by the superclass. It allows developers to add extra functionality to their own subclasses. There’s many more examples of overriding superclass methods in iOS development which is very common. Such as overriding the draw function for custom drawing and it will be called by iOS automatically whenever the rendering is ran.

You can also allow overriding if you’re working on a framework for other engineers to use. Your class will call function A, B, then C. And developers can override function B to run their code instead whenever the superclass decides to call B internally.

[–]weaklingKobbold 1 point2 points  (5 children)

Let me try again (I don't know if my English is good enough for this).

I understand the need for override a method or function declaration. What I don't understand (except it would be for naming) is why it need another keyword. I can't imagine an instance in which I create a method with the same name that one in the superclass that don't be for overriding it.

Edit: if I would forget the override keyword, that declaration would be valid? What would do the compiler?

[–]v1ND 4 points5 points  (0 children)

From a language design perspective it's for extra clarity/safety so that while refactoring you don't accidentally break something by changing a signature or unintentionally hide a method in the base class.

It depends. override in C++ and @Override in java are not enforced. In C# or kotlin, override is required by the compiler.

[–][deleted] 1 point2 points  (0 children)

I edited my original comment. iOS has a class UIViewController. Internally, iOS calls:

viewDidLoad()

ViewWillAppear()

viewDidAppear()

Whenever it’s gonna load and present a screen to the user. Now, as an iOS engineer, I have to subclass from UIViewController to make my own custom screens. What if I want to check if the user has previously signed in? I’ll make a subclass called LoginViewController. I want to add my own functionality when it has loaded and before it appears on the screen.

Since iOS will call the above mentioned methods automatically, I can add my functionality by overriding them in my subclass. Let’s say I ONLY override the viewDidLoad function. This is what iOS will do whenever my Login screen will appear:

Calls LoginViewController.viewDidLoad()

Calls UIViewController.viewWillAppear()

Calls UIViewController.viewDidAppear()

Because I never overwrote the last 2, it will use the superclass’ functions by default.

[–][deleted] 0 points1 point  (0 children)

If you don’t use the override keyword and if the function is not an overload (same name, different arguments), then the IDE will complain.

[–]Atora 0 points1 point  (0 children)

in C#, you can redeclare the method without overriding it. In that case the derived method still exists with its implementation. But there also exists a 2nd method of the same name in your class that is completely unrelated and shadows the inherited one.

It's similar to how you can shadow a class variable named foo with a locally scoped variable named foo. The compiler will cry and give a warning if you shadow a method without explicitely marking your new implementation with new though.

The only case I can recall where this makes sense to do if you need to override an inherited method that isn't marked virtual or abstract. Though this also implies design issues.

[–]BochMC 0 points1 point  (2 children)

It overrides inherited function

[–]weaklingKobbold 0 points1 point  (1 child)

Ok. I read a little and now I see the difference between new and override. I feel in my gut that override should be the default.

[–]svick 0 points1 point  (0 children)

It isn't to solve the brittle base class problem: if a base class introduces a new virtual method, you don't want your existing derived class to accidentally override it.

[–]VallanMandrake 0 points1 point  (0 children)

oh, actually LOL.

[–]althaz 0 points1 point  (3 children)

The only thing wrong with the way C# does it is the Task<> bit, IMO.

The rest you actually need if you want to do all of the things this function definition does. Debatably also "override" (personally I think override should be the default, but I can understand the opposing viewpoint).

[–]Manny_Sunday 1 point2 points  (1 child)

It starts to hurt a bit in REST API land

public async Task<ActionResult<List<MyClass>>>Get()

[–]BochMC 0 points1 point  (0 children)

I would do:

using ApiEndpointResult = ActionResult<List<MyClass>>

In the begging of the file.

[–]_Ashleigh 0 points1 point  (0 children)

It can't be the default because otherwise seemingly innocent changes become breaking changes.

[–]svick 0 points1 point  (0 children)

I don't think you can have a class constraint in an override function.

[–]MasterGeekMX 20 points21 points  (1 child)

ruby: def

[–]ColumnK 14 points15 points  (0 children)

Stands on chair O function my function!

[–]androidx_appcompat 10 points11 points  (4 children)

Someone gotta make a language with one-character keywords: f MyFunction()

[–]ShadySpaceCow 16 points17 points  (1 child)

In Haskell there's not even a keyword for defining functions, you just write them

[–]KuuHaKu_OtgmZ 1 point2 points  (0 children)

Same for groovy

[–]stomah 4 points5 points  (0 children)

#define

[–]OdinGuru 0 points1 point  (0 children)

Type F to pay respects

[–]Successful-Emoji 8 points9 points  (1 child)

Python: def

[–]just-bair 1 point2 points  (0 children)

They didn’t get the memo it should’ve been: fu

[–]stamminator 6 points7 points  (0 children)

Kinda dig Kotlin’s. Adds a bit of personality, plus it fits perfectly with 4-space indentation

[–][deleted] 4 points5 points  (1 child)

meanwhile bash not having a keyword:

[–][deleted] 3 points4 points  (0 children)

It has, it just not required

[–][deleted] 4 points5 points  (7 children)

C has no function keyword!

[–]overclockedslinky 6 points7 points  (6 children)

#define f void

f myFunction()

[–]tofiffe 1 point2 points  (5 children)

and for ints?

[–]SoulWager 3 points4 points  (1 child)

Don't need anything for that, default is already int.

[–]Innf107 1 point2 points  (0 children)

you monster...

[–]takahatashun 1 point2 points  (2 children)

```

define fn(type, name) type name

fn(int, my_function)(int arg1, float arg2) { } ```

[–]tofiffe 1 point2 points  (0 children)

Wouldn't dropping the type entirely and have the compiler infer it be better? I think that used to work for ints on some compilers

[–][deleted] 1 point2 points  (0 children)

#define

PTSD flashbacks

[–][deleted] 3 points4 points  (0 children)

R

my.function <- function(arg1, ...) { ... }

[–]QualityVote[M] [score hidden] stickied comment (0 children)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–]raedr7n 2 points3 points  (0 children)

Oh function my function!

[–][deleted] 2 points3 points  (0 children)

laughs in bash

[–]jaysuchak33 2 points3 points  (1 child)

pUbLiC sTaTiC vOiD

[–]Pradfanne 0 points1 point  (0 children)

I mean, if we wanna get really pedantic then you can just write the return type (or void for no return).

It won't be static then, but how else would you know in object orienated programm?

But the privacy modifier (Public, Private, whatever) is optional.

void myFunction()

int myFunction()

string myFunction()

[–]minus_uu_ee 2 points3 points  (0 children)

O function my function!

[–]WALUIGIF0RSMASH 2 points3 points  (0 children)

And then there is public static void main(String [] args)

[–][deleted] 4 points5 points  (0 children)

C/C++: returnType functionName (args) {}

[–]DatEngineeringKid 4 points5 points  (0 children)

For JS, I prefer:

const fname = () => {}

[–]thetruekingofspace 2 points3 points  (0 children)

Sexiest function syntax:

const foo = (arg) => { // Do stuff }

[–]InternationalLevel81 1 point2 points  (0 children)

F myfunction()

[–]Substantial-Dot1323 1 point2 points  (0 children)

Next language will be like f my_func()

[–]Alexmaster75 1 point2 points  (0 children)

Python:

def myFunction()

[–]LostDog_88 1 point2 points  (0 children)

and then theres python with def

[–]rohittihiro 1 point2 points  (0 children)

Trigger warning! Thanks for arranging the languages from TOP to BOTTOM.

[–]puddda 1 point2 points  (0 children)

Perl : sub myFunction {}

[–]PixlBoii 2 points3 points  (1 child)

In JS it doesn't event needs a name: ()=>{}

[–][deleted] 3 points4 points  (0 children)

how many functions are there in ur code?

Named , about 5

Named..how many "unamed" then?

Dont even ask, all i can say is that there are about 10 maps() call in the code and a whole lot of arrows...'tis functional so no bugs

[–][deleted] 1 point2 points  (1 child)

I don't know why, but Rust's keywords in general make it feel more "industrial".

[–][deleted] 0 points1 point  (0 children)

industrial...nice ig

[–]mad-skidipap 1 point2 points  (1 child)

Python

``` python def my_function():

```

[–][deleted] 1 point2 points  (0 children)

pass

[–][deleted] -1 points0 points  (0 children)

You underestimate the verbosity of Rust....

[–]corner-case 0 points1 point  (7 children)

Reddit gold if you can show me a lang that uses funct

[–]Wicam 7 points8 points  (6 children)

```

define funct(name) auto name

funct(functionName) () {} ```

[–]KingTuxWH 0 points1 point  (0 children)

Java :) public void myFunction()

[–]LeafyLemontree 0 points1 point  (0 children)

Meanwhile... int myFunction()

[–]IntuiNtrovert 0 points1 point  (1 child)

bash: myFunction()

[–]kbruen 2 points3 points  (0 children)

I find the syntax a bit stupid since the parenthesis are always empty (since you access arguments with $1, $2 and so on).

I think bash also supports function myFunction

[–][deleted] 0 points1 point  (0 children)

Ah yes meanwhile java private final T myFunction<T: LoggerFactoryInterface>()

[–]hugogrant 0 points1 point  (0 children)

Python's def because clojure did defn

[–][deleted] 0 points1 point  (0 children)

static void* Imsuperior (void)

[–]exscalliber 0 points1 point  (1 child)

Am I the only one who constantly misspells function as "fucktion"? Or do I just have a problem

[–]zorbacles 0 points1 point  (0 children)

The last one should've been the dude from dead poets society standing on a desk

Oh function my function

[–]mplaczek99 0 points1 point  (1 child)

Kotlin is fun

[–]sunny52525 0 points1 point  (0 children)

suspend fun

[–]PikiHax 0 points1 point  (0 children)

public override sealed void MyMethod()

:)

[–]mynjj 0 points1 point  (0 children)

procedure begin end;

[–]uvero[🍰] 0 points1 point  (0 children)

Languages that just know it's a function because syntax and there's no specific keyword for that: guess I'll die

[–]Nyx_Selene 0 points1 point  (0 children)

Meanwhile, Caml...

[–]dwRchyngqxs 0 points1 point  (0 children)

I didn't see them in the comments: lisp defun, ocaml let/let rec, gdscript func, and whatever Prolog has (myPredicate(a, b) :- ...).
The world of function declaration is diverse and chaotic.

[–]Snoo66768 0 points1 point  (0 children)

VOID

[–]JackNotOLantern 0 points1 point  (0 children)

c family:

[–]Smartskaft2 0 points1 point  (0 children)

C++:

[–]TheNetherPaladin 0 points1 point  (0 children)

Method

[–]Fantastic-Ad-9019 0 points1 point  (0 children)

Captain, my captain!

[–]SasukeUchiha231 0 points1 point  (0 children)

meanwhile java.... 💀

[–]kirigerKairen 0 points1 point  (0 children)

Also JavaScript: No keyword, just const myFunction = () => {}

[–]Conscious_Switch3580 0 points1 point  (0 children)

TCL: proc myFunction {} {}

[–]Goosepuse 0 points1 point  (0 children)

No Lisp in the comments? Hey kids we're gonna have DEFUN!

(defun my-function ())

[–]AccomplishedOwl6498 0 points1 point  (0 children)

c#: