No video

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

  Рет қаралды 383

CodingLikeMad

CodingLikeMad

Күн бұрын

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

Пікірлер: 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!!
Why Eval And Exec Are The WORST Python Functions [Tech Rants]
22:16
CodingLikeMad
Рет қаралды 1,9 М.
⚡ Why is MATLAB the way it is? - Oliver W
12:45
UWCS - University of Warwick Computing Society
Рет қаралды 2,3 М.
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 13 МЛН
拉了好大一坨#斗罗大陆#唐三小舞#小丑
00:11
超凡蜘蛛
Рет қаралды 14 МЛН
Dad Makes Daughter Clean Up Spilled Chips #shorts
00:16
Fabiosa Stories
Рет қаралды 3,1 МЛН
Violet Beauregarde Doll🫐
00:58
PIRANKA
Рет қаралды 36 МЛН
The Most Legendary Programmers Of All Time
11:49
Aaron Jack
Рет қаралды 552 М.
Anonymous Function Handles In Matlab - Advanced Matlab Tutorial
11:15
How To Fix Missing Data In Matlab [Machine Learning]
12:21
CodingLikeMad
Рет қаралды 4,5 М.
MATLAB vs Python for Engineers
5:53
Vincent Stevenson
Рет қаралды 50 М.
AI Destroys NES Tetris On A REAL Nintendo!
9:58
CodingLikeMad
Рет қаралды 5 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 398 М.
MATLAB and Python
1:45
Real Industry
Рет қаралды 13 М.
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 13 МЛН