Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Sunday, May 26, 2013

OOP in Matlab: basics /Tutorial

Software from Kelvin Murphy and Students (UBC)
http://www.cs.ubc.ca/~murphyk/Software/matlabTutorial/html/objectOriented.html#53

A more professional guide to Matlab
https://code.google.com/p/yagtom/

Suggestion:

The danger of premature optimization

Before spending a lot of time optimizing your code, you should first identify the key bottlenecks using the profiler. The usual pattern is that 80% of the the time is spent in 20% of the code, so you can focus your efforts accordingly. Also, remember that correctness is more important than speed!

matlab "Too many input arguments" OOP

http://stackoverflow.com/questions/715624/why-do-i-get-a-too-many-input-arguments-error-when-not-passing-any

I believe you can also get around this by declaring roll_dice to be a static method.

Why Static Method works?

Friday, May 24, 2013

Getting start with Matlab OOP

http://www.mathworks.com/help/matlab/matlab_oop/developing-classes--typical-workflow.html

difference between

properties (Constant)

can be access as independent variable or function directly.

properties (GetAccess = 'public', SetAccess = 'private')

can only be access outside class through another class

Thursday, May 23, 2013

observer pattern

http://www.oodesign.com/observer-pattern.html
To have a good design means to decouple as much as possible and to reduce the dependencies.

Saturday, April 13, 2013

Unused parameter

You can cast function parameters to void to avoid "unused parameter" compile warnings.
iterator find(const Data& item) const {
 (void) item;
 return iterator(nullptr);
}

Assuming your question was asked given that everything already does compile, I would say code in an order that makes sense to you. Hint: think about incremental testability. The more pieces of functionality you can test along the way, the less time you will spend debugging.

nullptr Vs. NULL

1. We encourage you to use nullptr as we have C++11, the latest version;

2. Whenever a method receives a pointer as a parameter, it can check whether it is equal to nullptr and do the appropriate thing. This is part of good defensive programming. Don't assume other parts of your program are acting as they should. 

2) Are we going to assume that null data will never be inserted in the insert method in BST.hpp?

3. Note that we will not test for this corner case, as we didn't specify that you needed to handle the case in the writeup. 

(This is a general rule, we won't hold you responsible for details left unspecified)
However, testing this corner case could be helpful during code development, much as cassert can be useful

The reason you should use nullptr instead of NULL: http://www.devx.com/cplus/10MinuteSolution/35167

nullptr: A Type-safe and Clear-Cut Null Pointer

Whether you're using NULL or 0, your C++ apps are subjected to bugs and maintenance problems that are caused by the ambiguity of 0. Find out how to use the nullptr keyword instead of 0 to indicate a null pointer value.