Please vote if you want to have M-function in M-script

1 回表示 (過去 30 日間)
Fangjun Jiang
Fangjun Jiang 2011 年 5 月 18 日
編集済み: Jan 2018 年 9 月 13 日

採用された回答

Jan
Jan 2017 年 1 月 28 日
編集済み: Jan 2018 年 9 月 13 日

その他の回答 (2 件)

Kelly Kearney
Kelly Kearney 2011 年 5 月 18 日
I support this wholeheartedly. I've seen the issue come up many times on the newsgroup, and yet I've never heard a convincing argument against it.
I consider myself very proficient in Matlab. When I write code, I think I'm far more attentive to making the code clean, readable, efficient, and robust than most people. I agree with the general opinion that most code belongs in functions, particularly code that is going to be reused by you, or distributed to others.
However, in my workflow, scripts have their own place. Usually, this involves wrapper scripts to set up input for, run, and analyze output from my main models. In this type of workflow, it's very handy to keep all variables in the base workspace so I can thoroughly analyze any variable at any time in the process. However, I often find myself wanting to add little functions to these scripts, which of course I can't do. I've become pretty adept at utilizing anonymous functions, but there's a limit to how much you can cram into a one-liner. So instead, I find my work folder littered with little one-off functions that are too specialized to be moved to my main library of functions (often specialized plots for data analysis, or utilities to reformat data in a very specific way), but a pain to wade through when I go back in search of a certain script I had written a few weeks ago.
It would be very useful to be able to add these little functions to the script instead. Nothing fancy, no nested functions or shared scope or anything like that, just a simple function with its own scope that can be called by the main script only.
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 5 月 18 日
Two thumbs (points too) up! I completely agree. What I want is the convenience!

サインインしてコメントする。


Jan
Jan 2011 年 5 月 18 日
編集済み: Jan 2017 年 1 月 28 日
No vote from me. I ever (edited: always) use functions due to the benefit of the separated workspace, which prevents the accidental modifications of variables used by the caller.
  4 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 5 月 18 日
Your English is excellent!
Clayton Chu
Clayton Chu 2011 年 9 月 8 日
@Jan Simon - if variables were lexically scoped, namespace collision would not happen so much. One of my annoyances with MATLAB..

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by