Anyway to avoid the + and @ nasty-ness in MATLAB?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm trying to organize a large codebase by using packages. Quite frankly, the + and @ namespace nonsense is infuriating. It makes navigating at the command line painful, + and @ are often reserved for other purposes in Windows and Linux, and the requirements for having classes nested in folders and requiring import specific members are just silly IMO.
Is there any way to avoid this? Any plans to change it? Or should I just give up on using namespaces for organizational purposes?
Regards,
Isaac
2 个评论
John D'Errico
2023-2-9
You don't show explicitly what it is you don't like. And of course, not everybody hates what you seem to dislike so terribly. Some surely use the feature and like it. Which just says if you don't like it, then don't use it.
回答(2 个)
Walter Roberson
2023-2-10
Although I am not a Mathworks employee, I have enough experience with Mathworks to doubt that there are plans to change this (or at least plans that would be more to your liking.)
It is within possibility that autocomplete / code hints might be improved for packages and classes, but IMHO Mathworks is highly unlikely to rework the class and package systems specifically to avoid using regexp metacharacters. The few ASCII characters that are not alphanumeric and are not metacharacters in any context, tend to also be forbidden in filenames for major operating systems. For example colon : is not (that I recall) ever meta but in Windows colon is strictly reserved for drive letters and device names such as NUL:
1 个评论
Walter Roberson
2023-2-11
I checked more carefully. The characters that are never meta in regexprep() are:
- ~ (tilde) -- used a lot in Unix shells, so using ~ as an introducer would cause problems
- % -- valid in filenames on Unix and Windows, but requires constant escaping when computing filenames with sprintf() and compose()
- _ (underscore) -- better than many of the other possibilities, but is matched by \w so it is not really clean from a regexp perspective
- ; (semicolon) -- command separator in Unix, used as separator by path
- " (double-quote) -- illegal in Windows filenames, gets messy when constructing external command strings
- ' (apostrophe) -- legal in filenames, but gets messy when constructing external command strings, and requires care in constructing character vectors in MATLAB.
The least bad of these is underscore. A single character. So if use with regexp becomes a primary driver, then Mathworks will need to encode both behaviours (classes and packages) into a single character.
Using regexp with packages already requires escaping period, so unless you think that Mathworks also needs to change the chain-of-periods naming convention for package elements to make it easier to use regexp, just call regexptranslate with the 'escape' option.
Jan
2023-2-9
移动:Jan
2023-2-9
Matlab is a programming language. Each language, also the spoken ones, have features, which can be likes or disliked. This is not the point, because languages are used to communicate, and in case of programming languages the goal is to solve a problem.
The + and @ name spaces are a feature of Matlab. They are part of the language and not "nonsense". Use them, if they help you to solve a problem, or don't use them, if not. You can also decide to use another language, if it is more efficient for solving your problem.
I do not see, why + and @ impedes the navigation in the command line, and in my Windows and Linux setups these characters are not reverved for another purpose.
"Is there any way to avoid this?" - Yes: Don't use classes and packages, but the old style folders. Or, of course, another programming language.
"Any plans to change it?" - I'm a Matlab user, not its designer. I do not assume, that this is subject to changes.
"Or should I just give up on using namespaces for organizational purposes?" - If these methods makes your life as programmer harder, avoid it. They are designed to be useful, but of course not every tool hits every problem.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!