Clear Filters
Clear Filters

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

1 view (last 30 days)
[~,maks_vektprosent_lost_CaCl2,~,~,maks_vektprosent_lost_MgCl2,~,~,~, maks_vektprosent_lost_NH4Cl,~,~]= beregn_maks_vektprosent_lost (forste_saltet, andre_saltet, tredje_saltet);
  2 Comments
Sargondjani
Sargondjani on 18 Dec 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 on 18 Dec 2021
Edited: Stephen23 on 18 Dec 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.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 18 Dec 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.

Community Treasure Hunt

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

Start Hunting!