@monorail it's good

most object-oriented languages are disappointing (why do they all use classes rather than prototypes) but the concept be good

@LottieVixen @monorail prototypes are just a fundamentally simpler way to structure objects

in your typical classical oo model, you have objects containing attributes, and those objects have a class which contains the methods you can perform on the object

it starts getting complicated when you think through more advanced features: do static attributes also live on the class? does that make it an object? where do static methods live that differentiates them from instance methods? what if you want to put custom methods on a particular object? where do traits fit into the hierarchy? etc.

ruby is classical and addresses those needs, but it does so by giving every object a hidden additional class called an "eigenclass". static and object-specific methods live in secret eigenclasses. it's weird

you can avoid that complexity by eliminating classes entirely. instead, you just have objects, and they have attributes. you don't need a separate structure to hold methods, because an attribute can trivially just contain a method. each object can be designated one or more prototypes, which simply means that if you can't find an attribute on an object, you check if the prototypes have it. that's it

base classes? prototypes. traits? also prototypes. statics? just live on a "class" object instead of an "instance" object. easy.

@00dani @LottieVixen that seems interesting theoretically but not useful practically

like you can argue about whether a class is itself an object but like. it works

maybe i'm misunderstanding but it seems like a more theoretically elegant and less practically useful approach

@monorail @LottieVixen it's more theoretically elegant and more practically useful in my experience? prototypal oo can trivially replicate classical oo yet is far more flexible in practice

for instance: you're guaranteed to be able to pass constructors around as parameters, so you don't need to define factories that more-or-less exist to wrap up constructors in objects? some classical languages do treat classes as objects anyway and also achieve this benefit, but many don't

additionally, one-off flyweight objects are super useful. take a look through pretty much any substantial amount of javascript and you'll find loads of them

even without multiple inheritance (which is sadly something js lacks), traits still work out fine since you can treat them as a pile of object-specific methods. obviously it's nicer if you can just use the trait itself as an additional prototype ofc, but the flexibility of prototypal oo means it's still possible without that option :blobcatblep:

overall there's really no functional disadvantage to using a prototypal model, it's conceptually simpler, and the flexibility is often valuable, so :blobcatgooglyshrug:

@00dani @LottieVixen I'm unconvinced about it being conceptually simpler because you just explained it to me and i still don't get it

@monorail @LottieVixen uh. that would be me misusing terminology apparently :ohno:

i meant a little one-off object used in a specific situation, such that an explicit class definition might be overkill. the kinds of things that js code uses all over the place?

@monorail @00dani and I am lost... I dunno what a tuple or lambda is eep.

@LottieVixen @monorail a named tuple is a python-specific thing which is basically like a struct or a javascript object

a lambda is another term for an anonymous function, since the idea of anonymous functions originated in lambda calculus. many languages, python included, actually use the keyword lambda to denote one

@00dani @LottieVixen @monorail I learned them as "closures" myself, because Swift.

I thiiink lambdas are closures, at least.

@IceWolf @00dani @LottieVixen i thought a closure was like

def closure(n):
def my_func(x):
return x*n

return my_func

f = closure(2)
f(5) # 10

@monorail @Felthry @IceWolf @LottieVixen
partial application is the ability to pass only some of the arguments to a function and get a new function that just needs the remaining arguments. currying is a particular technique for achieving partial application by having your function take just one argument at a time

you can also do partial application in other ways, depending on how arguments work in your language? for instance, if you have keyword arguments, you might do things a bit differently. i think python's got a partial function you can call that allows you to partially apply both positional and keyword args

the cute thing holly was doing was indeed an example of (manual) currying though, yes

@00dani @Felthry @IceWolf @LottieVixen python does have partial but it's not a builtin, it's in the standard library functools package

also how is that cute!!

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!