Тёмный

This Could Be Matlab's Worst Feature [Matlab Rants] 

CodingLikeMad
Подписаться 3,4 тыс.
Просмотров 377
50% 1

Function shadowing is, in my opinion, Matlab's worst feature. Unlike compiled languages like C and C++, Matlab let's you overwrite builtin functions with local variables. This creates opportunities for tons of bugs, and I think more people should know about this! learn matlab matlab programming matlab functions matlab basics

Наука

Опубликовано:

 

17 окт 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 7   
@michellehirsch2235
@michellehirsch2235 3 года назад
Thanks for this really interesting video. I agree with you that when a variable shadows a function, it can be extremely tricky to identify, diagnose, and fix bugs in your code. I think mthiese's answer does a good job of explaining why MATLAB behaves as it does. The reality is that for most users, most of the time, this isn't an issue and it's nice to not have to think about this. Even with one of your examples - it's no problem at all for you to use beta or gamma as a variable name, as long as you don't need to call the beta or gamma functions from within the same workspace (e.g. within the same function, or if you work a lot in the base workspace and don't have a habit of clearing it occasionally). I would guess that >99.99% of the use of beta and gamma as a variable name are without running across shadowing issues. Of course, another big reason that MATLAB behaves this way is because this is how MATLAB behaves. Before you say "Thank you, Forrest", what I mean is that this design decision was made decades, and billions (trillions?) of lines of code, ago. A change in behavior could have a catastrophic impact on compatibility of this code. All this still begs the question - given the behavior, how can we make it easier if you hit this issue, or easier for users who are ruthless about robustness to ensure that they don't get caught by this. We've discussed the idea of a code analyzer warning for this issue for years - a warning that tells you if a variable shadows a function. We don't think we would want it on for everybody all of the time because we expect that it would be noise most of the time (per my earlier conjecture about beta and gamma), but we could have something you can optionally turn on. There are some other technical hurdles I won't get into now, but I don't think they are insurmountable. BTW, I'm head of product management for MATLAB, so I'm speaking from deep inside MathWorks.
@CodingLikeMad
@CodingLikeMad 3 года назад
Thanks so much for the insight, I really appreciate it when I hear from insiders. I'm absolutely in agreement with your point of backwards compatibility - this is one of Matlab's primary strengths, and removing shadowing would break it catastrophically. The "cure" would certainly be far worse than the "disease" here. That said, a warning would be nice, and I think a reasonable compromise for organizations with more complex needs, and can be turned off (or on) depending on the level of the user or at an institutional level.
@mthees08
@mthees08 3 года назад
I think the reason they allow it is that they want matlab to be accessible to a broad audience. If you are an 18 year old freshman using matlab on you phys101 homework you want to be able to have variables alpha beta delta gamma etc, and you won't care that they are also (sometimes) very specific functions in math. Two or three years later in your big boy quantum class (tongue in cheek here a bit) now you are using those functions and you will call them and at that point hopefully you have learned to be more careful and name variables things like var_alpha var_beta var_gamma... Etc. This is also consistent with the idea that there is no formal definition of most variables in the code and everything can be defined on the fly. It goes against best practices but it makes the pseudo code to runnable code conversion easier. Alternatively you can do everything in fortran90 where all variables are explicitly defined (unless you are a savage who does not set implicit=none).
@CodingLikeMad
@CodingLikeMad 3 года назад
It might be related to ease of use for sure. The fact that with a lot toolboxes installed, the natural number of functions in scope can be massive might have been causing problems for people, so they just decided to allow you to overwrite them as you wanted. Really the lack of transparency about it is my main issue. At least if there was a warning things would be easier to watch out for.
@majorseanli
@majorseanli 3 года назад
Nice mustache
@CodingLikeMad
@CodingLikeMad 3 года назад
Thanks! It has caused me great controversy:p
@norwegianoot4124
@norwegianoot4124 3 года назад
WHERE IS T SPIN BOT!!
Далее
The last one surprised me! 👀 🎈
00:30
Просмотров 3 млн
Erdős-Woods Numbers - Numberphile
14:12
Просмотров 52 тыс.
⚡ Why is MATLAB the way it is? - Oliver W
12:45
Просмотров 2,2 тыс.
MATLAB and Python
1:45
Просмотров 12 тыс.
Should you learn Matlab when there’s python?
0:14
Просмотров 1,1 тыс.
Why is Matlab so Bad?
2:06
Просмотров 4 тыс.
5.5 Math Books For Self Made Mathematicians
25:50
Просмотров 23 тыс.
Get Excel Worksheet Name by Index
4:01
Просмотров 19
Python Tutorial:  Inputs Explained
7:23
Просмотров 33
XIAOMI для настоящих МУЖИКОВ!
0:34
Просмотров 292 тыс.