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

1 次查看(过去 30 天)
[~,maks_vektprosent_lost_CaCl2,~,~,maks_vektprosent_lost_MgCl2,~,~,~, maks_vektprosent_lost_NH4Cl,~,~]= beregn_maks_vektprosent_lost (forste_saltet, andre_saltet, tredje_saltet);
  2 个评论
Sargondjani
Sargondjani 2021-12-18
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 2021-12-18
编辑:Stephen23 2021-12-18
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.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2021-12-18
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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by