{"id":3804,"date":"2014-03-30T05:44:52","date_gmt":"2014-03-30T05:44:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-traits-collection-of-common-programming-errors\/"},"modified":"2014-03-30T05:44:52","modified_gmt":"2014-03-30T05:44:52","slug":"problem-about-traits-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-traits-collection-of-common-programming-errors\/","title":{"rendered":"problem about traits-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/95b165d3e2b7599b9d9ce46fecc200f6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser2646065<br \/>\npython matplotlib qt4 traits<br \/>\nI&#8217;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&#8217;m porting the GUI from a MATLAB script it made sense to use Matplotlib, with all the similar commands and whatnot.Since there isn&#8217;t a standard matplotlib traits editor so far as I can tell, I&#8217;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 (<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/MGhY2.png?s=32&amp;g=1\" \/><br \/>\nhakre<br \/>\nphp traits<br \/>\nI am trying to learn traits. I have used the example from PHP manual, but it does not work &#8211; 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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/99108829176dfbbc5d0bf3c041542a26?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPablo Fernandez<br \/>\nscala traits<br \/>\nI have a class which source I cannot modify:class Foo {def bar() = println(&#8220;bar&#8221;)}And a trait I&#8217;d like to mix into it at runtimetrait Zee { this: Foo =&gt;abstract override def bar() = {println(&#8220;before bar&#8221;)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 &#8216;before bar&#8217; and then &#8216;bar<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/939cc882ebaf28150d4f716b933d5960?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nstevenl<br \/>\nperl moose traits<br \/>\nLet&#8217;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 &#8216;MooseX::Traits&#8217;; sub foo {print &#8220;foo\\n&#8221;}package Bar; use Moose::Role; sub bar {shift-&gt;foo; print &#8220;bar\\n&#8221;; }package Baz; use Moose::Role; requires &#8216;bar&#8217;; sub baz {shift-&gt;bar; print &#8220;baz\\n&#8221;; }package main; my $foo = Foo-&gt;new_with_traits( traits =&gt; [qw\/Bar Baz\/] ); $foo-&gt;baz;In this example, I&#8217;ve enforced the dependency with requires &#8216;bar&#8217;. However, what I w<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/039d0df2ad0bdee4c506943c79bf70c3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMichael<br \/>\nscala traits<br \/>\nThe Cake Pattern article suggests using traits as namespaces:trait UserRepositoryComponent { val userRepository: UserRepository class UserRepository {&#8230;} }trait UserServiceComponent {this: UserRepositoryComponent =&gt; val userService: UserService class UserService {&#8230;} }class Context extends UserServiceComponent with UserRepositoryComponent { val userRepository = new UserRepository val userService = new UserService } However do we really need these &#8220;namespace traits&#8221; (UserServiceCom<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/4f60c49939f461f958a8b417ee26e017?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNYCBrit<br \/>\nscala new-operator instance traits<br \/>\nI&#8217;m trying to create an instance of a trait using this methodval inst = new Object with MyTraitThis works well, but I&#8217;d like to move this creation in to a generator function, ie.object Creator {def create[T] : T = new Object with T }I&#8217;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?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/daacb6d0a16d95a3858ccae59b44860d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPedro Morte Rolo<br \/>\nscala traits<br \/>\nI 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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d3cdea356895d34f120aa776a2f4fd1c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nThomas Lauria<br \/>\nphp traits<br \/>\nSimple question, is it possible to dynamically add traits to a php class in runtime without using eval?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9359760602e36ed0e43ff61a14f1812d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nom-nom-nom<br \/>\nscala reflection traits mixing scala-java-interop<br \/>\nI 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&#8217;t know how ? Thanks f<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7ce8659c80a409459e933e47701a398b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRalf<br \/>\nscala traits<br \/>\nIn 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.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/20d1630aeed952b78c3e4c609a48c0fa?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\narnaudrg<br \/>\nphp traits<br \/>\nI&#8217;m using MAMP with PHP 5.4.10 and I have a problem with the following MWE:&lt;?php trait T {public function hello() { echo &#8216;hello&#8217;; } } class A {use T; } $a = new A(); $a-&gt;hello(); ?&gt;The page shows &#8216;hello&#8217; 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, &#8216;hello&#8217; shows up again. Hit refresh again, and the Error 500 is back.Any clue where this might be coming from?Update:This sho<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1558b76ef320cdf23b0a9c255db65cc0?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMyStream<br \/>\nphp class eval traits<br \/>\nI 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:&lt;?php function new_item_class($type) {eval(&#8216;class Item_&#8217;.ucfirst($type).&#8217; extends Item_Driver { use tItem_Epic, tItem_Weapon; }&#8217;); } ?&gt;This is an example. There are some more parameters that change the course of eval (like: item quality, etc.).Does t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/33f960bc2654014d3c8e1ab593d20497?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nTinku<br \/>\njavascript prototype traits<br \/>\nHow can I implement traits in javascript ?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d9ae7aef22bea38dbf6a3f98789b4cc4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser833970<br \/>\nscala traits scala-2.10<br \/>\nI want to make the following example so that Collar is immutabletrait Collar{var text:String=&#8221;&#8221;;}class dog(val name:String){def bark()= &#8230;}val snoopy = new dog(&#8220;snoopy&#8221;) with Collar;snoopy.text=&#8221;charley&#8217;s dog&#8221;;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&#8217;t care when it has a Collar.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8d73ca4ca73d8d4f42ca86074d6cf068?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFred Haslam<br \/>\ngenerics scala factory traits<br \/>\nI 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 &#8216;new T()&#8217; doesn&#8217;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 &#8216;new T()&#8217; so that I can create my super simple fact<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/34a08f16b54a72bf2f54cae569a94835?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGeorg Fritzsche<br \/>\nc++ templates g++ traits<br \/>\nA colleague of mine told me about a little piece of design he has used with his team that sent my mind boiling. It&#8217;s a kind of traits class that they can specialize in an extremely decoupled way.I&#8217;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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e5d70b07efe98c43d8bdb01c0431f825?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBill<br \/>\nobjective-c traits mixins<br \/>\nAre 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 = &#8230;def reloadData = &#8230;def elementAtIndex = &#8230; }trait ControllerWithStandardToolbar {def buildToolbar = &#8230;def showToolbar = &#8230;def hideToolbar = &#8230; }class MyTableController extends ControllerWithData with ControllerWithStandardToolbar {def loadView = {super.loadViewloadDatabuildBar} }It&#8217;s basically a way to combine (or mix in) mult<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>user2646065 python matplotlib qt4 traits I&#8217;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&#8217;m porting the GUI from a MATLAB script it made sense to use Matplotlib, with all the similar commands and whatnot.Since [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3804","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3804"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3804\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}