Csound Csound-dev Csound-tekno Search About

Re: [Cs-dev] build issues

Date2007-05-01 17:13
FromMichael Gogins
SubjectRe: [Cs-dev] build issues
I am sorry, but it is not a silly assertion. It is based on my own personal experience, and the recommendations of experienced programmers. Macros can cause serious problems and perform no necessary function. They are a convenience that can become a serious inconvenience. The problems are as follows:

1. Macros defined in one header can collide with macros defined in another header. This can cause crashes or unpredictable behavior. It can also cause code to fail to compile without rearranging macros, #define ing and #undef ining them, and so on.
2. Macros 'vanish' during compilation and provide no information in the debugger. Complex macros, in particular, can leave a programmer trying to debug code almost completely in the dark, reliant on the disassembler.
3. The parsing of multi-parameter macros is not performed the same way as the parsing of multi-parameter functions, and can have serious side effects of unintentionally modifying arguments.
4. Parameters in macros are not typed the same way as parameters in functions. Again, this can lead to crashes or unpredictable behavior.

In 20 years of professional programming, I have been forced to deal with all of these problems. The most serious problems tend to be 1 (failure to compile due to clashing macros) and 2 (difficulty of debugging). I would say that I have repeatedly had to spend several full days at work trying to work around macro clashes when porting code (especially Unix sockets versus Windows sockets). I have experienced 1, 2, and 4 in Csound code. 

Code without macros, obviously, simply does not produce these problems. Most new languages intentionally omit a macro facility for these reasons, or they try to restrict the macro facility to enabling some kind of conditional compilation.

If there is a need for semantic indications, please replace the macros with enums or constants.

If you are making changes to code that is causing failures to compile, that should be telling you you are doing something wrong.

Please do not take this personally. I just know from experience that using macros is going to continue to cause these kinds of problems, and they are far easier to avoid than they are to fix.

Regards,
Mike

-----Original Message-----
>From: Anthony Kozar 
>Sent: May 1, 2007 11:05 AM
>To: Csound Developer list 
>Subject: Re: [Cs-dev] build issues
>
>I am sorry, but that is a fairly silly assertion.  FALSE and TRUE make more
>sense that 0 and 1.  They provide _semantic_ information that 0 and 1 do
>not.  I use 0 and 1 to refer to quantities; FALSE and TRUE refer to Boolean
>states.
>
>I could define them as an enumeration if you prefer that to macros, but
>there is really no harm in using macros to represent symbolic constants.
>
>Anthony
>
>Michael Gogins wrote on 5/1/07 10:15 AM:
>
>> Real programmers do not use macros. Replace FALSE with 0 or whatever it is
>> that FALSE is supposed to be translated to.
>
>
>-------------------------------------------------------------------------
>This SF.net email is sponsored by DB2 Express
>Download DB2 Express C - the FREE version of DB2 express and take
>control of your XML. No limits. Just data. Click to get it now.
>http://sourceforge.net/powerbar/db2/
>_______________________________________________
>Csound-devel mailing list
>Csound-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/csound-devel




-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-05-01 17:44
FromAnthony Kozar
SubjectRe: [Cs-dev] build issues
I find the extra semantic information to be helpful when reading or
modifying code.  The real problem -- as you implied -- is that C does not
have some of the modern programming facilities and types that are necessary
for clear, readable code.  In C programming, I personally find a simple
macro like FALSE to be clearer than 0 and relatively harmless.  I wondered
about using it the first time that I typed it in Csound last Saturday, but
because it compiled fine (for me), I gave it no further thought.

I will remove all uses of TRUE and FALSE that I added to Csound.  But I
don't think these particular macros are a real problem ...

(In my defense, I do prefer enums for most symbolic constants, and indeed I
introduced a large new enumeration in csoundCore.h over the weekend instead
of using macros, which by the way, was the norm in Csound (at least before
Istvan)).

Anthony

Michael Gogins wrote on 5/1/07 12:13 PM:

> If there is a need for semantic indications, please replace the macros with
> enums or constants.
> 
> If you are making changes to code that is causing failures to compile, that
> should be telling you you are doing something wrong.
> 
> Please do not take this personally. I just know from experience that using
> macros is going to continue to cause these kinds of problems, and they are far
> easier to avoid than they are to fix.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-05-01 19:03
Fromjpff
SubjectRe: [Cs-dev] build issues
OK since we are playing these games, I have earned my living
programming for 36 years, and have been full-time programming for 40.
I disagree.  Indeed I was berating students last week for bare 1000
and 92 in their compilers when they meant HASHSIZE or the like.  I
have also taught COBOL where the use of names for constants is
important.
  Anyway, I like macros.
==John ffitch

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-05-01 19:19
FromRichard Dobson
SubjectRe: [Cs-dev] build issues
A important aspect of the problem is that not all code treats 0 as 
false. Several C library functions (e.g. low-level file i/o) return 0 
for success, and -1 (or typically some other negative value) for 
failure. The logic being (among other things) that there is typically a 
unique successful result (and of course zero is unique), but potentially 
many reasons for failure. So your FALSE may well be someone else's SUCCESS!

Richard Dobson




Anthony Kozar wrote:
> I find the extra semantic information to be helpful when reading or
> modifying code.  The real problem -- as you implied -- is that C does not
> have some of the modern programming facilities and types that are necessary
> for clear, readable code.  In C programming, I personally find a simple
> macro like FALSE to be clearer than 0 and relatively harmless.  I wondered
> about using it the first time that I typed it in Csound last Saturday, but
> because it compiled fine (for me), I gave it no further thought.
> 
> I will remove all uses of TRUE and FALSE that I added to Csound.  But I
> don't think these particular macros are a real problem ...
> 



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-05-03 01:39
FromAnthony Kozar
SubjectRe: [Cs-dev] build issues
Committing these changes right now.  Of course, I cannot really test whether
I have removed all of "my" TRUEs and FALSEs and only "mine" since they are
defined in my system headers somewhere.  So, someone else give a shout if it
still does not compile ...

(There were over 100 other uses of these macros in Csound already, BTW; but
always with local definitions).

Anthony

Anthony Kozar wrote on 5/1/07 12:44 PM:

> I will remove all uses of TRUE and FALSE that I added to Csound.  But I don't
> think these particular macros are a real problem ...


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-05-03 15:24
From"Steven Yi"
SubjectRe: [Cs-dev] build issues
AttachmentsNone