@monorail everyone is entitled to an opinion, even if their opinion is wrong

@monorail I like functional, but I choose to defer that potential branch of evaluation

@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 @00dani part of a flywheel? heck okay that's a wall of text im not awake enough for (checked dani's response)

@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?

@00dani @monorail i use class definitions for everything because it just makes finding things easier to me. but I'll have to cover this when I'm more awake.

@monorail @LottieVixen yep, that's exactly the thing i'm talking about :blobcat: objects are essentially just named tuples with lambdas in them, and prototypal oo pretty much leans into that

@00dani @LottieVixen so if i made a named tuple with lambdas in it where they're useful and defined classes where they're useful, i'm pretty much good then?

@monorail @LottieVixen yeah, totally

python's object model is actually pretty complex though (metaclasses are. a thing here too?)

tangent and bleh bit negative re prototype discussion 

@00dani @monorail im still strugging to understand and realisticly I probably wont understand this later nor be out of this demoralised feeling by the time i wake up but...thanks for trying to accommodate my lack of understanding.

tangent and bleh bit negative re prototype discussion 

@LottieVixen @00dani it's okay i also am having a hard time getting it

re: tangent and bleh bit negative re prototype discussion 

@monorail @00dani boils down to, Ive been using class based as long as I can remember, why would I switch to prototyping and the hassle of learning it?. . i think

but also every time i get into a programming discussion on fedi it quickly gets over my head and i feel small in a bad way.

@LottieVixen @00dani a tuple is a collection of stuff. it's like a list that doesn't do as much, so it's simpler

a lambda is basically a function literal

in python, these two lines of code do (basically) the same thing

def f(x): return x*2
f = lambda x: x*2

@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 @IceWolf @00dani @LottieVixen python draws a distinction between "closures" and "lambdas" for mostly bad and historical reasons. It's not something replicated in other languages.

@riking @IceWolf @LottieVixen @00dani my understanding of what a closure is comes from javascript

what is a closure

...what do you call the thing i'm talking about

@monorail your understanding is good!

If I was trying to be formal, I would say... a piece of code (the inner function body) bundled together with some dynamically created variable definitions (variables from the outer scope that the function references).

you will notice that this definition plainly describes how JS implements them. But it also satisfies what Java does with `implements Runnable` - a Java class with fields can be an explicit closure!

@monorail @riking @IceWolf @LottieVixen
i think part of the problem is that although nearly every language that supports it talks about closure as though it's some kind of in-language object (having a "closure" type, talking about how it supports "closures", etc.), it's really not one

closure is a property that functions have in most languages: when defined inside another function, they automatically "close over" the variables from that local scope and retain access to the scope even after the containing function has returned

the thing that's called "a closure" is usually an anonymous function. in the python example, it's a named function, because python's anonymous functions are deliberately very limited. either way, it's really a function

@monorail @00dani @LottieVixen That's partial application I think? I've never really done it.

That's one use for a closure, but not one I see a whole lot.

@monorail @00dani @LottieVixen Mostly I see it used in like, callbacks.

[weird mashup of Swift and JS, sorry]

doSomething(callWhenFinished: function(x) {
// stuff

@IceWolf @monorail @00dani @LottieVixen Closures are anonymous[*] functions that capture their environment. But often you only care about the capturing, not the anonymity (in which case you can use a regular function in languages where regular functions also capture); or you only care about the anonymity, not the capturing.

@monorail, you focused more on the capturing; and @IceWolf, you focused more on the anonymity.

@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!!

Show newer
Show newer

@00dani this is necro'ing an old thread but im just trying to understand this in ways that i get it.

is this kind of how lisp handles "generics" and "methods" via specializers on objects?

@monorail i view oop as orthogonal to imperative/functional since they can totally coexist

especially since an object is literally just a function with a dispatcher


fight fight mrawr >:3
nuu XD

i made a language which is both object-oriented and not object-oriented 8>

everything is like static functions (in Java/Python terminology), there is no a.foo() only foo(a) !

but some static functions try looking inside their first parameter if it's a "special hashmap" (an "Object") and if it has a the static function's full (long) name mapped to a value, it executes that value.

if it does something otherwise, that's the "default implementation"! :D

that way, there's no worry about whether a function like "crossProduct" on "vectors" should be implemented as a utility function later on or built into the vector class/interface! :D

you can add a utility function like say, "determinant" for "matrix" after the fact, and it will work for original MatrixImpl implementations like any static utility function, but if you make it do that thing I said, then if someone makes a NewMatrixImpl class, they can override your static function! :D


then later I learned this is probably the same as the Common Lisp Object System that's older than I am! XDD

but I'm still happy I figured it out :3

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!