[RFC] traits-0.1.0

A

Ara.T.Howard

i'm having quite a time deciding what to do with traits. i first released as
'attributes' but some complained that

attribute 'foo'

and

class_attribute 'bar'

were just too long. to remedy that i switched to 'trait' - a synonym for
attribute. however, as it's been pointed out, that name currently has a
meaning in cs to some people. my current thoughts are

random thoughts for traits/against attributes:

- trait is short

- traits is a synonym for attribute (attr, attr_accessor, etc)

- i like the word 'role' to describe what others are calling traits. the
perl6 guys use this too so any future impl of 'traits' (the other ones)
as 'roles' wouldn't likely suprise anyone

- 'traits' (the other ones) are of dubious value to ruby. it's been shown
that they can be easily implemented in ruby - yet no one is using them.
their value, to me, seems largely academic and smells of
hyper-abstraction (read obfusication). however, i can easily imagine
situations where they might be extremely appropriate and wouldn't want
to steal the name. does anyone who might plan on needing it object to
using 'roles' for that concept?

random thoughts for attributes/against traits

- no confusion with other traits

- the alias 'has' can make 'attribute' plenty short (the current version
of traits uses this alias too btw.)

one other thing, the impl of traits was suprisingly hard. the tricky bit was
implementing defaults and inheritence in the general case of class methods,
instance methods, singleton methods (on objects not classes, and module
methods. the difficult bits revolved around being able to these things

singleton_super

class C
class << self
p singleton_super #=> C
end
end

class << []
p singleton_super #=> <#Array:1234567>
end

detecting singleton-ness

class C
p singleton? #=> false
class << self
p singleton? #=> true
end
end

p singleton? #=> false

class << []
p singleton? #=> true
end

deciding where to look for defaults

class A
trait 'x' => 42
end
class B < A
trait 'x' # clearly our default comes from A
end

module M
traits 'x' => 42
end
class C
include M # clearly our def AND default comes from A
end

a = []
class << a
trait 'foo' => 'bar' # our defaults must come from ourselves (no
# inheritence)
end

class A
class_trait 'x' => 42
trait 'x' => 'forty-two'
end
class B < A
# clearly get def and default of class x from A
# clearly get def and default of __instance__ x from A!
end

b = B::new
b.x = nil
p b.x # don't get default from A now!


anyhow - these are the kinds of confusing things anyone reading the code
will see being addressed.

and any code review would be appreciated. the code is pretty non-trivial and
un-commented - but it is brief. you'd need a complete understanding of
singleton (or whatever) classes to review it. one thing i plan on doing is
pulling alot of the __trait_XXX methods out of Object and into a specialized
module to avoid polluting the Object namespace : the current approach of
prefacing everything with __trait_XXX was just to get it working. feel free
to ping my offline.

any comments appreciated. sorry for confusion - i generally don't have a hard
time coming up with a decent name for a project but this one's stumped me.
people have expressed interest in me gem-izing traits so i'd like to pin it
down a bit before doing so.

kind regards.

ps. urls for project:

http://raa.ruby-lang.org/search.rhtml?search=traits
http://codeforpeople.com/lib/ruby/traits

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| renunciation is not getting rid of the things of this world, but accepting
| that they pass away. --aitken roshi
===============================================================================
 
I

Ilias Lazaridis

Ara.T.Howard said:
i'm having quite a time deciding what to do with traits. i first
released as 'attributes' but some complained that

attribute 'foo'

and

class_attribute 'bar'

were just too long. to remedy that i switched to 'trait' - a synonym
for attribute. however, as it's been pointed out, that name
currently has a meaning in cs to some people. my current thoughts
are

random thoughts for traits/against attributes:

- trait is short

and used within C++
- traits is a synonym for attribute (attr, attr_accessor, etc)

no need to use a synonym.

[...]
random thoughts for attributes/against traits

- no confusion with other traits
yes

- the alias 'has' can make 'attribute' plenty short (the current
version of traits uses this alias too btw.)
yes

one other thing, the impl of traits was suprisingly hard. the tricky
[...]

The code fragments (usage) I've saw are not thus attractive.

Code should looks simpler, more 'natural'.

-

This is an important project, but should be setup collaborative.

So, if you setup a ruby-forge project, people can contribute.

call it "attributes" or "attrib" or "has" - but not "traits".

..
 
A

Ara.T.Howard

and used within C++
hmm.


no need to use a synonym.

i mean it's meaning is the similar to 'attr :a == trait :a'.
[...]
random thoughts for attributes/against traits

- no confusion with other traits

yes

but are the other traits being used? also these seem to be called roles in
some langs too... this is a valid concern though.
- the alias 'has' can make 'attribute' plenty short (the current version of
traits uses this alias too btw.)
yes

one other thing, the impl of traits was suprisingly hard. the tricky
[...]

The code fragments (usage) I've saw are not thus attractive.

Code should looks simpler, more 'natural'.

what do you think could be more natural than

class C
has 'a' => 42
end

c = C::new
p c.a #=> 42

or

class AbstractWidget
class << self
has 'color'
has 'width'
has 'height'
end
end

class SmallishBlueWidget
color 'blue'
width 100
height 42
end

??

it's the best i could manage. come up with something more natural and i'll
see what i can do to implement.
This is an important project, but should be setup collaborative.

i'm working 70+ hours per week already - but if someone wants to take over and
do the initial setup work it's fine with me.
So, if you setup a ruby-forge project, people can contribute.

this is welcome of course - but see above.
call it "attributes" or "attrib" or "has" - but not "traits".

+1 for attributes then.

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| renunciation is not getting rid of the things of this world, but accepting
| that they pass away. --aitken roshi
===============================================================================
 
I

Ilias Lazaridis

i mean it's meaning is the similar to 'attr :a == trait :a'.

I mean: no mean to use (and search) a synonym
[...]
random thoughts for attributes/against traits

- no confusion with other traits

yes

but are the other traits being used? also these seem to be called roles in
some langs too... this is a valid concern though.

again: no need to research.
- the alias 'has' can make 'attribute' plenty short (the current
version of traits uses this alias too btw.)
yes

one other thing, the impl of traits was suprisingly hard. the tricky

[...]

The code fragments (usage) I've saw are not thus attractive.

Code should looks simpler, more 'natural'.


what do you think could be more natural than

class C
has 'a' => 42
end

class C
a = 42
end

class C
var a = 42
end
c = C::new
p c.a #=> 42

or

class AbstractWidget [...]

class SmallishBlueWidget
[...]

I dislike all this, but cannot clarify why.

concept, ruby, flexibility
it's the best i could manage. come up with something more natural and i'll
see what i can do to implement.


i'm working 70+ hours per week already - but if someone wants to take
over and do the initial setup work it's fine with me.

I think you should postpone this project.
this is welcome of course - but see above.


+1 for attributes then.

ok

..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top