#C doesn t just let you declare functions

1 messages · Page 1 of 1 (latest)

runic cloak
#

well, there are "top level statements", but you don't really use those in Unity

#

I also don't think you can define methods out there

#

Java is very similar. AFAIK you can only define methods in classes.

#

(well, a "method" is, by definition, a function that's a member of a class)

peak vine
#

Python is really the odd one out of the modern languages that actually has first order functions

neon cipher
#

ok, that is new to me. I was just wondering where the hell I could just define a function

runic cloak
#

functions just being objects

peak vine
neon cipher
#

it's been a long time, but I do remember just writing functions

runic cloak
#

C certainly doesn't have functions as first-class citizens :p

#

you'll take a pointer and you'll like it

peak vine
#

Everything in an object-oriented language is an object, so functions being able to be objects means they don't have to be members of objects

runic cloak
#

ah, true

neon cipher
#

right, I forgot python did something like that

#

so if I get this right, Instantiate is a method, because functions can't not be methods in C#?

runic cloak
#

You can't define named functions by themselves, yes

neon cipher
#

so it's a static method so it actually does behave as a lone function that doesn't fuck with anything

runic cloak
#

static methods cannot access any non-static members of their class

#

and they are accessed from the type name, not from an instance of the type

peak vine
runic cloak
#

Right.

#

I always get surprised when private members are accessed from anything other than this

#

It feels weird.

neon cipher
#

is "this" the same as self?

runic cloak
runic cloak
#

thus, it only exists in non-static methods

peak vine
neon cipher
#

gotcha. I was wondering

#

so if I call a named function, it has to be a method. And if there is nothing before it to show what it is a method of, C# will assume it is a method of "this"

peak vine
#

Yes