variable name length exceeds 63 characters

294 visualizaciones (últimos 30 días)
Diana Acreala
Diana Acreala el 25 de Jul. de 2011
Editada: Stephen23 el 19 de Ag. de 2023
Hello, I'm new here:) maybe you can help me with a problem. I need to use some variables whose names are exceeding 63 characters. Does anyone have any idea? I must fix this problem quickly:D
Thanks in advance!
  1 comentario
Nathan Greco
Nathan Greco el 25 de Jul. de 2011
As always, examples help. What do your variable names look like?

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 25 de Jul. de 2011
Your demand for more than 63 characters sounds, like you store important values in the name instead of the contents of a variable. A program using such long symbols is nearly unreadable and debugging will be ridiculous hard.
Beside the fact, that the limit of 63 characters is hard coded and cannot be changed in MATLAB, I assume that there is a misconcept in your program design. Please explain, why you want to stuff so much information in the names.
  10 comentarios
Rik
Rik el 30 de Nov. de 2020
The workaround is to not store data in a variable name. I have not yet seen a case where there was a legitimate need for variables over 63 characters. Can you provide more details? I'm here to learn, so your use case might be the first I see.

Iniciar sesión para comentar.

Más respuestas (7)

AL REY
AL REY el 14 de En. de 2020
Hello, I might reopen this topic. But i would like to add a reason why we do have so long name. On my side i'm using '.mf4' data from CANAPE (Vector), the recorded label are often the software structure and exceed the 63 limit, it's also something that we can change unless we change the software dictionary. Some native matlab function (blockset) as mdf('name.mf4') and read can't deal with such naming.
It will be nice to have a way to avoid that limit.
  1 comentario
Walter Roberson
Walter Roberson el 15 de En. de 2020
Editada: Walter Roberson el 15 de En. de 2020
Make the recorded label data rather than a variable name at the MATLAB level.

Iniciar sesión para comentar.


James Marriott
James Marriott el 20 de Jul. de 2023
Editada: James Marriott el 20 de Jul. de 2023
Sorry to re-open this question again, but I too have a need for >63 characters but in Simulink, who seems to inherit the 63 character limit chosen by MathWorks.
The reason for this need is that Autosar has started allowing 128 characters for variable names and the MISRA C 2004 rule 5.1 has been superseded by MISRA C 2012 “different external identifiers be distinct within the limits imposed by the implementation” (emphasis mine)
This means now interface signals in autosar are being meaningfully named with use of 128 characters, but then in Simulink we are having to try and contain the same meaning in only 63 characters, this is leading to a significant loss of readability and traceability within the models.
This is made even worse by having enumerations having the same restrictions. I agree that variable names >63 can hinder readability of code, but enumerations often are required to convey a greater meaning within them, so require >63 characters.
I really hope in a future release this limitation is removed, as it is making integration with our lower-level software a real challenge, and some teams are moving away from the toolset, whilst a agree it may not be desirable to use such long variable names, it should be up to the developer to decide, not MathWorks.
  5 comentarios
Rik
Rik el 18 de Ag. de 2023
Is the variable name the best way to do this? This sounds to me like you are storing data in variable names. You might want to consider creating a system that scales beyond a few dozen characters, since this setup will reach the limits of practicality, even if MathWorks decides to change the limit in version 10.
Stephen23
Stephen23 el 18 de Ag. de 2023
Editada: Stephen23 el 19 de Ag. de 2023
"The struct names are made of several small, underscore-separated identifiers that tell the user where the data came from (e.g., test-type_lab_section_group_date_sample"
Meta-data is data. Data should be stored in variables, not in variable names:
Your current approach is a dead-end: it forces you into writing slow, complex, fragile, inefficient code to generate/parse those awkward, fragile, looooong variable names. Best avoided.
"we hope to be able to allow users to see each full struct name to distinguish between them, without having to open the structs"
Better data design would store all of that meta-data in those structures (note that you can add any number of fields you want to a structure, and that you can store the (meta-)data in its native class/type rather than awkwardly force everything into text). If the intent is to lets your users compare/select (meta-)data, then MATLAB offers much better approaches (better than forcing your users to read and compare lots of loooooong variable names): e.g. GUIs, the variable viewer, etc. for which a table or similar might be a useful data type.
Hopefully you do not have lots of those variables imported into the workspace.

Iniciar sesión para comentar.


Oleg Komarov
Oleg Komarov el 25 de Jul. de 2011
Cannot help, but why do you need such long names?
Names are meant to identify quickly a variable, if you're trying to include meta data in the name I would rather suggest to create a structure with meta fields and data field.
s.description = 'longdescription'
s.place = 'myPlace'
s.data = 10;
EDIT
To search for files keep a cell array with short names (the ones you actually save the file as) and the long ones:
names = {'ak47_19992102', 'long description'
'ak47_19992102', 'another long description'};
search on the second column and match with teh real names.
Or using the struct array you can search through all the s.description
Also, are you using/planning to use eval?
  2 comentarios
Diana Acreala
Diana Acreala el 25 de Jul. de 2011
Movida: Rik el 20 de Jul. de 2023
Variable name must be explicit, among others should include the name of a graph axis and exceeds 63 characters (to do a search when needed).. it's a must to do this and I can't find any solution..
Thanks for you answer :)
Oleg Komarov
Oleg Komarov el 25 de Jul. de 2011
Movida: Rik el 20 de Jul. de 2023
Se the edit in my answer.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 25 de Jul. de 2011
This is not possible in MATLAB.
Perhaps it would make more sense to break your variable up in to a structure. For example, instead of
one_two_three_four_five
you could use
one.two.three.four.five
which would be a structure array.

Walter Roberson
Walter Roberson el 25 de Jul. de 2011
Possibly the Map Container would be suitable for your work, allowing you to index variables according to arbitrary strings. See here

Diana Acreala
Diana Acreala el 26 de Jul. de 2011
OK! Thank you all for your answers!
I will change my idea of solving the problem, I decided to reorganize the GUI and it is not necessary to create a structure. However, is a good idea for the future. Now I have many variables and the client does not know yet how he wants the variables to be organized.
Now I'm stuck on something else, but I will write a message with a new topic:D
Success!!
  4 comentarios
Jan
Jan el 17 de Jul. de 2017
@Clarisse: Please post the relevant part of your code, such that we can reconsider, what you are trying to do.
Walter Roberson
Walter Roberson el 17 de Jul. de 2017
... and posting as a new Question would be a good idea.

Iniciar sesión para comentar.


Stéphane
Stéphane el 2 de Sept. de 2022
Hello,
I reopen the topic: on my side also I need variable names longer than 63 characters.
Yes these long names are providing a lot of information describing the variable and are especially useful to name the variables in the interface of a generated code (from a model for example). Of course this information could also be stored in a metadata structure, but If the code is then used by a caller not able to handle this metadata, this information will be lost (or at least not visible at the caller's level). The most secure and portable way to link a metadata to it's variable is to put this data in the name of the variable.
I'm nevertheless not that much intererested in debating if it is a good practice or not to use long variable names. One can have this need and it's really unfortunate that Matlab limits the variable names to such a low value. Is there a real technical reason behind ? I hope that a way could be found in the future to get rid of this limitation.
  2 comentarios
Walter Roberson
Walter Roberson el 2 de Sept. de 2022
Your argument for the reason to support long variables does not have any natural limit on variable name lengths. You find 63 to be too small, but since you are using generated code that might have a number of different semantic layers to each variable, clearly 255 might be too small for your purposes as well. How about 65535? You could be doing generated code operating on generated code, so better not limit it to 65535 either.
It follows that your only hard limit should be the maximum array size supported on the hardware MATLAB runs on, same as the maximum array size supported by MATLAB, 2^48-1 bytes. The Intel x64 hardware in theory has 64 bit address paths, but in practice the chips for all publicly known versions are only designed with 48 address lines.
So, you have your 7 terrabyte variable name in one function, and by your arguments about callers, you expect other functions to be accessing the same variable name (you do not expect the names to be local to a single function.) It would obviously be inefficient to store the name twice in MATLAB. This suggests that instead of storing variable names in fixed-length structures, that MATLAB should instead be allocating character vectors for each of them and the symbol tables should point to the character vector -- and that this all should be a global table with reference counters, and some way (hash tables?) to quickly locate individual variables.
Since this is all for the convenience of generated code, it follows that at the same time, MATLAB should remove or alleviate the restriction on which characters are permitted in variable names, permitting at the very least the "alphabetic" letters in multiple languages, and permitting diacretic marks.
Should all be easy, right? No "real" technical reason against doing it, right?
Based on MISRA C 2004:
Rule 5.1 (required): Identifiers (internal and external) shall not rely on the
significance of more than 31 characters. [Undefined 7; Implementation 5, 6] The
ISO standard requires internal identifiers to be distinct in the first 31 characters
to guarantee code portability. This limitation shall not be exceeded, even if the
compiler supports it. This rule shall apply across all name spaces. Macro names
are also included and the 31 character limit applies before and after substitution.
The ISO standard requires external identifiers to be distinct in the first 6
characters, regardless of case, to guarantee optimal portability. However this
limitation is particularly severe and is considered unnecessary. The intent of this
rule is to sanction a relaxation of the ISO requirement to a degree commensurate with
modern environments and it shall be confirmed that 31 character/ case significance
is supported by the implementation. Note that there is a related issue with using
identifier names that differ by only one or a few characters, especially if the
identifier names are long. The problem is heightened if the differences are in
easily mis-read characters like 1 (one) and l (lower case L), 0 and O, 2 and Z,
5 and S, or n and h. It is recommended to ensure that identifier names are always
easily visually distinguishable. Specific guidelines on this issue could be placed
in the style guidelines (see section 4.2.2).

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by