フィルターのクリア

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

1 回表示 (過去 30 日間)
Muazma Ali
Muazma Ali 2021 年 12 月 18 日
回答済み: Image Analyst 2021 年 12 月 18 日
[~,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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by