problem about traits-Collection of common programming errors


  • user2646065
    python matplotlib qt4 traits
    I’m building a GUI using Python 2.7, Matplotlib version 1.2.1, QT4 4.9.6. The goal is to be able to load images, rescale them, and perform other small manipulations. Since I’m porting the GUI from a MATLAB script it made sense to use Matplotlib, with all the similar commands and whatnot.Since there isn’t a standard matplotlib traits editor so far as I can tell, I’ve used this article to help build the editor. Everything works just fine in Spyder 2.2.0, but in Eclipse I get an 18-item traceback (

  • hakre
    php traits
    I am trying to learn traits. I have used the example from PHP manual, but it does not work – why?trait ezcReflectionReturnInfo {function getReturnType() { /*1*/ }function getReturnDescription() { /*2*/ } }class ezcReflectionMethod extends ReflectionMethod {use ezcReflectionReturnInfo;}class ezcReflectionFunction extends ReflectionFunction {use ezcReflectionReturnInfo;}I get the error:Parse error: syntax error, unexpected T_STRING in /path/index.php on line 23

  • Pablo Fernandez
    scala traits
    I have a class which source I cannot modify:class Foo {def bar() = println(“bar”)}And a trait I’d like to mix into it at runtimetrait Zee { this: Foo =>abstract override def bar() = {println(“before bar”)super.bar()} }This is throwing that bar is not a member of Object with ScalaObjectWhat am I doing wrong? Is it possible to achieve this without modifying Foo source?The ultimate client code needs to look like this:val foo = new Foo with Zee foo.bar() // should print ‘before bar’ and then ‘bar

  • stevenl
    perl moose traits
    Let’s say I have a class Foo with plugin traits/roles Bar and Baz, where Baz is dependent on Bar. package Foo; use Moose; with ‘MooseX::Traits’; sub foo {print “foo\n”}package Bar; use Moose::Role; sub bar {shift->foo; print “bar\n”; }package Baz; use Moose::Role; requires ‘bar’; sub baz {shift->bar; print “baz\n”; }package main; my $foo = Foo->new_with_traits( traits => [qw/Bar Baz/] ); $foo->baz;In this example, I’ve enforced the dependency with requires ‘bar’. However, what I w

  • Michael
    scala traits
    The Cake Pattern article suggests using traits as namespaces:trait UserRepositoryComponent { val userRepository: UserRepository class UserRepository {…} }trait UserServiceComponent {this: UserRepositoryComponent => val userService: UserService class UserService {…} }class Context extends UserServiceComponent with UserRepositoryComponent { val userRepository = new UserRepository val userService = new UserService } However do we really need these “namespace traits” (UserServiceCom

  • NYCBrit
    scala new-operator instance traits
    I’m trying to create an instance of a trait using this methodval inst = new Object with MyTraitThis works well, but I’d like to move this creation in to a generator function, ie.object Creator {def create[T] : T = new Object with T }I’m obviously going to need the manifest to somehow fix the type erasure problems, but before I get to this, I run in to 2 questions :Even with an implicit manifest, Scala still demands that T be a trait. How do I add a restriction to create[T] so that T is a trait?

  • Pedro Morte Rolo
    scala traits
    I would like to know if having an instance to which a trait has been added to in runtime, it is possible to remove the trait off the instance, so it can behave as originaly.Thanks, Pedro

  • Thomas Lauria
    php traits
    Simple question, is it possible to dynamically add traits to a php class in runtime without using eval?

  • om-nom-nom
    scala reflection traits mixing scala-java-interop
    I need to get all the interfaces at runtime from a given Class (all loaded in a ClassLoader).For instance, if a class has been declared this way :trait B trait C trait D class A extends B with C with DI want to get this information at runtime : A depends on B and C and D. The java getInterfaces() (or the interfaces() from the clapper library) methods gives only the first dependency, namely: A depends on B. Is there a way to achieve that ? I guess by reflection but I don’t know how ? Thanks f

  • Ralf
    scala traits
    In Scala, what is the advantage of using an abstract class instead of a trait (apart from performance)? At first glance it seems like abstract classes can be replaced by traits in most cases.

  • arnaudrg
    php traits
    I’m using MAMP with PHP 5.4.10 and I have a problem with the following MWE:<?php trait T {public function hello() { echo ‘hello’; } } class A {use T; } $a = new A(); $a->hello(); ?>The page shows ‘hello’ on the first load. But then, when I hit refresh, I get an Error 500.If I modify the file (just by adding an empty line somewhere for instance) and refresh again, ‘hello’ shows up again. Hit refresh again, and the Error 500 is back.Any clue where this might be coming from?Update:This sho

  • MyStream
    php class eval traits
    I want to make use of traits in my project, and for multiple inheriance I want to use traits.So I created some traits to use eg: tItem_Epic, tItem_Weapon, Item_DriverWhen I create new class for Sword, I thought I could use eval to create class:<?php function new_item_class($type) {eval(‘class Item_’.ucfirst($type).’ extends Item_Driver { use tItem_Epic, tItem_Weapon; }’); } ?>This is an example. There are some more parameters that change the course of eval (like: item quality, etc.).Does t

  • Tinku
    javascript prototype traits
    How can I implement traits in javascript ?

  • user833970
    scala traits scala-2.10
    I want to make the following example so that Collar is immutabletrait Collar{var text:String=””;}class dog(val name:String){def bark()= …}val snoopy = new dog(“snoopy”) with Collar;snoopy.text=”charley’s dog”;println(snoopy.text)However when I try something like trait Collar(val text:String){}I get the compile time errortraits or objects may not have parametersIs there currently a a way to do this? If not, why not?Remember, a good dog shouldn’t care when it has a Collar.

  • Fred Haslam
    generics scala factory traits
    I was playing with creating a generic factory as follows:trait Factory[T] { def createInstance():T = new T() } val dateFactory = new Factory[Date](){} val myDate = dateFactory.createInstance()The ‘new T()’ doesn’t compile, as T is undefined until runtime. I know that I can get it to work by passing in an instance of the class to some method (ie. createInstance(classOf[Date]) )I am asking if there is some introspection magic that could replace ‘new T()’ so that I can create my super simple fact

  • Georg Fritzsche
    c++ templates g++ traits
    A colleague of mine told me about a little piece of design he has used with his team that sent my mind boiling. It’s a kind of traits class that they can specialize in an extremely decoupled way.I’ve had a hard time understanding how it could possibly work, and I am still unsure of the idea I have, so I thought I would ask for help here.We are talking g++ here, specifically the versions 3.4.2 and 4.3.2 (it seems to work with both).The idea is quite simple:1- Define the interface// interface.h te

  • Bill
    objective-c traits mixins
    Are there any techniques for emulating traits or mixins in Objective-C?In Scala, for example, I can do something like this:trait ControllerWithData {def loadData = …def reloadData = …def elementAtIndex = … }trait ControllerWithStandardToolbar {def buildToolbar = …def showToolbar = …def hideToolbar = … }class MyTableController extends ControllerWithData with ControllerWithStandardToolbar {def loadView = {super.loadViewloadDatabuildBar} }It’s basically a way to combine (or mix in) mult

Web site is in building