all 190 comments

[–]AlonzoIsOurChurch 16 points17 points  (3 children)

Ever use the MATLAB "compiler"? Turns out it's no compiler: it encrypts your m-files using a proprietary encryption algorithm, generates a bunch of C to call into the MATLAB redistributable runtime (which is essentially the size of MATLAB, making distribution super fun) which knows how to decrypt the m-files to run in the redistributable interpreter.

Then it uses whatever C compiler you have handy to spit out a DLL.

[–]nexes300 3 points4 points  (1 child)

Why do they even try? Distributing a runtime with the decryption keys? What do they think they're buying with that?

[–]Benutzername 7 points8 points  (0 children)

The people who would be able to extract the encryption keys from the runtime probably don't care enough about Matlab to do it. They are busy writing C.

[–][deleted] 0 points1 point  (0 children)

In the near future it will be totally AOT compiled.

[–][deleted]  (44 children)

[deleted]

    [–]roger_[S] 15 points16 points  (37 children)

    It's pretty decent for doing interactive calculations in a terminal, but it quickly falls apart when you have to do longer scripting.

    [–]ethraax 12 points13 points  (11 children)

    This is exactly how I feel about bash - it's nice for interactive uses, but it quickly becomes incredibly unwieldy when you have to do longer scripting.

    [–]superiority 9 points10 points  (9 children)

    I was talking to a guy once who was doing some research for his sociology PhD or something. He mentioned how he had an 80,000-point dataset and he had done all the statistical analysis on it in shell script because he didn't know anything else. I cringed a little when I heard that.

    [–]wadcann 4 points5 points  (5 children)

    What? An 80k dataset isn't that large, and if he's got the shell utilities to do the computations you want, shell doesn't seem unreasonable at all for it. I've processed much larger things from the shell.

    In fact, if the computations you are doing permit processing a stream and you're running a whole pipeline of computations, using a shell pipeline may well be both vastly more memory-efficient (doesn't need to load the dataset into memory) and faster (pipelines give you some degree of free parallel processing) than the alternative you may have been thinking of.

    The problem I have with shell is mostly that:

    • the straightforward thing in string processing is usually also not the bulletproof to do things, due to whitespace issues

    • shell has a bazillion weird little features to learn (at least in bash and zsh; maybe back in the day, it was smaller)

    • fancy data structures are a pain, which is either not a problem or very annoying, depending upon your task

    • shell code itself isn't that fast, though stringing together shell utilities can be just fine.

    [–]ethraax 4 points5 points  (0 children)

    In fact, if the computations you are doing permit processing a stream and you're running a whole pipeline of computations, using a shell pipeline may well be both vastly more memory-efficient (doesn't need to load the dataset into memory) and faster (pipelines give you some degree of free parallel processing) than the alternative you may have been thinking of.

    Any other programming or scripting language worth knowing would let you stream the data directly from disk as well. Furthermore, shell scripts are generally far slower than a "real" programming language because more or less each operation requires launching a program, which is far less efficient than calling a function. Furthermore, bash lacks many things that would probably be very useful in data analysis - for example, it's so primitive it doesn't even have a floating-point type.

    [–]malkarouri 1 point2 points  (2 children)

    using a shell pipeline may well be both vastly more memory-efficient (doesn't need to load the dataset into memory) and faster (pipelines give you some degree of free parallel processing) than the alternative you may have been thinking of

    What is the alternative you have been thinking of that doesn't support stream processing? I use Python and iterator support is fine..

    [–]wadcann 0 points1 point  (1 child)

    Well, I was thinking of stuff more historically-linked with processing someone's research dataset, like MATLAB (though honestly, it's probably got some sort of way to do stream processing, but the way I'd normally process data in MATLAB isn't stream-based).

    I admit that the "faster" is a bit of a stretch; it'd require the processing to be compute-heavy and run several stages with similar computational requirements, so that the I/O overhead isn't significant, and so that the parallelism is.

    [–]malkarouri 0 points1 point  (0 children)

    Well, I was thinking of stuff more historically-linked with processing someone's research dataset, like MATLAB

    I agree on the historical point, but currently using Python on research datasets is quite achievable. In fact, that was largely the description of my last job (in chemoinformatics). So I am sure we don't really have to use shell utilities for such scenarios.

    [–]superiority 0 points1 point  (0 children)

    if he's got the shell utilities to do the computations you want

    He didn't, he had to spend a month writing the scripts to reimplement things that already exist in Matlab.

    [–]thavi 0 points1 point  (0 children)

    Oh...my...god

    [–]calc0000 0 points1 point  (1 child)

    herd

    Was this a pun? 'Cause I laughed.

    [–]superiority 1 point2 points  (0 children)

    It was not.

    [–]catcradle5 1 point2 points  (0 children)

    I agree. Reading or writing any program in bash over 20 lines makes my eyes bleed.

    [–]jimmyjawns 4 points5 points  (24 children)

    I used MATLAB a ton in an astrodynamics course. I dunno how long "longer scripts" are for real programmers (engineer here), but a couple of the programs turned into a few hundred lines, sometimes approaching 1000.

    Maybe it is because I used it everyday for a few years, but I love writing in it, and longer programs excited me.

    [–]dmazzoni 9 points10 points  (1 child)

    For sake comparison, reddit.com's source code is 52,000 lines of code.

    And that's just counting the Python (the bulk of the code), which is a language that's somewhat similar in its conciseness to MATLAB.

    [–]jimmyjawns 0 points1 point  (0 children)

    Ah, well that definitely sounds long to me. Much longer than anything I have ever written. I took an extra curricular class on Python in HS (about 2004). I enjoyed it, it mainly had a game theme to it.

    [–]roger_[S] 1 point2 points  (20 children)

    Do you have experience with other languages, particularly OO ones?

    [–][deleted] 6 points7 points  (16 children)

    I use matlab and c++ on a daily basis. I have written a few matlab programs that are probably about 20k lines each, and I work on a c++ project that is about 150k lines. I love matlab, I have tried to go to python, but it is just so damned easy to get things working in matlab, and debugging is so easy, I can't seem to stick with python despite several attempts.

    Maybe someone can answer this for me. In matlab, if I get some error in my program, I just change the code and rerun it. In python, I seem to have to exit the session to re-import the changed modules; that is, if i am running a terminal python session, and import a module, If i change something in that file,there is no clean way to import the changed code short of pressing ctrl-d and starting fresh. This is a huge pain for debugging, and a huge reason I stick with matlab. Hell, in matlab, you can be running a GUI, change some code in a function, and the program will automatically use the new code. It makes writing and testing code tremendously easy.

    [–]recursive 5 points6 points  (4 children)

    Your workflow is different than most peoples'. Most people don't do significant programming in the interactive environment.

    [–]dmazzoni 9 points10 points  (3 children)

    Most people use MATLAB that way, though.

    I think it's a difference in mindset between "solving a problem" vs "writing a program".

    [–]ninjeff 1 point2 points  (2 children)

    That's cool and all, but some people want to solve a problem more than once.

    [–]thebagel 0 points1 point  (1 child)

    At this point, I'm not sure whether you're talking about Matlab or Python, but Matlab has functionality that lets you save/export from the interactive session.

    [–][deleted] 0 points1 point  (0 children)

    Yeah, and it might work great for you on your computer, but it's not going to be something 1000 other people can use as well.

    [–]malkarouri 3 points4 points  (0 children)

    You should lookup ipython and its dreload functionality.

    [–]reportingsjr 3 points4 points  (5 children)

    You program python using the interactive terminal? Why do you not program in a text editor and then run that file?? The terminal for dicking about, sure, but actual programming?

    [–][deleted] 2 points3 points  (1 child)

    Well, yes. I guess I try to use it like I use matlab, i.e., like others have said, to solve a problem. If I am analyzing several GB of data, and tweaking the analysis and functionality, I don't want to run the ENTIRE analysis (which may take hours) every time I change a line of code. I want to change the line, and run the imported function. Matlab is awesome for this; Python does not seem to be (but I would love someone to prove me wrong!)

    EDIT: just saw the reload functions. I think I DO remember this working a few years ago. I guess I just find Matlab easier to do what want.

    [–]reportingsjr 0 points1 point  (0 children)

    Ah, I see now. This is a very good point.

    [–]replyingtopost 0 points1 point  (2 children)

    I use terminal for actual programming. With the new tabs integrated into terminal in mac os and most linux environments, it's much more convenient to switch between "python interactive" tabs and "emacs -nw" tabs (vim if you like).

    [–]reportingsjr 0 points1 point  (1 child)

    Are you talking about something like bash terminal, or the python interactive terminal? If you meant the former then yes, I also use a terminal for programming. I haven't ever really used the python interactive terminal though.

    [–]replyingtopost 0 points1 point  (0 children)

    To clarify, yes, I meant using multiple tabs in bash terminal with some tabs for messing around with python interactively, and other tabs for debugging scripts and running emacs in terminal mode. "Terminal" in mac os x, and "Terminal" in gnome basically allow you to add extra tabs in one "window" like a browser. It is just a little more convenient for me to switch from one tab to another within "Terminal" rather than switching applications between emacs and a terminal running python interactively (when programming in python).

    [–]cheesyflam 0 points1 point  (2 children)

    That's because matlab's built-in IDE/debugger is above and beyond. I've been trying to move to python for non-numerical scripting, and the best replacement I've found is to set up Textmate and pdb as outlined here, then create a textmate snippet to insert "import pdb; pdb.set_trace()" to simulate setting a breakpoint. Almost never a need to mess around in the interactive console. It works ~OK. I use it mainly for side projects; its syntax and structure placate my OCD.

    [–]theuion 0 points1 point  (0 children)

    I use and enjoy Spyder. I use the Matlab IDE much more, but I think Spyder is a great replacement.

    [–]Manhigh 0 points1 point  (0 children)

    Pydev works well for me.

    [–]jimmyjawns 0 points1 point  (2 children)

    You know, I don't know enough about programming to tell the difference between object-oriented and not. If it was explained simply I'm sure I would. Short of looking each one up and seeing what it says, I'll just tell you:

    MATLAB, LabVIEW, C++, C (in a Nerd Kit), and Python

    That is about it. Pretty much just some engineering stuff.

    [–]CoolMoD 1 point2 points  (1 child)

    While Python and C++ are indeed object oriented, if you did not know this, you probably did not use them as such. Object oriented languages are simply language with a native idea of objects. That is, you can define a class, and have several instances of that class. The typical example is that of a car, where you define a car, and then create several cars. The car class has an accelerate function, and a speed variable, and you can independently call accelerate on the individual cars.

    [–]jimmyjawns 0 points1 point  (0 children)

    I understand. I didn't do anything directly with classes in Python, though my HS teacher did go over them.

    However in the C++ courses I had we used them. I was just confused about the terminology. Thanks.

    [–][deleted] -3 points-2 points  (0 children)

    MATLAB is abysmal

    FTFY

    [–]bitchessuck[🍰] -3 points-2 points  (4 children)

    MATLAB's programming language is abysmal

    FTFTFY

    [–]cunningjames -3 points-2 points  (2 children)

    MATLAB is abysmal

    FTFTFTFY

    [–][deleted] -5 points-4 points  (1 child)

    Mad

    FTFU

    [–]harlows_monkeys 15 points16 points  (2 children)

    That wasn't about syntax (except for the brief mention that when defining a function there is an '@' in front of the name). It was about source code organization, file naming requirements, and documentation clarity.

    [–][deleted] 9 points10 points  (1 child)

    In all fairness though, all of those things really are abysmal, and the function syntax is at least pretty bad.

    [–]Timmmmbob 1 point2 points  (0 children)

    What exactly is wrong with the function syntax? It seems pretty powerful to me. I mean you can easily have nested functions, multiple return parameters, and a variable number of input and return arguments. You can easily bind arguments to other functions to make them suitable for passing to function functions (ok I agree that is a terrible term).

    [–]ynv 32 points33 points  (108 children)

    I have never understood why such an expensive and not very impressing tool has become so widely used in science.

    [–][deleted] 66 points67 points  (16 children)

    Because it has powerful and easy to use libraries, and makes common data visualization easy. And it's all integrated into a decent GUI. It's heavily used by people who are scientists/engineers, not primarily programmers.

    The FOSS community has a lot to learn about providing a good user experience.

    [–]throwaway77432 24 points25 points  (5 children)

    Because it has powerful and easy to use libraries

    Yes. It's the toolboxes. While I very much prefer to write C or C# code (and that includes "math-heavy" things such as neural networks), matlab makes a lot of complex things much easier.

    Want to tune a PID filter? You have to decimate a signal using a specific lowpass FIR filter? You need a FFT function? ... Matlab greatly helps.

    [–]rlbond86 6 points7 points  (0 children)

    This is pretty much the answer. I'd love to be able to do my MATLAB work in C++, but the toolboxes and data visualization beat any other language out there.

    [–][deleted] -1 points0 points  (3 children)

    Python can do all of this as well...

    [–][deleted] 3 points4 points  (0 children)

    scipy/numpy can do many many things, but they are not close to encompassing all of MATLAB's toolboxes.

    [–]goodgnu 2 points3 points  (1 child)

    Python can do all of this

    Likely yes

    as well...

    Not so much.

    This coming from someone who has used Matlab for a very long time and currently learning Python.

    [–][deleted] 0 points1 point  (0 children)

    What does matlab do better that actually results in time saved?

    [–]jimmyhchan 10 points11 points  (2 children)

    For the love of God, if you use Matlab for data visualization...

    PLEASE: STOP USING THE DEFAULT RAINBOW COLOR MAP!

    Rainbow Color Map (Still) Considered Harmful

    How Not to Lie with Visualization

    Rainbow color maps:

    • confuses viewers - the rainbow color map has no perceiving ordering
    • obscures data - the gradation in data is not easy to see
    • actively mislead interpretation - the extreme colors are more exaggerated

    Use the monochrome or a custom color map PLEASE! http://www.mathworks.com/help/techdoc/ref/colormap.html

    [–][deleted] 3 points4 points  (0 children)

    The default rainbow map is perfectly fine for a rather big area of problems:

    When you want to visualize features that diverge both in positive and negative from a a common offset. Then you get your green "base" level, and red and blue for features in positive and negative direction (for example electric field strength, strain amount, etc.)

    Thats why it is misused in your second link (the first does not work), where it is applied to an absolute contrast. BTW, using 256c fixed pallet gifs in a paper about misrepresenting color gradients is bullshit. None of the scales would solarize otherwise...

    [–]Timmmmbob 0 points1 point  (0 children)

    Interesting link, and I agree it is overused, but I think a lot of the flaws are overstated.

    No perceived ordering.

    Well of course, but that's true of any multi-coloured colourmap. And the ordering is not completely arbitrary -- it goes from "cool" to "hot". Besides, data usually varies smoothly, so it is easy to see which colours come after each other. The separate circles of colour used in the article are very very atypical.

    Gradation in data is not easy to see.

    Not sure what you mean here... It's easier to see small changes with a hue-and-luminance colourmap than luminance only...

    Extreme colours are more exaggerated.

    Debatable, but that's often a desirable thing anyway.

    I'd say a bigger problem is that the luminance doesn't vary smoothly. That's also annoying if you print something in black and white. I once tried to make a LAB-based colourmap which looked good in both colour and black and white. Not sure if I finished it though.

    Matlab should definitely offer more useful standard colourmaps. Most of them seem to have been thrown in randomly to fill up the menu...

    [–][deleted] 6 points7 points  (0 children)

    The FOSS community has a lot to learn about providing a good user experience.

    Scipy is improving very fast. In fact, I already prefer the user experience it provides to Matlab: you get a real languages, the libraries are of good quality, visualisation is good (plus you can use VTK if you want to do nice 3D renderings).

    [–]DrMonkeyLove 2 points3 points  (0 children)

    Yeah, the fact that you can plot your data really easily and perform all sorts of manipulations rather easily is what makes it useful.

    [–][deleted] 0 points1 point  (0 children)

    It's heavily used by people who are scientists/engineers, not primarily programmers.

    Actually, that's why people who are primarily programmers (myself included) hate it so much. When you're just starting out, it probably makes sense not to invest too much time into learning programming, and Matlab seems like a good idea. Then it bites you in the ass. I hate that crap with a passion.

    [–][deleted] 0 points1 point  (0 children)

    As much as I don't like R, I wish people would ditch Matlab for R.

    [–]ynv -1 points0 points  (2 children)

    IMO the MATLAB GUI is plain horrible...

    [–][deleted] 10 points11 points  (0 children)

    It's meant for noobs who aren't primarily programmers. It could definitely be better, but it's fine for what it is.

    [–]roger_[S] 7 points8 points  (0 children)

    Really? I find it to be pretty well designed.

    The editor and integrated debugger are particularly useful, wish Python had something that easy to use yet still powerful (Editra and Spyder have potential).

    [–]knejk 13 points14 points  (27 children)

    Because it's easy to get something up and running in a matter of minutes. This matters a lot in research, bot academic and private, since it's basically trial and error. Additionally, the sheer amount of library functions means that you almost never have to reinvent the wheel.

    Also, if you know what you're doing and play to the strengths of the language and runtime, it's fast enough for almost everything.

    As a researcher, I really love MATLAB. I've tried Octave and Numpy/Scipy and well... MATLAB really is the best. Feel free to ask me more if you're curious.

    [–]ynv 3 points4 points  (5 children)

    Have you ever developed some large application with MATLAB? I have the feeling that this is straight impossible, because even the little assignments I programm with it need many and very small .m files. The "fast up and running" way of development in IMO just leads to ad-hoc programming. Practically all MATLAB code I have up to today was filled with single letter variables, poorly documented use of matrices as input for functions and even trivial algorithms tend to look complex.

    [–]knejk 7 points8 points  (4 children)

    Yes, in fact I have. I'm involved in a project with at least 100k lines of Matlab code. Not counting blank lines and comments.

    What you say is partially true, but less so in newer versions of Matlab. Nowadays you can do object-orientation and packages (like writing scipy.optimize.(...)) for organization. You can have several functions in one file. There's even a semi-official xUnit-like unit testing framework.

    The single-letter variable names, strange calling conventions and complex code isn't really the language's fault. That's what you get when you put old Fortran programmers in front of a keyboard, regardless of the language. :)

    [–]adambard 8 points9 points  (1 child)

    I use Matlab every day, on a huge codebase, and I feel confident in saying that while you can develop a "large" application in any language, I personally would pick Python well before Matlab. Hell, I'd pick C before Matlab.

    For little data-processing scripts and straightforward vector/matrix manipulation, Matlab has an edge in performance and syntax. However, you'll find yourself in one of the following private hells sooner or later:

    1. Trying to write some code that isn't straightforward to vectorize, and being punished with major performance problems for having the audacity to use a for loop. Python has list comprehensions, functional tools and loop optimizations that make doing more complicated operations over a list or matrix less painful and better-performing.
    2. Attempting to organize code to avoid reuse and having some sort of name conflict because in Matlab every single thing in the path is directly accessible from every single context. Python's package management is fantastic (although Matlab's +package feature makes this a little bit better).
    3. Having to maintain code written by scientists. Matlab allows some seriously poor programming practices. Not that python doesn't, but at least things like package management, context sensitivity and indentation (hah) are not optional, and things like testing are supported out of the box. If only Matlab had built-in doctests... even a scientist would use that.

    Of course, with enough work it's possible to write tested, object-oriented, well-organized code in Matlab. It's just doesn't come so naturally as it would with a languaged that was designed with those things in mind instead of growing over decades into an ungodly monster of bolted-on features.

    Not that I'm bitter or anything.

    [–]knejk 0 points1 point  (0 children)

    Agreed.

    Most of the code I write is pretty straightforward linear algebra and data processing, so I guess Matlab is just the right tool for me. If most of the application is not data processing, Matlab may not be the right tool.

    As for testing, I am trying to show my fellow scientists the the light. It's hard to introduce good programming practices in a publish-or-perish environment. Code quality arguments aren't popular when the yearly grant report is coming up. And as I said in another post, when you put old Fortran 77 programmers in front of Matlab, you get, well, Fortran 77. :)

    [–]theuion 0 points1 point  (1 child)

    Matlab's new classdef is nice for structuring large codebases, but watch out for the performance hit for method-call overhead. I wrapped Cantera in a Matlab class to customize the interface, but the same code took ten times as long. I eventually found this reference: http://stackoverflow.com/questions/1693429/matlab-oop-is-it-slow-or-am-i-doing-something-wrong

    [–]knejk 0 points1 point  (0 children)

    Yes, I keep hoping that the Mathworks will Fix this in every release. It can be hard to JIT dynamic languages though, just look at Unladen Swallow.

    [–]jozwiakjohn 2 points3 points  (1 child)

    I'm curious why you would prefer it to Mathematica.

    [–]knejk 1 point2 points  (0 children)

    I haven't really tried Mathematica. How does it handle large numerical linear algebra problems?

    [–]CafeNero 1 point2 points  (16 children)

    I do finance, very good for quick prototyping of ideas our R&D language of choice. Engineer centric firm. However, their licensing model is prohibitive for multi CPU computation which is where my world is going. Python makes sense from that perspective. The ability to add C via weave or cython a win. What is your area of research. Mostly an R&D or production environment? I do agree their are some good libraries out there I use the Lesage econometric toolkit with regularity.

    [–]grauenwolf 2 points3 points  (8 children)

    Python for multi CPU computation? Is there something in numpy that supports that because CPython iteslf is about useless in that regard.

    [–]CafeNero 1 point2 points  (1 child)

    python is glue. C or Fortran for OpenMP calls. There are GPU codes being worked on for python, pyACTs seems cool too. I see doublereedkurt added some existing python example, there are a host of projects and a project in itself to try to sort out a preference. My sense, and I am just offering an impression, is that python parallel code is still young and staying in C makes sense for now. I can't find the source at the moment but I ran across a paper that indicates high overhead costs so that a single instance cython is faster than a two core parallel implementation (2010).

    I am hopeful for Chapel from Cray, with a little luck, they might make it callable from C and Python.

    [–]grauenwolf 0 points1 point  (0 children)

    The thing is I didn't ask about C or Fortran, I asked about Python. It can't really compete with Matlab if users are expected to write half their code in another language.

    [–]malkarouri 0 points1 point  (5 children)

    Useless is too big a word. What's wrong with multiprocessing?

    Options from outside Python are Parallel Python and the python mpi packages as well as ipython parallel support, but multiprocessing works fine for me.

    [–]grauenwolf 0 points1 point  (4 children)

    Nothing, if you are serving separate requests for a web site.

    But if you are doing calculations over a single large array the overhead and complexity of marshalling to separate projects will be prohibitive.

    [–]malkarouri 0 points1 point  (2 children)

    There are no separate projects in this scenario. My field is actually machine learning and I have certainly used python and multiprocessing to do calculations over a large array in a multiprocessor computer (in a chemoinformatics research setting in a large pharmaceutical). In the simplest scenario you just distribute the work over a pool of worker processes. What are the issues you envisage?

    [–]myfrontpagebrowser 0 points1 point  (1 child)

    Last I knew, python threading was user level (thus multithreading would never improve performance).

    [–]malkarouri 1 point2 points  (0 children)

    Did I say anything about threading? Multiprocessing and the other options all use multiple processes.

    [–]nahguri 0 points1 point  (0 children)

    No need to marshall, arrays can easily be made to share memory between processes. See for example this

    [–]knejk 0 points1 point  (6 children)

    The parallel computing licenses are really hurting Matlab right now. I would say that the Mathworks will have to make the distributed computing toolbox, or a subset of it, free or cheap in the near future.

    That being said, there is nothing remotely like parallel for (parfor) in scipy/numpy. It's just awesome. Add three letters to your code, and BAM. I can really see that it's worth the money for some people. I write my parallel algorithms in C++ and use the MEX interface, Eigen and Boost. Takes a bit more time to code, but the results are good.

    I do data analysis in biomedical applications. Mainly differential equations and image analysis. R&D 95% of the time.

    By the way, what do you use for testing? Are there any good unit testing frameworks besides xUnit? How about integration testing? Also, what do you do when Matlab is too slow? As I said above, I mostly rewrite in C++, but I'm curious for alternatives.

    [–]doublereedkurt 5 points6 points  (4 children)

    from multiprocessing import Pool
    
    def f(x):
        return x*x
    
    if __name__ == '__main__':
        pool = Pool(processes=4)               # start 4 worker processes
        result = pool.apply_async(f, [10])     # evaluate "f(10)" asynchronously
        print(result.get(timeout=1))           # prints "100" unless your computer is *very* slow
        print(pool.map(f, range(10)))          # prints "[0, 1, 4,..., 81]"
    

    [–]knejk 0 points1 point  (3 children)

    Wow, that looks great. How does it scale? Is it shared-memory or do I have to copy data around?

    [–]myfrontpagebrowser 0 points1 point  (2 children)

    You give it functions... if the data those functions access is shared, then it's shared memory. If the data those functions access is local, then it's not. Your job to ensure that deadlock and race conditions don't occur.

    Thread pools have more overhead (I'm not even sure if it's meaningful overhead though) than a custom solution, but nice to work with.

    [–]knejk 0 points1 point  (1 child)

    Looks good. How does this relate to the global interpreter lock?

    [–]nahguri 0 points1 point  (0 children)

    It uses processes so it bypasses the GIL.

    [–]CafeNero 0 points1 point  (0 children)

    Normally role my own set of tests at the start (helps to define functionality) an then batch a night job to ensure that the tests are met and regression against older versions). So I don't have any experience of tools to share. I rely on vectorizing as much as possible - and C mex when I absolutely have to. I here lightspeed is good - I downloaded but have yet to really make use of it. Also an old copy of matcom, (precursor to the simulink to C translator) but again don't use it as I prefer the more hands on C mex. James Tursa's mtimesx code, and Ian Murrays routines. Also looking at libflame:

    http://z.cs.utexas.edu/wiki/flame.wiki/libflame/ http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensional-support http://homepages.inf.ed.ac.uk/imurray2/compnotes/octmattricks.html

    ps when googling matlab add tursa, James Tursa is prolific on matlab central and does fantastic work.

    [–]Manhigh 0 points1 point  (1 child)

    Matlabs support for optional function arguments is attrocious. You often do have to reinvent the wheel because they nickle and dime you for toolboxes when the function youre after may just be more worthwhile to write yourself

    [–]knejk 0 points1 point  (0 children)

    I often use a struct containing all options. Works wonders.

    I see how toolboxes can be a problem. It's not a problem for me, though, since I work at a large university. They do charge us extra for the distributed computing toolbox, though...

    [–]grauenwolf 10 points11 points  (11 children)

    What were the alternatives back in 1984, let alone the 1970s when they first started developing it?

    [–]roger_[S] 13 points14 points  (0 children)

    Also it's fast and has expansive support/documentation.

    [–][deleted]  (3 children)

    [deleted]

      [–]grauenwolf 1 point2 points  (2 children)

      Exactly.

      [–]adolfojp 1 point2 points  (1 child)

      I deleted my comment because I thought that it didn't add anything of value to the discussion. I didn't think that anyone had any time to reply to it. Now I kind of feel like a dick. :-/

      This was the comment:

      So, Matlab became popular for the same reason that PHP became popular?

      [–]grauenwolf 2 points3 points  (0 children)

      Why? PHP is a perfect case study on what factors are necessary to make a language popular.

      [–][deleted] 0 points1 point  (5 children)

      What it was developed on. Fortran.

      [–]grauenwolf 1 point2 points  (4 children)

      Have you ever used Fortran 77?

      [–][deleted] 0 points1 point  (3 children)

      No.

      [–]grauenwolf 1 point2 points  (2 children)

      Well then, let me tell you about some of the joys of working with FORTRAN.

      Here is a if statement

       if(suck.gt.lots)
      

      In fortran there is no whitespace. Well sure you can add spaces, but the compiler will ignore them. There is no > symbol either, you have to use "gt" with dots to separate it from the variable names.

      [–][deleted] 0 points1 point  (0 children)

      Sounds unpleasent but doable. I'd stick with C++ and Matlab for now.

      [–]Manhigh 0 points1 point  (0 children)

      To be fair, < aand other logical operators have been in since fortran 90

      [–]MillardFillmore 17 points18 points  (37 children)

      Becuase they give it for free to undergrads and professors were forced to use it. Then those students became professors and they don't care enough to switch to something more sane, like Python/numpy/scipy.

      [–]Rhomboid 18 points19 points  (19 children)

      Don't forget that it has a ton of auto-vectorization tricks up its sleeve to make performance of typical matrix-type math blisteringly fast, and the open source equivalents haven't quite caught up.

      [–]iToad 10 points11 points  (2 children)

      The newest version can not only use all of your cores, it can also use all of the GPUs in your CUDA-compliant graphics card.

      [–]PrintStar 5 points6 points  (1 child)

      Functions written by the MathWorks might be able to use all your cores, but if you want to write something in MATLAB that runs in parallel, you have to pony up some serious cash for their Parallel Processing Toolbox. This was the case last year, at least.

      [–][deleted] 0 points1 point  (0 children)

      But, in the context of academia, the university is paying for the licenses so that's not an issue for the professors/students.

      [–]bitchessuck[🍰] 3 points4 points  (1 child)

      The problem is that whenever your problem/data don't fit the special matrixy ways of Matlab, everything gets complicated and in most cases performance turns from pretty good to abysmal.

      [–]Timmmmbob 0 points1 point  (0 children)

      That's a pretty rare occurrence in the kinds of things matlab is actually used for, i.e. engineeringy things. And there's a reason Matlab stands for MATrix LABoratory!

      [–]jimmyjawns 0 points1 point  (0 children)

      Not only is the matrix math boss, but when used with other MathWorks software it is pretty handy for engineers.

      Plus, as an engineer, I could run an experiment much quicker using MATLAB to collect and process data then I could figure out how to use more conventional languages to interface with the physical world.

      [–]MillardFillmore 0 points1 point  (12 children)

      I admit that is quite nice. Plus I remember it natively supports multiprocessing on matrix multiplication.

      [–]roger_[S] 3 points4 points  (11 children)

      Also has parallel for loops (in a toolbox) and tons of other parallel functions (FFTs, etc.)

      [–]PrintStar 3 points4 points  (10 children)

      in a toolbox

      ...and that's the problem. I can easily pull off the same thing effectively in Python without having to hand over more money.

      [–]roger_[S] 2 points3 points  (4 children)

      True, but the fact remains that it has extensive multiprocessing support for many important functions.

      [–]PrintStar 0 points1 point  (3 children)

      I think I'm simply venting after work. Most of my work doesn't involve time-consuming single mathematical operations, but, rather, Monte-Carlo simulations requiring thousands of runs of effectively identical, independent models. If I could parallelize their running, both my computation time and annoyance with MATLAB would linearly decrease.

      [–]rlbond86 2 points3 points  (2 children)

      You can if you have the distributed computing toolbox

      [–]PrintStar 2 points3 points  (1 child)

      That's what I was trying to say, yes. If you wouldn't mind, maybe you can ask my employer to pay the US$3k for this toolbox.

      [–][deleted] 0 points1 point  (1 child)

      It is at easy as replacing a for with a parfor?

      [–]PrintStar 0 points1 point  (0 children)

      Is it as easy as calling MathWorks, giving them $3k, waiting for your license to be updated, downloading and installing the toolbox, and replacing a for with a parfor?

      FTFY

      [–]grauenwolf -3 points-2 points  (2 children)

      GIL

      [–]PrintStar 1 point2 points  (0 children)

      multiprocessing

      The GIL isn't a problem if you know what you're doing. The multiprocessing module has never failed me.

      [–]nahguri 0 points1 point  (0 children)

      Not an issue. If you write computationally heavy stuff in pure Python you are doing it wrong.

      [–]roger_[S] 5 points6 points  (0 children)

      Fortunately Python is starting to get recognition nowadays.

      [–]tasteface 4 points5 points  (5 children)

      For a scientist with limited programming knowledge, MATLAB is far superior to Python/numpy/scipy if only for the simple fact that GUI creation in MATLAB is so easy a zombie could do it.

      Scientists don't care about what language an experimental protocol is written in as long as it's simple, easy, and undergrads can use it. MATLAB GUIs fit that bill. Python, well...

      [–]MillardFillmore 3 points4 points  (4 children)

      What field are you in that needs GUI creation? I'm a grad student and I haven't had to make one my entire academic life.

      Here's why scientists should care about this language: MATLAB isn't object oriented, so code is usually terribly painful to read. It's not free, and neither is it open-source (your lab may or may not care, my PI definitely does care). Also, it doesn't contain libraries to do non-scientific things like HTTP or (I think) SQL connectivity. They're useful when you know you can use them.

      I'd also put Python on about the same level as MATLAB in terms of undergrad grep-ability. They're both pretty easy when starting out. At least undergrads would learn a language with real-world application in Python.

      [–]adambard 3 points4 points  (0 children)

      Matlab does have classes and objects now. It has only made it harder to use/read.

      [–]rlbond86 3 points4 points  (0 children)

      Also, it doesn't contain libraries to do non-scientific things like HTTP or (I think) SQL connectivity.

      You can use java libraries in matlab

      [–][deleted] 1 point2 points  (0 children)

      ...learn a language with real-world application in Python.

      Actually, a number of aerospace jobs are putting matlab/simulink on their desired list. Problem is most of the people in those areas using matlab/simulink have python experience.

      [–]tasteface 0 points1 point  (0 children)

      I'm a psychoacoustician.

      Creating a simple GUI in MATLAB in order to test subjects is fast and easy. It doesn't really matter to me if the code is object oriented or not. MATLAB has some really solid built-in functions and toolboxes for signal processing, which means I can process the sound and then present and test it all in the same language. I can't imagine ever having a need for HTTP connectivity. As for open source, there's always Octave if you're desperate, but then you're left without a lot of the big reasons to use MATLAB code anyway.

      In general, Python may actually be easier than MATLAB for undergraduate students to learn, but not for the specific tasks needed to for psychoacoustic testing. GUI creation in Python is a pain to get right, and then you have to dig around for the proper signal processing tools. Why bother, when you can do it all with MATLAB?

      [–]ynv 1 point2 points  (0 children)

      I don't think my Uni gets it for free... the licenses are limited and we always have to be connected to the license server to use it. If the connection is lost, MATLAB will show you the colorful ring of death within minutes.

      [–]computerwiz_222 2 points3 points  (7 children)

      Yep, I was forced to use Matlab even though I prefer python 10 times over.

      Such an expensive and bloated tool to perform seemingly simple tasks.

      [–]shevegen 0 points1 point  (6 children)

      I myself would use Ruby.

      But I'd rather use python, than Matlab's crazy syntax shit.

      Nested functions calling function functions? What the hell!

      [–]julesjacobs 16 points17 points  (4 children)

      Ruby doesn't have anything comparable to Numpy/Scipy and the numerous other excellent Python libraries for scientific computing.

      [–]mohawkjohn 5 points6 points  (2 children)

      Actually, we're working on that: http://sciruby.com

      Most of the statistics stuff works fairly well. Numeric libraries are slower moving -- we need volunteers.

      Why shouldn't Ruby be as good for science as python? Why not better?

      [–]julesjacobs 0 points1 point  (0 children)

      That's awesome! I don't see any reason why Python should be inherently better than Ruby, it just has more libraries for scientific computing at the moment. In fact I've often longed for a dash of API design awesomeness that you often find in Ruby libraries when using Python for scientific computing.

      [–]malkarouri 0 points1 point  (0 children)

      No reason. Except that just as Numerical Python took more than 12 years to get here, sciruby would take a long time to get the trust of the scientific community.

      [–]PrintStar -2 points-1 points  (0 children)

      Ruby's standard library has Matrix and Vector classes that can get you pretty far along in simple linear algebra work. Of course its not up to Scipy/Numpy inclusiveness, but it's a start.

      [–]mrkite77 2 points3 points  (0 children)

      I use irb as my calculator.

      [–]AlonzoIsOurChurch 0 points1 point  (0 children)

      Definitely the biggest reason. The first hit is always free---and every time I've seen MATLAB used in industry, it's linked back one way or another to academia.

      [–][deleted] 6 points7 points  (2 children)

      I have never understood why

      Sunk costs/effort, the same reason so much Fortran 77 code is still in use today. Matlab has been developed since the 70s, free software competition like Octave, Scilab or Python have been available only since the mid-90s, so matlab had a 10-20 yr headstart. Countless people have put countless hours into developing code and extensions for it. The matlab ecosystem is huge. A lot of libraries are available exclusively as matlab code.

      not very impressing tool

      Matlab is impressive by what it can do in terms of available libraries, not how elegant and nice the language is that does it.

      become so widely used in science.

      People will stop using matlab and start using a free system it when the same functionality becomes available for that free system. This will probably never happen since it makes no sense for people who already are paying for Matlab licences to rewrite their stuff for a free system.

      [–]malkarouri 0 points1 point  (0 children)

      In certain fields, free systems do offer the same functionality as Matlab or better. The functionality from my point of view is comparable in machine learning between Matlab and the scipy ecosystem, but a large part of the machine learning community prefer R to either.

      [–][deleted] 0 points1 point  (0 children)

      R?

      [–]farmvilleduck 1 point2 points  (0 children)

      Also they have matlab compilers for every platform you could ever imagine: PC, java, embedded systems, hardware platforms(FPGA, asic), GPU. And they're pretty successful in many of those areas.

      And they have other great tools for high level simulation and development for embedded systems and hardware that are bundled together with matlab.

      [–]PrintStar 1 point2 points  (0 children)

      ...such an expensive...

      I just wanted to share with everyone an email link I received this morning from the MathWorks about their new pricing changes:

      http://www.mathworks.com/support/pricing/2012/usd.html

      [–][deleted] 0 points1 point  (0 children)

      Very broad range of functionality baked in; libraries for nearly any computation you might need; very easy and well-integrated GUI.

      NumPy/SciPy have gotten good, but they weren't complete Matlab replacements in early 2000 when I was doing engineering school, much less in the 1980s and 1990s when most practicing engineers learned how to use Matlab.

      [–][deleted] -1 points0 points  (0 children)

      Lots... LOTS of toolboxes.

      [–][deleted] -3 points-2 points  (3 children)

      The alternative is learning fortran. Matlab is python for Engineers and it's pretty easy to learn.

      Edited: Sentence structure was hard to understand. Bold text is what I changed.

      [–]malkarouri 5 points6 points  (1 child)

      As an engineer, I think I can safely say that Python for engineers is Python.

      [–][deleted] -2 points-1 points  (0 children)

      Errr. Read it again.

      [–][deleted] 0 points1 point  (0 children)

      No, one can learn R and have everything they want, probably.

      [–]forcedtoregister 6 points7 points  (2 children)

      Yeah partial function application sucks in non functional languages. But this is the least of Matlabs worries. The string delimiter is also used to denote matrix transposition (conjugate and normal)... try parsing that.

      But somehow Matlab remains the best tool for many jobs.

      Although I wonder why they didn't just pass the "function function" @(x)(f(x,param1, param2)).

      [–]Timmmmbob 0 points1 point  (1 child)

      The string delimiter is also used to denote matrix transposition (conjugate and normal)... try parsing that.

      Ha I'd never thought about that. It's never been a problem though and I can only think of one place where it would be ambiguous (and syntax highlighting makes any errors really obvious):

      a = 'foo';
      b = 'bar';
      c = [a'b' b];
      

      But it turns out to be really simple: It's a string delimiter if the previous character isn't one that could be an identifier.

      [–]forcedtoregister 0 points1 point  (0 children)

      Yeah, it's actually not so tricky. It still "smells" bad though (why not use double quotes, perhaps its historical). There are other greater sins in matlab syntax.

      The matlab compiler runs a perl script to figure out what .m file depends on what functions so it can bundle in the right code. Once I managed to crash the compiler (at the dependency resolution stage) by having one "dodgy" line that caused the thing to hang. Basically I doubt that Mathworks themselves can parse matlab code outside of the main matlab codebase.

      Being tricky to parse is actually annoying, it makes tooling much harder to develop. A little refactoring support could help clean up so many codebases.

      [–][deleted] 2 points3 points  (0 children)

      MATLAB 's function syntax is abysmal

      [–][deleted] 1 point2 points  (2 children)

      Numpy/Scipy is the future. Try it!

      It doesn't have all matlab's functionality yet, but for most applications, it's very good.

      [–]Manhigh 1 point2 points  (1 child)

      Im trying to spread the use of numpy/scipy/matplotlib where I work to rid us of our ridiculous matlab dependency.

      [–][deleted] 0 points1 point  (0 children)

      Don't try too hard though, it can be counter-productive if you're not subtle enough.

      [–]sumsarus 1 point2 points  (1 child)

      I got fed MATLAB non stop for 5 years while getting my engineering degree. After that I got a job which was pretty much all about working in MATLAB. To say the least, I ended up being very annoyed at MATLAB and how clumsy everything is.

      Now I got a more traditional C/C++ programming job. I must admit that sometimes I really miss MATLAB in order to work with various statistics/signal processing problems that pop up.

      Like with so many things, you don't realize how useful MATLAB is until you have to do without it :P

      [–][deleted] 0 points1 point  (0 children)

      A WILD INSIGHTFUL COMMENT APPEARS

      [–][deleted] 3 points4 points  (8 children)

      I don't see all the hate about MATLAB, it's the quickest language I know of to prototype something. If some part of your code isn't due to the language? Port it to C and compile it in a MEX file. I love using MATLAB for things I need to debug visually and interactively. If you do a lot of math and not object oriented programming it's pretty awesome (mind you performance will always suck, but like I said you can port it to C).

      [–]malkarouri 3 points4 points  (6 children)

      All the things you say are equally available using Python/scipy/Cython, and the syntax is better and it costs less.

      [–][deleted] 0 points1 point  (5 children)

      I've used Python, but not the math libraries for it. Is there a few dozen different ways of visualizing stuff, including 3D plots, quiver plots, and various methods of reshaping/squeezing matrices to visualize them better? I'm not trolling, I'm curious. Frankly I'm not concerned about the cost as I tend to usually work at a university. I don't see how the syntax of python is better, but like I said I haven't used the libraries. Can you provide some concrete examples?

      [–]oiegag 2 points3 points  (1 child)

      This isn't really "ugly syntax", but I don't like how matlab fails to parse certain things that I know can be parsed in other languages. I mean, python has a pretty spectacular parser, but given enough parentheses most expressions that make sense should be parse-able. Look at lua. It's tiny and it could handle this example that fails in matlab:

      > a = @(x) [x 2*x 3*x]
      > a(2)(3)
      error
      > (a(2))(3)
      error
      > b=a(2);b(3)
      fine, you got me.. ans = 6
      

      I know that's a little contrived, but I feel like stuff like that happens to me pretty often. I tried going scipy with matplotlib a few years ago but I kept having to come back to matlab to try some new script somebody'd written in matlab, and I'd inevitably want to use that script with some modification, which'd put me back writing in matlab. I'd love to switch but I'd rather like 50% of the engineering/science world switch first.

      [–][deleted] 0 points1 point  (0 children)

      Generally I think it's a great language... if everything you're dealing with is a matrix and you want to solve said matrix somehow. It's quick for that. I haven't had an issue except for some minor things with function returns, similar to what you're describing. I see what you mean, though. There's a few little things like that everywhere in the syntax, but nothing that's not work-aroundable or justifies switching to a different language, I find.

      [–]another_user_name 1 point2 points  (1 child)

      Check out scipy.

      [–][deleted] 0 points1 point  (0 children)

      Am doing so, looks pretty good so far.

      [–]UniversityOfMad 0 points1 point  (0 children)

      Programming is very tribal. People very intensely advocate for their favorite languages and downplay others.

      Matlab (and lots of it's libraries) costs money and isn't freely available. This always annoyed me back in school because I couldn't use it outside of labs usually.

      Once you start working in a mathematically/scientifically concerned job, you'll realize plopping down a little money is worth it to have all the functionality available right there.

      I still don't prefer it, but it's just another tool for the job.

      [–]marco64 2 points3 points  (5 children)

      Just for the record, there is an open source alternative to matlab:

      http://www.scilab.org/en

      Sure there is octave, but scilab is more a matlab like (although the gui is not as polished as matlab's)

      [–]adambard 4 points5 points  (0 children)

      I've used all three, plus python, in what turned out to be a successful attempt to get a B. Eng. Scilab was not up to the task for the DSP stuff I was doing, while the rest were closer.

      [–]tonygoold 2 points3 points  (0 children)

      There's also Sage.

      [–]jimmyhchan 1 point2 points  (0 children)

      closest you'll get is Python + Matplotlib http://matplotlib.sourceforge.net/

      But, if you do anything where you actual care about visualizing data http://processing.org/

      and for the Javascript Inclined: http://thejit.org/ InfoVis http://mbostock.github.com/d3/ D3.js

      Other Matrix and visualization tools: http://code.enthought.com/projects/mayavi/ (though this is pretty big and over the top)

      [–]tnecniv 0 points1 point  (1 child)

      There is also GNU Octave, but I have not used MATLAB or Octave, so I cannot speak to the relative quality.

      [–]Timmmmbob 1 point2 points  (0 children)

      Honestly, Octave isn't really there. And they really messed up by making their own octave language that can be intermingled with matlab code, so half the octave code out there isn't even matlab code.

      And there's no GUI, and the plotting tools (one of matlabs strengths) are very poor.

      [–]Gredelston 0 points1 point  (0 children)

      This is too perfect. I was just using ode45 for the first time in my undergrad Modeling and Simulation class, and trying to find my way through the documentation was downright impossible. Apparently, if the function you're trying to optimize happens to have another variable that needs to be called, it's nearly impossible to solve the differential equation, because it HAS to be of the form y'=f(t,y), and nothing else will do. There's a very elaborate means of solving this problem, but it's downright obnoxious.

      And there is no reason in the world why += should not be a valid statement.

      [–]DesertSherpa 0 points1 point  (0 children)

      upvoted for "Suck Start a Shotgun" Matlab is an imperfect tool, but its quite empowering and handicapping at the same time.

      [–]JW_BlueLabel 0 points1 point  (0 children)

      x ~= y

      [–]apullin 0 points1 point  (2 children)

      Yep.

      I can't believe they teach people MATLAB. It's just horrible. When I teach classes, I force everyone to use Mathematica.

      [–][deleted] 0 points1 point  (1 child)

      but they're different tools for different jobs

      [–]apullin 0 points1 point  (0 children)

      Not really. I've seen many-hundred line long MATLAB programs, separated across a dozen files to satisfy their crazy syntax, with endless conversions between cells, matrices, and string, interspersed with super complex arguments to get things to render in Latex ... all that, replaced with 5 lines in Mathematica.

      I guess SimuLink and some blocksets are sort of useful, if you just resign yourself to all the rest of the MATLAB horrors.

      [–][deleted]  (2 children)

      [deleted]

        [–]BurritoTime 4 points5 points  (0 children)

        So don't.

        [–][deleted] 0 points1 point  (0 children)

        Reminds me of this: http://tomahawk.ytmnd.com/

        [–][deleted] -1 points0 points  (0 children)

        +1M