[Lazarus] Hints usability
Christian Iversen
chrivers at iversen-net.dk
Fri Apr 10 22:17:28 CEST 2009
JoshyFun wrote:
> Hello Christian,
>
> Friday, April 10, 2009, 1:20:43 AM, you wrote:
>
> CI> That's really 2 statements:
> CI> A) There should be a way to tell the compiler that the hint is expected
> CI> Well, I can't see why this is a given. By definition, hints are things
> CI> that _can_ be potentially dangerous, but it's impossible to determine
> CI> for sure. Warnings point out things which are always potentially dangerous.
>
> As warnings are usually bad practice maybe they can be isolated with a
> simple {$WANINGS OFF}{$WARNINGS ON} and they are quite rare in a
> program.
>
> But now hints are being too verbose, almost anybody initializes a
> string because by definition is is being initialized to '' (nil) and
> it is garanteed, so why add some code to reset it to the expected
> value :-?
I agree. Maybe that specific hint is even poorly implemented, and overly
trigger-happy.
> In other words MY (capital, as it is my problem, maybe not the problem
> of other people) is that the amount of expected hints are hidding the
> non-expected ones.
Right. And as I said, it would probably be more productive to disable an
entire type of hints.
>>> In my case for the "Parameter not used" I'm using a heavily overloaded
>>> procedure "UseParameter" which does nothing and my code is clear of
>>> this kind of hints. The problem is that I must updated the
>>> "UseParameter" each time I use a new parameter type.
> CI> I'm not sure what you mean? Can you give a small example?
>
> unitparameters.pas
> ------------------
> {$HINTS OFF}
> procedure UseParameter(const A: integer); overload;
> begin
> end;
>
> procedure UseParameter(const A: String); overload;
> begin
> end;
>
> procedure UseParameter(const A: TObject); overload;
> begin
> end;
>
> {$HINTS ON}
>
> OtherUnit.pas
> -------------
> uses ...,unitparameter;
>
> procedure ClickPos(Sender: TObject; X,Y: integer);
> begin
> UseParameter(Sender);
> UseParameter(X);
> UseParameter(Y);
> Beep;
> end;
>
> This "technique" keeps my code more or less clean of expected non-used
> parameter hints, and when releasing program I perform a search and
> replace for "UseParameter" -> "//UseParameter".
Ok, I can see what you're doing there. In my opinion, it's not very
pretty. How about something like this:
procedure SilenceHint(const A); inline;
begin
end;
That should require only 1 procedure, and wont require search-replace
because it will simply be optimized out.
Still, I think it's kind of ugly ;-)
My original point is that the "uninitialized variable" hint is so common
that it becomes practically useless in certain applications -- for
example lazarus ones. If you could say, e.g:
{$HINT UNUSED_PARAMETER OFF}
Then that would make it easier for you to spot the real problems.
Granted, it wont catch the maybe 1-in-1000 actual "unused parameter"
problems, but littering the code with UseParameter() "calls" seems, in
my opinion, quite ugly, and a lot of work for a small gain.
> Maybe an array of variants could be used to simplify, but then
> variants come in play and I do not like them if I can code without ;)
I think my version works fine. You could even overload it to accept
multiple argument, so you could do
SilenceHint(Sender, X, Y);
--
Med venlig hilsen
Christian Iversen
More information about the Lazarus
mailing list