<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Considering Performance in Object-Oriented MATLAB Code</title>
	<atom:link href="http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Wed, 08 May 2013 12:21:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Dave Foti</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33096</link>
		<dc:creator>Dave Foti</dc:creator>
		<pubDate>Fri, 22 Jun 2012 21:50:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33096</guid>
		<description><![CDATA[Hi Jan,

I assume your alternative with specific get methods is something like this:

classdef superClass
  properties (Access=private)
    state_data
  end
  properties (Dependent)
    state
  end
  methods
    function tf = get.state(obj)
      tf = getState(obj);
    end
  end
  methods(Access=protected)
    function getState(obj)
      tf = strcmp(obj.state_data, ‘Happy’);
    end
  end
end
classdef subClass &lt; superClass
  methods(Access=protected)
    function tf = getState(obj)
      tf = strcmp(obj.state_data, &#039;Sad&#039;);
    end
  end
end

I do see your point about not &quot;making it hard&quot; and I agree we could make improvements.  Sometimes enforcing rules makes some things easier but we want to do it in a way that doesn&#039;t make other things harder.  For example, if a superclass can guarantee what kinds of values may be returned by that property, it is easier to write general-purpose functions that use the superclass without knowing about all possible subclasses.  If changing a property to Dependendent and adding a get-function doesn&#039;t open up the property to reimplementation in subclasses, there is one less consideration for the superclass author making this change.]]></description>
		<content:encoded><![CDATA[<p>Hi Jan,</p>
<p>I assume your alternative with specific get methods is something like this:</p>
<p>classdef superClass<br />
  properties (Access=private)<br />
    state_data<br />
  end<br />
  properties (Dependent)<br />
    state<br />
  end<br />
  methods<br />
    function tf = get.state(obj)<br />
      tf = getState(obj);<br />
    end<br />
  end<br />
  methods(Access=protected)<br />
    function getState(obj)<br />
      tf = strcmp(obj.state_data, ‘Happy’);<br />
    end<br />
  end<br />
end<br />
classdef subClass &lt; superClass<br />
  methods(Access=protected)<br />
    function tf = getState(obj)<br />
      tf = strcmp(obj.state_data, &#039;Sad&#039;);<br />
    end<br />
  end<br />
end</p>
<p>I do see your point about not &#8220;making it hard&#8221; and I agree we could make improvements.  Sometimes enforcing rules makes some things easier but we want to do it in a way that doesn&#8217;t make other things harder.  For example, if a superclass can guarantee what kinds of values may be returned by that property, it is easier to write general-purpose functions that use the superclass without knowing about all possible subclasses.  If changing a property to Dependendent and adding a get-function doesn&#8217;t open up the property to reimplementation in subclasses, there is one less consideration for the superclass author making this change.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33095</link>
		<dc:creator>Jan</dc:creator>
		<pubDate>Fri, 22 Jun 2012 17:43:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33095</guid>
		<description><![CDATA[I find the inability to override getters of dependant properties in subclasses very frustrating.


classdef superClass
    properties (Access=private)
        state_data
    end
    properties (Dependent=true)
        state
    end
    methods
        function tf = get.state(obj)
            tf = strcmp(obj.state_data, &#039;Happy&#039;);
        end
    end
end

classdef subClass &lt; superClass
    methods
        function tf = get.state(obj)
           tf = strcmp(obj.state_data, &#039;Sad&#039;);
        end
    end
end

(sorry not really performance related)

To work around and get the type of behaviour I want means I have to write specific get methods. Yes I know there is risk in overriding set methods, but leave it to the programmer to Do It Right, rather than enforce rules that Make It Hard]]></description>
		<content:encoded><![CDATA[<p>I find the inability to override getters of dependant properties in subclasses very frustrating.</p>
<p>classdef superClass<br />
    properties (Access=private)<br />
        state_data<br />
    end<br />
    properties (Dependent=true)<br />
        state<br />
    end<br />
    methods<br />
        function tf = get.state(obj)<br />
            tf = strcmp(obj.state_data, &#8216;Happy&#8217;);<br />
        end<br />
    end<br />
end</p>
<p>classdef subClass &lt; superClass<br />
    methods<br />
        function tf = get.state(obj)<br />
           tf = strcmp(obj.state_data, &#039;Sad&#039;);<br />
        end<br />
    end<br />
end</p>
<p>(sorry not really performance related)</p>
<p>To work around and get the type of behaviour I want means I have to write specific get methods. Yes I know there is risk in overriding set methods, but leave it to the programmer to Do It Right, rather than enforce rules that Make It Hard</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vijay Iyer</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33080</link>
		<dc:creator>Vijay Iyer</dc:creator>
		<pubDate>Wed, 13 Jun 2012 15:04:56 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33080</guid>
		<description><![CDATA[We have been able to use Matlab OO quite successfully in our projects, though there definitely have been some hiccups along the way. The issue of needing to restart Matlab frequently when &#039;clear classes&#039; fails, as Hanan mentions, is definitely prevalent. I&#039;m not sure if the improved deletion logic seemingly added in 2012a may help there...I&#039;m still using 2011b for all of my projects.

I agree with the idea that the OO group needs a blog!]]></description>
		<content:encoded><![CDATA[<p>We have been able to use Matlab OO quite successfully in our projects, though there definitely have been some hiccups along the way. The issue of needing to restart Matlab frequently when &#8216;clear classes&#8217; fails, as Hanan mentions, is definitely prevalent. I&#8217;m not sure if the improved deletion logic seemingly added in 2012a may help there&#8230;I&#8217;m still using 2011b for all of my projects.</p>
<p>I agree with the idea that the OO group needs a blog!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hanan</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33052</link>
		<dc:creator>Hanan</dc:creator>
		<pubDate>Thu, 10 May 2012 08:05:43 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33052</guid>
		<description><![CDATA[I am a machine-learning team leader in my company. We considered to use OO in matlab for our new system. However we fill that OO is not mature enough in MATLAB. Especially because of bugs that happen when you change a class code. Sometimes clearing the instance doesn&#039;t help and neither the class or even clearing the whole work-space (&#039;clear classes&#039;). The only thing that make the object to update is to close MATLAB and reopen it. This is very annoying and makes debugging an impossible mission.
Moreover, if there are handles to functions inside the class (as properties) the saved class takes 100 times more disk space than if you convert it to string (why?!)
Hanan]]></description>
		<content:encoded><![CDATA[<p>I am a machine-learning team leader in my company. We considered to use OO in matlab for our new system. However we fill that OO is not mature enough in MATLAB. Especially because of bugs that happen when you change a class code. Sometimes clearing the instance doesn&#8217;t help and neither the class or even clearing the whole work-space (&#8216;clear classes&#8217;). The only thing that make the object to update is to close MATLAB and reopen it. This is very annoying and makes debugging an impossible mission.<br />
Moreover, if there are handles to functions inside the class (as properties) the saved class takes 100 times more disk space than if you convert it to string (why?!)<br />
Hanan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Foti</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33050</link>
		<dc:creator>Dave Foti</dc:creator>
		<pubDate>Thu, 03 May 2012 22:25:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33050</guid>
		<description><![CDATA[Hi Ian,
In R2012a and going forward, there should be almost no overhead for nesting objects in other object properties and no need to pull the property out into a temporary variable before using it.  If you repeat the indexed expression many times in a function, it might still be helpful to do the indexing once into a variable that is used in several places.

I should clarify the statement about obj.f(data) being slower than f(obj, data).  The overhead is higher for obj.f(data) but this will generally not be noticeable if the function execution time is significant so I can&#039;t say that you will notice a difference for any particular function.  The overhead is higher because of the way MATLAB currently interprets syntax involving dots.]]></description>
		<content:encoded><![CDATA[<p>Hi Ian,<br />
In R2012a and going forward, there should be almost no overhead for nesting objects in other object properties and no need to pull the property out into a temporary variable before using it.  If you repeat the indexed expression many times in a function, it might still be helpful to do the indexing once into a variable that is used in several places.</p>
<p>I should clarify the statement about obj.f(data) being slower than f(obj, data).  The overhead is higher for obj.f(data) but this will generally not be noticeable if the function execution time is significant so I can&#8217;t say that you will notice a difference for any particular function.  The overhead is higher because of the way MATLAB currently interprets syntax involving dots.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Andolina</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33049</link>
		<dc:creator>Ian Andolina</dc:creator>
		<pubDate>Tue, 01 May 2012 14:38:30 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33049</guid>
		<description><![CDATA[Hi, I often like to have objects embedded in normal properties of other objects (bike.wheel). These child objects themselves have properties (bike.wheel.nSpokes). Is there any additional overhead with nesting objects and retrieving properties, and is the best solution to copy the final property to a standard struct etc. and work on those each time, i.e. x = bike.wheel.rim.thickness; function(x)    VS.    function(bike.wheel.rim.thickness)

Also, I tried testing this:

 f(obj, data) is generally faster than using obj.f(data)

But saw no difference in my test. Why is it supposed to be faster, should I be using f(obj, data) as best practice irrespectively?]]></description>
		<content:encoded><![CDATA[<p>Hi, I often like to have objects embedded in normal properties of other objects (bike.wheel). These child objects themselves have properties (bike.wheel.nSpokes). Is there any additional overhead with nesting objects and retrieving properties, and is the best solution to copy the final property to a standard struct etc. and work on those each time, i.e. x = bike.wheel.rim.thickness; function(x)    VS.    function(bike.wheel.rim.thickness)</p>
<p>Also, I tried testing this:</p>
<p> f(obj, data) is generally faster than using obj.f(data)</p>
<p>But saw no difference in my test. Why is it supposed to be faster, should I be using f(obj, data) as best practice irrespectively?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gautam Vallabha</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33032</link>
		<dc:creator>Gautam Vallabha</dc:creator>
		<pubDate>Fri, 30 Mar 2012 14:29:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33032</guid>
		<description><![CDATA[Dave,

I&#039;m curious about the order-of-magnitude difference between the performance of the SimpleCylinder and NewCylinder examples:

SimpleCylinder (loop outside) :  0.112309 seconds.
SlowCylinder (custom set/get):  0.174094 seconds.
NewCylinder (loop inside constructor):  0.006654 seconds.

I would have expected the SimpleCylinder time to be closer to the NewCylinder time. I assume the discrepancy is because the SimpleCylinder loop goes from 1:1000, whereas the NewCylinder loop goes from numel(R):-1:1? (in the former case, the array size grows continually, whereas in the latter case it is effectively preallocated?)

Thanks,
Gautam]]></description>
		<content:encoded><![CDATA[<p>Dave,</p>
<p>I&#8217;m curious about the order-of-magnitude difference between the performance of the SimpleCylinder and NewCylinder examples:</p>
<p>SimpleCylinder (loop outside) :  0.112309 seconds.<br />
SlowCylinder (custom set/get):  0.174094 seconds.<br />
NewCylinder (loop inside constructor):  0.006654 seconds.</p>
<p>I would have expected the SimpleCylinder time to be closer to the NewCylinder time. I assume the discrepancy is because the SimpleCylinder loop goes from 1:1000, whereas the NewCylinder loop goes from numel(R):-1:1? (in the former case, the array size grows continually, whereas in the latter case it is effectively preallocated?)</p>
<p>Thanks,<br />
Gautam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Terry Deglow</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33031</link>
		<dc:creator>Terry Deglow</dc:creator>
		<pubDate>Thu, 29 Mar 2012 20:12:06 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33031</guid>
		<description><![CDATA[Two Questions:  In designing a cohesive solution to plotting general equations, I have one for independent variable and first attempt at plotting, another which supplies the dependent variable and a third for formatting the final plot [by passing the handle for the original plot].  Can you point to other options and techniques?

Secondly, a good design requires avoiding problems, including use of try/catch/finally statements.  I have seen just a few examples.  Please point me to other examples or tutorials, especially for the Matlab specific error messages that are available.

Thanks in advance.]]></description>
		<content:encoded><![CDATA[<p>Two Questions:  In designing a cohesive solution to plotting general equations, I have one for independent variable and first attempt at plotting, another which supplies the dependent variable and a third for formatting the final plot [by passing the handle for the original plot].  Can you point to other options and techniques?</p>
<p>Secondly, a good design requires avoiding problems, including use of try/catch/finally statements.  I have seen just a few examples.  Please point me to other examples or tutorials, especially for the Matlab specific error messages that are available.</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad Gilbert</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33030</link>
		<dc:creator>Chad Gilbert</dc:creator>
		<pubDate>Thu, 29 Mar 2012 12:19:15 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33030</guid>
		<description><![CDATA[I agree with Daniel - A Mathworks OOP blog would be very exciting! I know there&#039;s some low-hanging fruit in some of my MATLAB &quot;OOPlications&quot; in terms of efficiency gains.]]></description>
		<content:encoded><![CDATA[<p>I agree with Daniel &#8211; A Mathworks OOP blog would be very exciting! I know there&#8217;s some low-hanging fruit in some of my MATLAB &#8220;OOPlications&#8221; in terms of efficiency gains.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/#comment-33029</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Wed, 28 Mar 2012 14:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=391#comment-33029</guid>
		<description><![CDATA[Great post. Will have to reread this post a number of times to digest the huge number of nuggets about OO MATLAB. Dave I would love to see, and would definitely read, a regular blog from someone in your group.]]></description>
		<content:encoded><![CDATA[<p>Great post. Will have to reread this post a number of times to digest the huge number of nuggets about OO MATLAB. Dave I would love to see, and would definitely read, a regular blog from someone in your group.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
