#C doesn t just let you declare functions
1 messages · Page 1 of 1 (latest)
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)
Python is really the odd one out of the modern languages that actually has first order functions
ok, that is new to me. I was just wondering where the hell I could just define a function
isn't that a separate idea
functions just being objects
C does that too
modern
it's been a long time, but I do remember just writing functions
C certainly doesn't have functions as first-class citizens :p
you'll take a pointer and you'll like it
Technically separate, but also connected.
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
ah, true
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#?
You can't define named functions by themselves, yes
so it's a static method so it actually does behave as a lone function that doesn't fuck with anything
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
But, notably, can access private members of that class if they have a reference. Thats what makes a static method different than a function
Right.
I always get surprised when private members are accessed from anything other than this
It feels weird.
is "this" the same as self?
incidentally, the simplest definition of a static method is that it doesn't have this
this is a reference to the object the method is running on
thus, it only exists in non-static methods
Yes, but you don't need to implicitly pass it to functions like you do with self in python
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"
Yes