Blueberry icon indicating copy to clipboard operation
Blueberry copied to clipboard

Modules / Traits

Open gosukiwi opened this issue 10 years ago • 4 comments

I think traits / modules are awesome as they help you get the best out of dynamic typing. I'm not sure on the syntax though, PHP uses include and require keywords already, so using Include like in Ruby might be confusing. PHP uses the use keyword for this, which in my opinion might be better for our use case.

Beeing verbose is good sometimes, but maybe something like this would be nicer?

class MyClass
  +SomeModule, SomeOtherModule

  def some_method
    # ... etc
  end
end

Alternatively, we can just use the use keyword:

class MyClass
  use SomeModule, SomeOtherModule

  def some_method
    # ... etc
  end
end

I'm open to suggestions on the syntax and modules in general. I'd like to keep them simple for now. Also, this would only work on PHP 5.4+ unless we generate some ugly hacky PHP.

gosukiwi avatar Jan 10 '15 23:01 gosukiwi

Maybe import? Since you sort of import the methods. Or copy, since it's essentially compiler-assisted copy and paste.

hikari-no-yume avatar Jan 10 '15 23:01 hikari-no-yume

Yeah import is a good keyword. What do you think about the + though? Is is hard to read? It kind of reminds me of SASS :smile:

gosukiwi avatar Jan 10 '15 23:01 gosukiwi

I don't think it's sufficiently obvious what it does

hikari-no-yume avatar Jan 11 '15 00:01 hikari-no-yume

Yeah I don't want to end up like Perl. With variables such as $_ and @_. It's not like I cannot do both syntaxes though.

gosukiwi avatar Jan 11 '15 00:01 gosukiwi