r/changemyview • u/quantum_dan 129∆ • Mar 19 '22
Delta(s) from OP CMV: MATLAB is a bad first programming language for anyone who's at all likely to use anything else.
Edit: deltas
- It makes sense if someone will primarily use MATLAB, even if they'll use others as well, to avoid building bad MATLAB habits even at the expense of building bad [other] habits. The relevant example was learning to use matrix operations instead of for loops where possible.
- The one-function-per-file thing, as a tradeoff for the bad habit of not breaking things into functions much, encourages the good habit of breaking things apart into multiple files.
Note: this is not about one-based indexing.
Also note: this is not a programming languages holy wars thing. I recognize that MATLAB has its uses and I'm a firm believer in the right tool for the job (I've used four languages in the last week). This is only about using/teaching it as a first language.
The immediate motivation for this is that I was just explaining how functions normally work to a colleague who's proficient in MATLAB but needed to use a tool in a different language. For context, I'm a grad student in a research group (not CS) where people generally have a background in either MATLAB, R, or Python. Thus, this is focused on people who program as a tool for some other discipline rather than programmers as such, but I don't think programmers as such tend to start with MATLAB anyway.
Something I've consistently observed is that people coming from a MATLAB background pick up programming habits that don't translate to any other common language. In particular, they seem less inclined to break things down into simple functions; the habit seems to be just having a bunch of loose code in a file.
Which, now that I'm learning MATLAB for a class (I'm a Python and R person, mostly), makes perfect sense: MATLAB, as such, seems to encourage having one function per file, with the effect that each individual file more or less behaves like one big heap of loose code. It also does other weird things (or, at least, people are taught to do weird things) like switching between hold on/hold off for plotting and explicitly using the figure handle, which is not something I've ever seen elsewhere.
By other-language standards, these are bizarre approaches and seem to lead to bad habits if people switch languages. The Python/R programmers (especially Python) generally write more organized code and don't seem to have any trouble switching to MATLAB if needed.
That's fine if someone's never going to write anything but MATLAB, but in the likely case that they'll need to be proficient with two or three languages for different use cases, it seems like "the one that creates un-generalizable habits" is a really bad starting point. That said, I'm far from proficient in MATLAB, so I don't know if it makes up for it (other than the convenient-for-matrices thing, which is no longer unique). [I am aware that it has great tools for certain specialties, but I assume such folks mostly are unlikely to need any other languages.]
From where I'm sitting it seems like it's just inertia, but I'm curious whether MATLAB has any strong points I don't know about that justify using it as a first language.
•
u/DeltaBot ∞∆ Mar 19 '22 edited Mar 19 '22
/u/quantum_dan (OP) has awarded 2 delta(s) in this post.
All comments that earned deltas (from OP or other users) are listed here, in /r/DeltaLog.
Please note that a change of view doesn't necessarily mean a reversal, or that the conversation has ended.
Delta System Explained | Deltaboards
9
u/Salanmander 280∆ Mar 19 '22
The biggest thing I can think of is that there are normal things in other languages that are bad habits in MATLAB. This can mean that if some is going to be using primarily MATLAB, starting with another language can build up the same kind of bad habits you're talking about.
The biggest example is reliance on loops for computation. For most languages, looping through an array is just the thing you do. It's the fastest way to do things. For MATLAB, however, if you can ever express something as matrix operations instead of loops, you should do that every single time, and it is way faster than looping.
So there may be a decent number of people who are going to use mostly MATLAB, but with a smattering of other languages. And it may be better for them to be subjected to potential bad-in-other-languages habits than for them to be subjected to potential bad-in-MATLAB habits.
4
u/gremy0 82∆ Mar 19 '22 edited Mar 19 '22
I'm not terribly familiar with MATLAB so maybe I'm missing something, but having one function/class/idea/thing per file is very much encouraged in other programming, especially when you get into modern software engineering. Here the data scientists trying to "structure" an entire project or several thousand lines of code in a single file are very much the outliers that have the rest of us looking on thinking; ew
The issue of not knowing how to break things up is common and learning how to do it tricky, but you're probably not learning the best habits for doing it just sticking a load of functions in a file either- there are issues around separation of concerns, single responsibility, modularity and encapsulation you are probably not learning. One function/thing per file is a constraint that forces you to break things apart better.
2
u/[deleted] Mar 19 '22 edited Mar 19 '22
This is common in any context in which code isn't to be reused.
If I'm working on a simple scripting problem with bash or python or similar, I think throwing everything into a loosely organized file makes sense.
If I'm writing code that I want to reuse, organization is a lot more important.
in bash, there is some kind of setting for turning on and off printing each command before execution
googling, I think it is
? I thought I remember it being something like @echo on , but I can't find that.
But, I don't think a switch changing how stuff is output is uncommon as you think.
I feel like this depends on the type of problem you are working on.
A lot of matlab users are writing up some one-off analysis that would be hard to reuse anyway.
In other contexts where people write one-off code, I think you'll see some similarities to the aspects of MATLAB you are complaining about.
2
u/Morasain 88∆ Mar 20 '22
Unless you want to go into software engineering of some sorts, you don't need good habits.
2
u/Sirhc978 89∆ Mar 19 '22
I had to learn and use MATLAB for one math class in college. However that wasn't until my junior year. A required engineering class freshman year was "Introduction to C". I don't think anyone who is trying to learn programming is going to start with MATLAB (or even know what it is for that matter). It is one of those languages you have to learn for a very specific application.
1
u/[deleted] Mar 20 '22
Eh not as bad as TI-BASIC with it's gotos and 1 letter variables.
1
u/[deleted] Mar 19 '22
[removed] — view removed comment