Borrar filtros
Borrar filtros

is this an example of bad programmering which can lead to errors?

1 visualización (últimos 30 días)
Muazma Ali
Muazma Ali el 18 de Dic. de 2021
Respondida: Image Analyst el 18 de Dic. de 2021
[~,maks_vektprosent_lost_CaCl2,~,~,maks_vektprosent_lost_MgCl2,~,~,~, maks_vektprosent_lost_NH4Cl,~,~]= beregn_maks_vektprosent_lost (forste_saltet, andre_saltet, tredje_saltet);
  2 comentarios
Sargondjani
Sargondjani el 18 de Dic. de 2021
Yes.
I mean, that's a lot of output arguments. I would group them and put them in structures, as Matlab itself does.
Stephen23
Stephen23 el 18 de Dic. de 2021
Editada: Stephen23 el 18 de Dic. de 2021
Yes.
More than five or six positional input or output arguments is just asking for bugs. Use a table or structure instead.
The basic cause seems to be poor data design: forcing meta-data (e.g. chemical formulas) into variable names makes acessing data inefficient and more complex. Meta-data is data, and data should be stored in a variable not in a variable name. Once you put all meta-data in variables (e.g. into a column of a table) then you can simplify and generalize your code.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 18 de Dic. de 2021
See Loren's Blogs:
I agree with @Sargondjani and @Stephen though it is good to have descriptive variable names. No one likes looking at an alphabet soup mess of a programs with single letter variables all over. They can be longer and more descriptive though there's no need to go overboard with dozens of letters or full sentences as variable names.
I also wonder, since you're accepting so few of the outputs, if it's really necessary for the function to return all those things -- things that you, at least, don't want. Maybe you can have it return fewer things.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by