Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Classes Suck. ROLES are the new best thing

Name: Anonymous 2010-09-09 15:09

quote:

Roles in Perl 6 take on the function of interfaces in Java, mixins in Ruby, and traits[26] in the Smalltalk variant Squeak. These are much like classes, but are entirely abstract. These are used to perform composition when used with classes rather than adding to their inheritance chain. Roles define nominal types; they provide semantic names for collections of behavior and state. The fundamental difference between a role and a class is that classes are instantiable; roles are not.[27]

Essentially, a role is a bundle of (possibly abstract) methods and attributes that can be added to a class without using inheritance. A role can even be added to an individual object; in this case, Perl 6 will create an anonymous subclass, add the role to the subclass, and change the object's class to the anonymous subclass.

For example, a Dog is a Mammal. Dogs inherit certain characteristics from Mammals, such as mammary glands and (through Mammal's parent, Vertebrate) a backbone. Dogs may have one of several distinct types of behavior; for example, a Dog may be a Pet, a Stray, or a Guide for the blind. However, these are simply sets of additional behaviors that can be added to a Dog; a Cat can equally be a Pet or Stray, for example. Hence, Dog and Mammal are classes, while Pet, Stray, and Guide are roles.
 class Mammal is Vertebrate {
     . . .
 }
 class Dog is Mammal {
     . . .
 }
 role Pet {
     . . .
 }
 role Stray {
     . . .
 }
 role Guide {
     . . .
 }

Roles are added to a class or object with the does keyword, as opposed to inheritance's is. The keywords reflect the differing meanings of the two features: role composition gives a class the behavior of the role, but doesn't indicate that it is truly the same thing as the role.
 class GuideDog is Dog does Guide {
     . . .
 }   # Subclass composes role
 
 my $dog = new Dog;
 $dog does Guide;                         # Individual object composes role

Although roles are distinct from classes, both are types, so a role can appear in a variable declaration where one would normally put a class. For example, a Blind role for a Human could include an attribute of type Guide; this attribute could contain a Guide Dog, a Guide Horse, a Guide Human, or even a Guide Machine.
 class Human {
     has Dog $dog;                        # Can contain any kind of Dog, whether it does the
     ...                                  # Guide role or not
 }
 role Blind {
     has Guide $guide;                    # Can contain any object that does the Guide role,
     ...                                  # whether it is a Dog or something else
 }

Name: Anonymous 2011-04-06 22:24

>>80
U MENA HASKAL

Name: Anonymous 2011-04-06 23:22

So Perl now has aliased mixins to ``roles'', just like Ruby aliased them to ``modules''.

[b][i][o]Fascinating.[/b][/i][/o]

Name: Anonymous 2011-04-06 23:29

>>82
Who needs mixins, if instead of `objects` we can use lists? This mathematical OOP bullshit is just plainly retarded. Fuckin jews and their Set Theory...

Name: Anonymous 2011-04-06 23:32


'(dog (roles mammal pet stray guide))

It's that simple.

Name: Anonymous 2011-04-06 23:39

Perl sucks.

Sincerely yours,
Anonymous

Name: Anonymous 2011-04-06 23:55

perl sucks. long live perl.

Name: Anonymous 2011-04-07 6:41

I thought, roles/interfaces were a fix for missing multiple inheritance.
If you have multiple inheritance as in perl 6, what exactly can you do with roles that you can't already do with classes?

Name: Anonymous 2011-04-07 10:46

Multiple inheritance is cool if you want to lose your temper and hair.

Name: Anonymous 2011-04-07 10:53

SPAM INHERT MULTIPLE CLASSES FOR THAT REFRESHING MADNESS

Name: Anonymous 2011-04-07 13:31

U MENA TYPECLASSES

Name: Anonymous 2011-04-07 13:50

>>88
Too close to home.

Name: Anonymous 2011-04-07 18:11

>>90
SPAM DERIVE TYPECLASSES FOR THAT REFRESHING MONADS

Name: Anonymous 2011-10-06 18:01

>>82
And Scala calls it "traits"

Name: HAXUS THE SAGE 2011-10-07 0:29

Not /prog/ related. GTFO!

Name: Anonymous 2011-10-07 1:44

YOU MENA HASH TABLE

Name: Anonymous 2011-10-07 1:53

>>10
so they're closures.

I thought Perl already had those.

Name: Anonymous 2011-10-07 2:04

I was excited for Perl6, but its never coming out.

PHP5.4 has traits.

Name: Anonymous 2011-10-07 2:15

>>96
wtf are you smoking?

Name: Anonymous 2011-10-07 2:25

>>96

back to /g/!

back to /b/!

Name: Anonymous 2011-10-07 3:12

>>98
>>99

Roles, then, are a collection of states and behavoirs, than can be attached or removed from objects in runtime.

closures in mutable hash tables. How are they different?

Name: Anonymous 2011-10-07 3:22

>>100
They have composition and dispatch for two. They apply to types (and instances) and also cause changes relevant to the type system. They're completely abstract.

Name: :D 2011-10-07 12:12

Mixin based programming in C++

http://www.cs.umass.edu/~yannis/practical-fmtd.pdf




Roles are here to stay.

Name: Anonymous 2011-10-07 13:14

>>101
you can't compose closures
wat

they have type dispatch
which is overrated.

they cause changes relevant to the type system
why do you need a type system?

closures aren't abstract
uh huh.

seriously don't see what about roles you can't do more simply and with fewer buzzwords with closures, hash tables, and Lua metatables.

Name: Anonymous 2011-10-07 13:46

>>103
Not a single accurate quote.

But since you're a retarded Lua person I'll just point out that prototype-OO (the kind Lua has) is a completely different bag of dicks.

why do you need a type system?
I don't need one any more than you need an object system. I sure love having one though.

Name: Anonymous 2011-10-08 1:35

hhere's my p6 thread

Name: Anonymous 2011-10-08 4:42

multiple inheritance.
/thread

Name: Anonymous 2012-01-12 17:28

>>106
multiple inheritance is a disease

roles are the cure

Name: Anonymous 2012-01-12 17:31

weeabo shit is the disease

penis is the cure

Name: Anonymous 2012-01-12 18:28

lithper anus is the disease

penis is the cure

Name: Anonymous 2012-01-12 18:59

who the fuck even uses perl anymore? it's for old men.

Name: Anonymous 2012-01-12 19:18

Treb role

Name: Anonymous 2012-02-16 8:24

>>1
PHP 6 will have this too.

Accept it... this shit is THE FUTURE

Name: Anonymous 2012-02-16 16:18

autism is the disease

jews are the cure

Name: Anonymous 2013-04-01 19:12

bump just because

Name: Anonymous 2013-04-01 19:32

Name: Anonymous 2013-04-01 19:47

bump my anus

Name: Anonymous 2013-04-01 23:23

jews are the disease
extermination is the cure

Name: Anonymous 2013-04-02 1:06

"roles"

do you mean methods and attributes, fuckface? what you're proposing is making my code harder to understand that this spaghetti deaghuujmj shit already is

Name: Anonymous 2013-04-02 19:54

extermination is the disease
im the cure

Name: Anonymous 2013-04-02 20:47

roles/traits are cool. i use them all the time.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List