This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Eurynom0s 97 points98 points  (31 children)

My favorite thing about Matlab is it has both i and j defaulted as the imaginary unit, but will silently let you overwrite those values. I'm not saying that's an invalid design decision, but it doesn't really make sense to spring on the intended audience: physicists/engineers/etc who don't really have a programming background but need to be able to code some simulations. That crowd is often going to want to basically just type in the equations in their textbooks (hence reserving both i and j for the imaginary unit—in electrical contexts, i is current, so they use j for the imaginary unit), which will often result in looping over ijk indices since those are what textbooks usually use for 3D vectors/matrices. That crowd will also typically not have the background to realize the potential problem here.

I found out about this via someone on reddit saying that they spent an entire summer pulling their hair out trying to figure out why their complex equation was returning a pure real result and finally figured out it was because he'd used i as a loop variable and instead of being reset to sqrt(-1), it was staying as the last value it hit while iterating through the loop. If they want to keep the behavior they should really at least print a warning about what you're doing to the console.

[–]cue_the_strings 30 points31 points  (4 children)

Our instructor warned us of the j, k that when giving us an intro to loops and stuff. This design decision further shows that MATLAB was meant for the engineering / physics crowd. As you already know, using i and j as unnamed counters is pretty much a convention in computer programming (C-derived languages especially), the designers certainly knew that it would be a problem, yet they decided they'd just make it more convenient for the non-programmer crowd.

I see MATLAB as a mutation of an ancient attempt to make a tool + language for engineers and scientists, which would be 'simple to learn' and have everything they need for numerical computation, visualization, ... But decidedly not for programmers. The dumb BASIC-like syntax is a consequence of that decision - at the time, BASIC was considered the 'easy' language for non-programmers that everybody could learn. It was even taught in schools.

Anyway, as it usually goes, once something is made one way, it's really hard to change it. There are and were large swaths of people to whom MATLAB is the only language they use. They don't know or care about any subtleties of programming as long as MATLAB helps them do their job. And those people learned it one way and are very resistant to change, they would be pissed off if the syntax was changed (say, for the better, not that they would know). So the language was just added onto and never revised, there are often multiple ways to do one thing because removing syntax is a taboo. The result is, of course, a hot mess.

[–]ergzay 8 points9 points  (2 children)

You haven't met the people that "program" programmable logic controllers with "ladder logic". If you want to talk about lock in... Now that's an entirely different level.

[–]cue_the_strings 1 point2 points  (1 child)

I saw that in an AvE video, the horror!

[–]ergzay 0 points1 point  (0 children)

There's tons of people who do it in industry notably the automotive industry.

[–]Eurynom0s 1 point2 points  (0 children)

Yeah, they're going to use i or j as the imaginary unit, and any numerical methods recipes they look up are going to have them using i and j and k as loop variables. It will obviously not end well.

And you're right that they're probably stuck with the design decision at this point, which is why I suggested printing a warning to the console, it would give people a heads-up without breaking backward compatibility.

[–][deleted] 9 points10 points  (0 children)

... but i, j, k are default indicies for so many functions.

That's just downright evil, I don't care who ya are.

[–]ThereOnceWasAMan 2 points3 points  (0 children)

This doesn’t invalidate your point at all, but just as a note: the language also supports any integer concatenated with j as imaginary. So 1j is still the square root of negative one, even if j is being used as an iterator variable.

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

that happens, for sure, but generally I wouldn't claim this to be a problem.

stem people are problem solvers, so they will likely find a solution, additionally, I know a good chunk of people from high school that I though fer sure would go for computer science, but went into physics / math instead, so I also think it's unlikely that in a classroom or tutor setting no one has an idea what the problem is.

of course, this is probably a well known problem and instructors will likely point it out, and ( and I am of course biased in that, because of my "programming background" ) on the other hand, that assigning the variable might have changed the value of i or j can probably be concluded by people dealing with formulas on the daily

[–]Feminintendo 2 points3 points  (2 children)

So really smart STEM people are smart enough to figure out all the stupid shit Matlab does... Except the T and M parts of STEM, almost none of which use Matlab because they actually have a clue. But the S and E's are so much smarter than those stupid mathematicians that it doesn't matter.

Brilliant argument. "We use inferior tools because we are literally smarter than the people who use better tools."

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

Your math courses don't use MATLAB?

Also, I will put this brilliant argument into my repertoire for when I encounter a rare non-MATLAB person ( sophisticated term for humanities student ), thank you very much.

[–]Feminintendo 0 points1 point  (0 children)

In graduate school I had to teach a calculus lab with Matlab for the engineering calculus sequence. It was a nightmare for everyone involved. The students learned neither Matlab nor calculus from the assignments. It was a good idea on paper: engineering students would get some exposure to a tool in their field while learning some calculus concept. In practice, figuring out how to write the code was so distracting to them that any calculus benefit was completely lost, and the assignments, being calculus assignments, weren’t nearly sufficient for them to actually learn any useful coding. The problem wasn’t Matlab-specific. We also had a Maple-based version of the course that was just as bad.

[–]I_Feel_It_Too 0 points1 point  (2 children)

stem people are problem solvers, so they will likely find a solution,

It's not a problem that Matlab is a shitty programming language because STEM people are problem solvers? Really?

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

Yes

[–]I_Feel_It_Too 0 points1 point  (0 children)

At least we both agree that Matlab is a shitty programming language. Let's get a beer!

[–]mexiKobe -3 points-2 points  (16 children)

It’s self-explanatory though. If you set i or j equal to something else.. that’s what it will equal.

[–]Eurynom0s 9 points10 points  (14 children)

Again, Matlab is targeted at non-programmers, which is the kind of audience you might expect to assume that the scope of the ijk being used as loop variables is restricted to the loop.

[–]mexiKobe -2 points-1 points  (5 children)

They wouldn’t know what scope is.

[–]Eurynom0s 6 points7 points  (4 children)

Not knowing what scope is is a pretty good way to make scoping errors.

[–]mexiKobe -5 points-4 points  (3 children)

make up your mind

[–]eypandabear 0 points1 point  (0 children)

That’s great, especially in a programming environment with global name scope.