is this an example of bad programmering which can lead to errors?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
[~,maks_vektprosent_lost_CaCl2,~,~,maks_vektprosent_lost_MgCl2,~,~,~, maks_vektprosent_lost_NH4Cl,~,~]= beregn_maks_vektprosent_lost (forste_saltet, andre_saltet, tredje_saltet);
2 Kommentare
Sargondjani
am 18 Dez. 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
am 18 Dez. 2021
Bearbeitet: Stephen23
am 18 Dez. 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.
Antworten (1)
Image Analyst
am 18 Dez. 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!