Request about comment char % vs C++ //

I'm switching back and forth between C(++) for my Arduino Pico and MatLab App Designer
It would be really nice if when I type // to start a comment you could switch it to %
You have so much help in completion of typed stuff this shouldn't be hard for next release.
I'm getting the hang of MatLab but it can still be irritationg for "real" programmers. :-)

11 Comments

John D'Errico
John D'Errico on 13 Jul 2024
Edited: John D'Errico on 13 Jul 2024
That seems a little arrogant if you ask me, as if MATLAB is a toy language, while you are a real programmer. (I've learned and used something like 15 different languages over the years at one counting. My language of choice is MATLAB.)
Anyway, you are acting as if Answers is a direct line to tech support, or to the people who build and develop MATLAB. It is not. Answers is just a purely volunteer forum. As such, remember that all of the people who frequent this forum are here generally because they like MATLAB. There is no need to insult them, even in jest.
As @John D'Errico notes, submit a enhancement request to official support although don't expect it in the next release; even if were to make the grade, it'll take time to percolate to the top of the "todo" list...
So, to be clear on the request, you are asking that the MATLAB-specific programming interface recognize (in real-time) that you are typing a comment character from C++, and convert it to a MATLAB comment character?
Should it also do that for other C++ syntax, like if you accidentally type x++, MATLAB should convert that to x = x+1?
What about other languages? Should it recognize the comment character # from python and R, and convert that?
What about JavaScript, PHP, Swift, Rust, Ruby, Go, and Kotlin?
Just trying to understand the spec.

I understand the question a bit differently: if you accidentally type // it should be replaced by %.

There are already some autocorrect features in Matlab, so I don't expect such an autocorrect to be an unreasonable request. In the mean time you could look into autohotkey to see if you can do the replacement that way.

How complex would it be to instead allow alternate form of comment character? That would require changing the parser, of course, does it interfere with any other use of "//"?
Stephen23
Stephen23 on 14 Jul 2024
Edited: Stephen23 on 14 Jul 2024
Which comment characters should be supported?:
As "real" programmers use many languages MATLAB would need to support all of them (past, present, & future).
dpb
dpb on 14 Jul 2024
Edited: dpb on 15 Jul 2024
Same Q? as @the cyclist raised regarding which "mistakes" should be converted in edit mode.
I'm ok as is although my mistypes would tend to be either ' (VBA) or ! (Fortran) if were again actively consulting as those were the two alternatives I used frequently enough to have developed habits (and my Forth time period is now so long ago I have no retained habit of it although I loved using it at the time). I never liked the // even if had to use C and avoided C++ entirely.
But, since Mathworks controls MATLAB, I see no reason if were to choose they couldn't just pick and choose arbitrarily as they do for everything else as what to introduce and what to deprecate; there certainly isn't anything that would require to support everything possible.
Which comment characters should be supported?
And how should we handle the cases where either 1) the comment character already has a meaning in MATLAB (', !, ;, --, *, ||, ", and \) or 2) in the future we decide to use one of those comment characters that doesn't already have a meaning in MATLAB for a new operator?
It's rare that we introduce a new operator to MATLAB, but it has happened. Shortly before I started we introduced the ability to create function handles using the @ operator, and during my tenure here we have introduced the ? operator to create a metaclass object from a class name and the " operator to create a string. If we were to introduce an operator # (choosing one of the characters from that Wikipedia list that doesn't have meaning in MATLAB already) does that mean that users who had gotten used to having the Unix shell comment character automatically replaced would suddenly lose that functionality?
Frankly, I think it probably should NOT change; not even all that enamored with the idea for the autocorrect featured...
As long as it remains an optional autocorrect (just like the indent and inserting an end when writing for and if), what would be the problem?
I suppose nothing, really, I guess I got too much into thinking of the language itself after my initial gut reaction that it could be similar to the selectable comment character when reading data files and the subsequent "toss it out for comment". Other than adding more to the editor that already seems to be slow....

Sign in to comment.

Answers (1)

Samantha
Samantha on 16 Jul 2024
Edited: Samantha on 16 Jul 2024
You could simply control F and replace all the // with % as I do, I attached an image below.
There really is no need to add this into the program as long as ctrl F exists. FYI matlab IS a real coding language and it's my code of choice for lots of data manipulation and programming. Please try to be mindful that some people use this daily in their work or schooling (I know I started off using it in college for lots of data aquisition stuff), or this might be someones first coding language and they get to deal with a pretentious "real" coder answering their questions.

Products

Release

R2023b

Asked:

on 13 Jul 2024

Edited:

on 16 Jul 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!