From: Steven Lord on

"Merciadri Luca" <Luca.Merciadri(a)student.ulg.ac.be> wrote in message
news:87634a8a1n.fsf(a)merciadriluca-station.MERCIADRILUCA...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> writes:
>
>> Dear Merciadri!
>>
>>> [var1 var1] = myfunction(stuff)
>>> [stuff2]
>>>
>>> structure, assuming that myfunction(stuff) outputs two different
>>> variables var1 and var2. As I understood it, it should help me in the
>>> case where var2 that `myfunction' returns is not used later in my
>>> code, i.e. in [stuff2]. But M-Lint did not stop showing the message,
>>> and the trick was consequently not working, if I understand it well.
>>
>
>> After this:
>> [var1, var1] = myfunction(stuff)
>> var1 has the value of the 2nd output. So better call it:
>> [var2, var2] = myfunction(stuff)
>> The first var2 is never used, because it is immediately overwritten. This
>> is not an error, but MLint should warn the user to control this manually.
>> After this has been controlled, the MLint message can be suppressed with
>> %#ok without any danger. This is not squeezing MLint, but it is the
>> simple consequence from the fact that some programmers are still more
>> intelligent than MLint.
> Thanks. This is the same point of view as mine. However, I think that,
> for clarity's sake, using %#ok without replacing variables that are
> not desired by desired variables, is better.
>
> Another question naturally arises: I have a function which defines an
> ODE system. I then pass a handle to this function in the ODEsolver
> args. However, my function which defines the ODE system takes the
> integration variable (t, the time), as an argument. That is normal,
> but it is not directly used in the function which defines the ODE
> system (and that is normal). Is it a good idea to simply %#ok the
> resulting line?

If your version of MATLAB supports the syntax to suppress individual M-Lint
messages (something like %#ok<NASGU>) then I would use that instead of
simply suppressing ALL M-Lint messages on that line with %#ok. I don't
remember off the top of my head when that support was introduced. I would
probably also explain, with a short comment, why you're suppressing M-Lint
on that line so that if someone comes along six months from now, it's clear
why the %#ok is present. [Don't overestimate how "obvious" something is --
most people here have probably had an experience where they couldn't
understand what a piece of code they had written 6 months earlier did.]

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Merciadri Luca on
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Steven Lord" <slord(a)mathworks.com> writes:

> "Merciadri Luca" <Luca.Merciadri(a)student.ulg.ac.be> wrote in message
> news:87634a8a1n.fsf(a)merciadriluca-station.MERCIADRILUCA...
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> writes:
>>
>>> Dear Merciadri!
>>>
>>>> [var1 var1] = myfunction(stuff)
>>>> [stuff2]
>>>>
>>>> structure, assuming that myfunction(stuff) outputs two different
>>>> variables var1 and var2. As I understood it, it should help me in the
>>>> case where var2 that `myfunction' returns is not used later in my
>>>> code, i.e. in [stuff2]. But M-Lint did not stop showing the message,
>>>> and the trick was consequently not working, if I understand it well.
>>>
>>
>>> After this:
>>> [var1, var1] = myfunction(stuff)
>>> var1 has the value of the 2nd output. So better call it:
>>> [var2, var2] = myfunction(stuff)
>>> The first var2 is never used, because it is immediately overwritten. This
>>> is not an error, but MLint should warn the user to control this manually.
>>> After this has been controlled, the MLint message can be suppressed with
>>> %#ok without any danger. This is not squeezing MLint, but it is the
>>> simple consequence from the fact that some programmers are still more
>>> intelligent than MLint.
>> Thanks. This is the same point of view as mine. However, I think that,
>> for clarity's sake, using %#ok without replacing variables that are
>> not desired by desired variables, is better.
>>
>> Another question naturally arises: I have a function which defines an
>> ODE system. I then pass a handle to this function in the ODEsolver
>> args. However, my function which defines the ODE system takes the
>> integration variable (t, the time), as an argument. That is normal,
>> but it is not directly used in the function which defines the ODE
>> system (and that is normal). Is it a good idea to simply %#ok the
>> resulting line?
>
> If your version of MATLAB supports the syntax to suppress individual M-Lint
> messages (something like %#ok<NASGU>) then I would use that instead of
> simply suppressing ALL M-Lint messages on that line with %#ok.
Mine seems not to support it, actually. Not a problem. That was my
idea too. Too bad that my version does not support this. And if I had
had this option, would this setting have been saved in a file which I
could have moved with my .m files to another computer, or not? I think
not so.

> I don't remember off the top of my head when that support was
> introduced.
> I would probably also explain, with a short comment, why you're suppressing M-Lint
> on that line so that if someone comes along six months from now, it's clear
> why the %#ok is present. [Don't overestimate how "obvious" something is --
> most people here have probably had an experience where they couldn't
> understand what a piece of code they had written 6 months earlier
> did.]
Sure. That is one of the first things I learnt when I began
programming. I had already indicated those things. Thanks for pointing
them out, though.

- --
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- --

When one door closes, another opens; but we often look so long and so regretfully upon the closed
door that we do not see the one which has opened for us. (Alexander
Graham Bell)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAku2ErQACgkQM0LLzLt8MhzSoACggG/F6s+SPFmFRFbau0dMq7BE
QyoAoJWZRDFYE4LllDNyYOtHMTn3JWW8
=zyA4
-----END PGP SIGNATURE-----
From: Steven Lord on

"Merciadri Luca" <Luca.Merciadri(a)student.ulg.ac.be> wrote in message
news:87k4sp97ii.fsf(a)merciadriluca-station.MERCIADRILUCA...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> "Steven Lord" <slord(a)mathworks.com> writes:

*snip*

>> If your version of MATLAB supports the syntax to suppress individual
>> M-Lint
>> messages (something like %#ok<NASGU>) then I would use that instead of
>> simply suppressing ALL M-Lint messages on that line with %#ok.
>
> Mine seems not to support it, actually. Not a problem. That was my
> idea too. Too bad that my version does not support this. And if I had
> had this option, would this setting have been saved in a file which I
> could have moved with my .m files to another computer, or not? I think
> not so.

I'm not quite sure I follow. When you add the comment %#ok to the end of a
line of code, it suppresses the M-Lint messages on that line of code. It
doesn't make a change to a "global state" or anything like that; the only
way you could lose that behavior when you move the M-file to another machine
is if the mechanism by which you moved the M-file happened to randomly
delete this comment. If your moving mechanism does that, the solution I
suggest is to get a better mechanism for moving your code :)

Also just FYI, in recent releases there is a way to select which messages
and coding patterns M-Lint (which was recently renamed Code Analyzer) will
flag and save those settings to a file that can be copied to another
machine. The description of this feature in the documentation for the
latest release is here:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/brqxeeu-151.html

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Merciadri Luca on
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Steven Lord" <slord(a)mathworks.com> writes:

> "Merciadri Luca" <Luca.Merciadri(a)student.ulg.ac.be> wrote in message
> news:87k4sp97ii.fsf(a)merciadriluca-station.MERCIADRILUCA...
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> "Steven Lord" <slord(a)mathworks.com> writes:
>
> *snip*
>
>>> If your version of MATLAB supports the syntax to suppress individual
>>> M-Lint
>>> messages (something like %#ok<NASGU>) then I would use that instead of
>>> simply suppressing ALL M-Lint messages on that line with %#ok.
>>
>> Mine seems not to support it, actually. Not a problem. That was my
>> idea too. Too bad that my version does not support this. And if I had
>> had this option, would this setting have been saved in a file which I
>> could have moved with my .m files to another computer, or not? I think
>> not so.
>
> I'm not quite sure I follow. When you add the comment %#ok to the end of a
> line of code, it suppresses the M-Lint messages on that line of code. It
> doesn't make a change to a "global state" or anything like that; the only
> way you could lose that behavior when you move the M-file to another machine
> is if the mechanism by which you moved the M-file happened to randomly
> delete this comment. If your moving mechanism does that, the solution I
> suggest is to get a better mechanism for moving your code :)
That is what I had understood, but I was asking for a way to change
Code Analyzer's parameters, and to save them in a given file which
could be automatically lauched on another computer at the opening of
one of my functions.

> Also just FYI, in recent releases there is a way to select which messages
> and coding patterns M-Lint (which was recently renamed Code Analyzer) will
> flag and save those settings to a file that can be copied to another
> machine. The description of this feature in the documentation for the
> latest release is here:
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/brqxeeu-151.html
Thanks! :-)

- --
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- --

The heart has reasons that reason does not understand. (Jacques
Bossuet)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAku2K20ACgkQM0LLzLt8MhyYFwCdGB/NuUDt26G7n9Hsppw8FoGI
IRgAn1SL3QYc7pR76HOVCfOJF8YgQ8LJ
=04tZ
-----END PGP SIGNATURE-----