5 ms·
IMO Matlab is the worst programming language widely used in production. This perfectly fits my expectations of Matlab: - i is a mutable, but should be constan
by fosap 14y ago
IMO Matlab is the worst programming language widely used in production.
This perfectly fits my expectations of Matlab:
- i is a mutable, but should be constant
- It has a horrible, non obvious name because mathematicians are used to it. (And they are not used to var names longer than two chars)
- It is in the global scope.
- It's a feature that has a special syntax (sort of).
/edit Apologies for php programmers, maybe php is worse. But I'm not sure.
- _pmf_ 14y agoHaving worked with both Matlab and VBA, it's hard to say for me what is worse. Nowadays, whenever I have to do something (UI, non-numeric data processing) in Matlab, I tend to write a Matlab-shim that calls a Java-component (the Java interaction is fortunately very nice). The mere fact that one gets things done with less hassle in Java than with a scripting language is a quite damning verdict for said scripting language.
- nemetroid 14y ago> - i is a mutable, but should be constant It's not really mutable, because it isn't a variable. However, if there is a variable by that name, Matlab will use it instead of the complex constant. > - It a feature that has a special syntax (sort of). The problem is rather a lack of special syntax (or too much leniency). Python also has built-in complex numbers: >>> 1 + 1j (1+1j) but it doesn't allow you to omit the constant before the j: >>> 1 + j Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'j' is not defined You can do it the same way in Matlab to avoid this problem (1 + 1i is always OK since implicit multiplication is not allowed), so the problem is that Matlab lets you use i syntactically like a variable when it in fact isn't.
- fosap 14y ago>It's not really mutable, because it isn't a variable. However, if there is a variable by that name, Matlab will use it instead of the complex constant. This is what i mean with a sort of special syntax. It's awful corner case. I don't like the Python syntax either. What would be wrong with Math.C(1,1) for 1+i? Or how about 1 + Math.I ?
- potatolicious 14y agoThe idea is expressivity - your solution seems boilerplatey and doesn't scale to longer expressions. The idea is to make math expressions as easy to write (and read) as it would be on paper, or at least get as close to it as possible. I don't have a problem with using i or j as the complex constant, as long as the necessary sanity checks exist to make sure it's not misused (e.g., duplicate declaration of i/j, overwriting i/j, etc).
- andreasvc 14y agoWell it is more verbose which matters if you do a lot of complex math. IMHO i, j, l should be avoided as variables anyway, as they are too similar visually; I prefer a, b, c & n, m for loop variables and indices.
- andreasvc 14y agoIt will only give that NameError if 'j' is in fact undefined; 'j' can be used as a variable which would lead to a similar bug in Python (and why is it 'j' instead of 'i' ... they're both common one-letter variables).
- DoubleMalt 14y agoElectrical engineers use j instead of i to distinguish it from current (that is commonly referenced by i).
- shardling 14y agoWhereas physicists use capital I for current. (And J for the current density.)
- fosap 14y agoI have seen j for current density only so far. But physics are convinced you can tell the difference by context (which is usually true, but probably impossible for a compiler, even if physics is "typed" with units). For handwritten text at least my professors managed to come up with at least two different ways to write each letter to avoid confusion. My (not serious) attempts to use Chinese characters haven't been very successful.
- nemetroid 14y agoThe difference is that in Matlab, 1 + j is valid as a complex literal and equal to 1 + 1j. In Python it is never valid to write j as an implicit 1j, so this particular bug (a correctly working function stops working because you've put a new name into scope) can't arise. The use of j is common in electrical engineering, where i denotes current.
- jerf 14y agoj is the abbreviation used by some disciplines; see the third paragraph of http://en.wikipedia.org/wiki/Imaginary_unit http://en.wikipedia.org/wiki/Imaginary_unit .
- 14y ago
- geon 14y ago> if there is a variable by that name, Matlab will use it instead of the complex constant. Sort of like how PHP will treat undefined constants as unquoted strings. Like if that made any sense... At least PHP will trigger a warning if you do that.
- fafner 14y agoMatlab and PHP are very similar in their history. They weren't invented by programming language designers or compiler writers. The creators saw a problem and came up with a makeshift quick solution. Which sucked but was good enough to solve the problem. Matlab was created to provide a simple way to make FORTRAN Libraries available to non-programmers. And it was quite successful at that. It was quickly picked up by engineers and all kinds of features were piled on top of it. And the worst thing is that Matlab is a de-facto standard in many areas now. As a webprogrammer you can probably easily avoid PHP by using Python, Ruby, JavaScript, Perl or whatever. But in engineering many people only know Matlab. They don't care about anything else.