- ZmeiGorynych
**Posts:**876**Joined:**

Care to show an example of a matlab class with generics to illustrate your 4th point in 2.?By the way, where are you located geographically?

- Cuchulainn
**Posts:**61149**Joined:****Location:**Amsterdam-
**Contact:**

QuoteOriginally posted by: ZmeiGorynychCare to show an example of a matlab class with generics to illustrate your 4th point in 2.?I second that; have never seen OO and/or generic examples in Matlab in this forum.

http://www.datasimfinancial.com

http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself

Jean Piaget

http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself

Jean Piaget

QuoteOriginally posted by: ZmeiGorynychBy the way, where are you located geographically?Hamden, CT, US. Hamden is a suburb of New Haven, a city best known for the Yale University. QuoteCare to show an example of a matlab class with generics to illustrate your 4th point in 2.?A simple example: methods display(obj) and disp(obj)There are two close related functions in Matlab: disp and display:- disp(var) prints value of a built-in variable (array, expression) on the screen; - display(var) additionally prints the name of the variable before its value. When you type varwithout trailing semicolon ( ; ) that suppresses display, Matlab calls display(var) internally. Very convenient for debugging, unit testing, etc.Now, if the variable is not of a built-in type, but an object of a Matlab class, by default the system prints only a minimal information. However, if method display(obj) is defined for the class, Matlab calls the method. It lets you control what will be printed. Usually the most convenient is to display all members of the class.Matlab OOP documentation describes the method and its effect and also supplies several examples including the following:

Last edited by yurakm on April 21st, 2007, 10:00 pm, edited 1 time in total.

I think you may be getting too bogged down in the details already. Matlab is basically a (very comprehensive) scripting language, implementation details like stack/heap memory should be irrelevant, no?

QuoteOriginally posted by: rwinston ... Matlab is basically a (very comprehensive) scripting language ...It depends on how will you define "scripting language". It is a very vague concept that in different contexts means rather different things: 1. A "glue" language controlling starts and execution of programs and passing data between them. Like bash shell language for UNIX / Linux or DOS / Windows batch files. People are also using this way such languages as Perl, Python, and Matlab, which are much more than "scripting languages" in this sense. 2. Language for machine-generated codes in context of dynamic web pages and similar.3. Languages that are good for writing short programs fast. Practically always the languages are typeless or weak typed, and are interpreted, not compiled. Weak typing makes it easier to produce codes fast, while interpreting makes it easier to check/fix/check again the codes. The codes tend to be of write-once/run once kind. Good for proof of concepts, checking algorithms, etc., and often used also for such operations as reformatting a batch of data for loading in database, when the next batch most probably will have a bit different format.I guess that you meant "scripting language" in the third sense. You are right: for smaller to midsize, run-once codes, the discussion is mostly irrelevant.The problem is that what starts as a proof of concept script often lives much longer time that was originally expected. The codes grow, became more complicated, are combined with other codes, get rich user interface, etc., etc. When your program reach some threshold size and complexity like 10,000 lines of Matlab codes organized into 200 functions and storing and passing data through 100-200 global variables, it turns rather hard to make the codes to work reliable and and to continue the development at reasonable speed.Now we either have to rewrite everything in "proper language", or refactoring in Matlab using such tools and techniques appropriate for bigger programs as OOP, generics, and design patterns. There is a rich literature and experience with using the techniques in/with C++. On the other hand, they are not described well in Matlab manuals, if described at all. This is what we are discussing here.Of course, we would like to reuse the techniques proved to work in other languages like C++ and Python. For this we are comparing Matlab facilities with the C++, Python, Java, etc. ones.

- Cuchulainn
**Posts:**61149**Joined:****Location:**Amsterdam-
**Contact:**

QuoteOriginally posted by: rwinstonI think you may be getting too bogged down in the details already. Matlab is basically a (very comprehensive) scripting language, implementation details like stack/heap memory should be irrelevant, no?This is a highly relevant and deep set of posts from someone who has obviously thought about the subject. It is refreshing to see that Matlab - at least in theory - can be used for OOP/GP and not just _define_the_variables_then_do_the_algorithm_then_plot_ style of programming.My own major question is how a Matlab programmer makes a paradigm shift to OO way of things. What are the steps?Indeed, you don't need to worry about memory for small prototypes.

Last edited by Cuchulainn on April 25th, 2007, 10:00 pm, edited 1 time in total.

http://www.datasimfinancial.com

http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself

Jean Piaget

http://www.datasim.nl

Every Time We Teach a Child Something, We Keep Him from Inventing It Himself

Jean Piaget

QuoteOriginally posted by: rwinstonMatlab is basically a (very comprehensive) scripting language, implementation details like stack/heap memory should be irrelevant, no?they are irrelevant for most of matlab users.

- ZmeiGorynych
**Posts:**876**Joined:**

Irrelevant for any casual user, likely enough. Once you try using matlab in anger without looking out for memory issues, you hit a brick wall of memory limitations and start caring about those things.

Last edited by ZmeiGorynych on April 26th, 2007, 10:00 pm, edited 1 time in total.

QuoteOriginally posted by: ZmeiGorynychOnce you try using matlab in anger without looking out for memory issues, you hit a brick wall of memory limitations and start caring about those things.unless, you install applications in production, for users, you dont care much about memory issues. i think it's almost insane to develop applications of such kind in matlab. it's a tool for researchers, as i see it. production code should be in a proper language like C++

- ZmeiGorynych
**Posts:**876**Joined:**

Quoteproduction code should be in a proper language like C++I certainly agree with that. However, research on over a year's worth of tick data leads to datasets of 100's of MBs, too - and then you notice it.

QuoteOriginally posted by: jawabeanit's almost insane to develop applications of such kind in matlab. it's a tool for researchersI also thought so, but my (not technical) managers did not believe me and insisted to rewrite everything from C and C++ into Matlab. They turned to be right - kind of: it is possible to develop some production applications in Matlab. Matlab provides the necessary facilities. Its OO is more close to Python than to C++ (no destructors), but it is fine with me. It is much easier to write generic codes in Matlab than using C++ templates. Of course, being an interpreted, weak typed language, Matlab does not provide static checking during compilation. You have to run each function to check syntax, and verify parameters dynamically using isa(), isempty(), and similar functions. It was not the major problem, though. Speed also turned to be less a problem than I expected: the Matlab application is sluggish, but it was bearable even with soft real-time, interactive graphics and models.The biggest problem (not counting management) turned to be a lack of collective experience. Nobody around to learn from, no good tutorials, no relevant code examples. Had to invent too many wheels, made many mistakes, and got in many dead ends. It resulted in the development proceeding much slower that would in C++. However, the development speed increased many times after learning the techniques. I still think that it was a wrong decision to develop a serious application in Matlab, but definitely not insane. I witnessed much worse wastings of programmer's time and efforts.

Last edited by yurakm on April 27th, 2007, 10:00 pm, edited 1 time in total.

QuoteOriginally posted by: CuchulainnI ... have never seen OO and/or generic examples in Matlab in this forum.An OO example from Matlab documentation: two classes related by inheritance

- DominicConnor
**Posts:**11684**Joined:**

Can large Matlab programs really be made truly robust ?

QuoteOriginally posted by: DCFCCan large Matlab programs really be made truly robust ?Apps written in Matlab or using Matlab routines can be quite robust. However, C++ and C# are significantly better languages with which to write applications so why would anyone ever choose Matlab? It certainly isn't for the quality of their math routines which are okay for only trivial math.

QuoteOriginally posted by: DCFCCan large Matlab programs really be made truly robust ?How large? There is a lot of million lines C and/or C++ programs. Windows and Linux codes have 50 million lines, Bloomberg's code base is about 40 million lines and grows fast, MathWorks code base (Matlab, Simulink, etc.) is about 25 millions lines. I doubt that any program written in Matlab is bigger than 100 thousand lines.How robust? I would not dare to code a phone exchange, avionics, or a heart monitor in Matlab.On the other hand, I had experience with 10,000 lines Matlab codes that were used by several (five?) people for several hours a week without serious complains. Actually, I found that some of them are still using my codes almost accidentally: after 2.5 years without a single complaint in one case and one year in another, I was sure that they abandoned the projects long ago.By the way, Python codes also can be made reasonably robust.I would say that I had more problems with crashes of C codes that Matlab ones, but C++ is better. As to Matlab itself, as a running system, it was improved immensely during the last five years. Matlab 5 and early 6 was a joke in the respect, Matlab 6.5 was OK, and Matlab 7.2 is rather robust. MathWorks did a great job in this respect: they eliminated 95% to 99% of bugs. From 300+ known bugs down to four or so, if I remember it right.

GZIP: On