Re: [fpc-pascal] Using constants instead of comments

2018-04-18 Thread Mark Morgan Lloyd

On 18/04/18 12:15, wkitt...@windstream.net wrote:
On 04/17/2018 11:06 PM, James Richters wrote:> I have a whole section of 
diagnostic writeln's in a program, and it's tedious to comment them all 
out/in as needed.   I'm curious if doing something like


what's wrong with traditional IFDEF?? use something like this...
{$IFDEF DEBUG}writeln ('blahblahblah');writeln 
(LOGFILE,'blahblahblah');flush (LOGFILE);{$ENDIF}


then you simply create the DEBUG define...
-DDEBUG
if you don't want it, leave it out and none of the bracketd code is even 
included...


I agree. Another possibility is something like

{$if declared(customDebugWrite) }
  customDebugWrite(...);
{$endif declared() }

so if customDebugWrite() isn't present in the program during compilation 
(commented out, or the entire unit containing it omitted) no attempt 
will be made to call it.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Using constants instead of comments

2018-04-18 Thread Vojtěch Čihák

Hi,
 
Why not define?
 
{$DEFINE DEBUG}
 
{$IFDEF DEBUG} Writeln('diagnostic info'); {$ENDIF}
 
V.
 
__

Od: "James Richters" <ja...@productionautomation.net>
Komu: "'FPC-Pascal users discussions'" <fpc-pascal@lists.freepascal.org>
Datum: 18.04.2018 05:06
Předmět: [fpc-pascal] Using constants instead of comments


I have a whole section of diagnostic writeln's in a program, and it's tedious 
to comment them all out/in as needed.   I'm curious if doing something like

Const 
  diagnosticdetail=false;


If diagnosticdetail then Writeln('diagnostic info');

Is the same as 


// Writeln('diagnostic info');

And the Writeln will actually end up being left out of the compiled program 
altogether... since the constant will never allow it to run,  or if not, is 
there a better way to optionally exclude diagnostic information entirely from 
the compiled program?


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 
<http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Using constants instead of comments

2018-04-18 Thread Giuliano Colla

Il 18/04/2018 05:06, James Richters ha scritto:

  is there a better way to optionally exclude diagnostic information entirely 
from the compiled program?


Did you consider to replace your Writeln with a DiagWrite (or whatever 
name you prefer),


and have a DiagWrite such as:

DiagWrite: Procedure(aMessage: string); inline;
begin
  if diagnosticdetail then Writeln(aMessage);
end;

This should do the job, and reduce your typing.

Giuliano
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Using constants instead of comments

2018-04-17 Thread Sven Barth via fpc-pascal
James Richters  schrieb am Mi., 18. Apr.
2018, 05:00:

> I have a whole section of diagnostic writeln's in a program, and it's
> tedious to comment them all out/in as needed.   I'm curious if doing
> something like
>
> Const
>diagnosticdetail=false;
>
> If diagnosticdetail then Writeln('diagnostic info');
>
> Is the same as
>
> // Writeln('diagnostic info');
>
> And the Writeln will actually end up being left out of the compiled
> program altogether... since the constant will never allow it to run,  or if
> not, is there a better way to optionally exclude diagnostic information
> entirely from the compiled program?
>

It should be excluded. You can confirm this by checking the assembler
output generated with "-al".

Regards,
Sven

>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Using constants instead of comments

2018-04-17 Thread R0b0t1
On Tue, Apr 17, 2018 at 10:06 PM, James Richters
 wrote:
> I have a whole section of diagnostic writeln's in a program, and it's tedious 
> to comment them all out/in as needed.   I'm curious if doing something like
>
> Const
>diagnosticdetail=false;
>
> If diagnosticdetail then Writeln('diagnostic info');
>
> Is the same as
>
> // Writeln('diagnostic info');
>
> And the Writeln will actually end up being left out of the compiled program 
> altogether... since the constant will never allow it to run,  or if not, is 
> there a better way to optionally exclude diagnostic information entirely from 
> the compiled program?
>

In C typically you would use conditional compilation. This would work
well in FPC as well. Or, you can do what is more often done in higher
level or managed languages, which is to use a log function that
behaves differently based on the verbosity level.

Cheers,
 R0b0t1
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Using constants instead of comments

2018-04-17 Thread James Richters
I have a whole section of diagnostic writeln's in a program, and it's tedious 
to comment them all out/in as needed.   I'm curious if doing something like

Const 
   diagnosticdetail=false;

If diagnosticdetail then Writeln('diagnostic info');

Is the same as 

// Writeln('diagnostic info');

And the Writeln will actually end up being left out of the compiled program 
altogether... since the constant will never allow it to run,  or if not, is 
there a better way to optionally exclude diagnostic information entirely from 
the compiled program?


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal