From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.os.msdos.programmer,comp.lang.c++,comp.lang.c
Subject: Re: Newbie Wants Advice on C-Programming
Date: 12 Jan 93 17:05:24 GMT
Followup-To: comp.os.msdos.programmer
Organization: negligable

In article <1993Jan11.131838.12844@cbnewsj.cb.att.com> davet@cbnewsj.cb.att.com (Dave Tutelman) writes:
>In article <FISCHER.93Jan9030817@orange.iesd.auc.dk> fischer@iesd.auc.dk (Lars Peter Fischer) writes:
>>
>>>>>>> "Michael" == Michael Malak (malak@grebyn.com)
>>>>>>> "Lars" == fischer@iesd.auc.dk (Lars Peter Fischer)
>>>>>>> "John" == John MAX Skaller (maxtal@extro.ucc.su.OZ.AU)
>>
>>John> 	Seems to me that the simple concept of
>>John> nesting the symbol table so that symbols go out of scope at the
>>John> end of the block is very nice.
>
>C and C++ have this, too.
>
>My organization's coding standard (adopted explicitly to make our software
>easier to read and maintain) calls for declaring and initializing
>variables as close as possible to their point of first use.  In the ability
>to meet this goal:
>	C++ good.
>	Pascal bad.

I am a C person and I have to disagree with your standard.  In C++
(and, I think, ANSI C although I am not certain) it is possible to
declare new variables almost anywhere.  e.g.:

	main()
	{
	cout << "stuff" << endl;
	int i = 2;
	cout << "i is " << i << endl;
	}

This, you would agree, is declaring as close to the usage as possible,
but let's say the function is a little longer than that.  I want to
add a loop w/ the control variable "i".  Where can I check to see if
it has already been declared or not if all the variable declarations
are scattered throughout the code?

The biggest concession I will make to this practice is declaring 
variables at the top of the nearest enclosing block.  Which I
don't think Pascal can do anyway, aren't they limited to the 
enclosing function/procedure?

>As someone who has a few years real-world programming experience with
>each of C and Pascal, the ONLY times I've ever wished for nested
>procedures in C involved a combination of:
> - Repetitive operations of the same pattern within a single function,
>   that weren't repeated in any other function.

static function.

> - A lot of function-specific state information (i.e.- local variables)
>   required for this operation... too many to make each one an argument
>   of a procedure.

struct.

>In such cases, I use macros in C; not as elegant as nested procedures,
>but they do the job.

that works too.  (actually I use macros more than static functions, 
but then I don't always care about poluting the name space as much
as I should...)



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Blasting, bursting, billowing forth with	|
the power of ten billion butterfly sneezes,	|	-Richard Hartman	
Man, with his flaming fire,			|	hartman@uLogic.COM
has conquered the wayword breezes.		|
----- News saved at 12 Jan 93 17:04:17 GMT
In article <1993Jan11.131838.12844@cbnewsj.cb.att.com> davet@cbnewsj.cb.att.com (Dave Tutelman) writes:
>In article <FISCHER.93Jan9030817@orange.iesd.auc.dk> fischer@iesd.auc.dk (Lars Peter Fischer) writes:
>>
>>>>>>> "Michael" == Michael Malak (malak@grebyn.com)
>>>>>>> "Lars" == fischer@iesd.auc.dk (Lars Peter Fischer)
>>>>>>> "John" == John MAX Skaller (maxtal@extro.ucc.su.OZ.AU)
>>
>>John> 	Seems to me that the simple concept of
>>John> nesting the symbol table so that symbols go out of scope at the
>>John> end of the block is very nice.
>
>C and C++ have this, too.
>
>My organization's coding standard (adopted explicitly to make our software
>easier to read and maintain) calls for declaring and initializing
>variables as close as possible to their point of first use.  In the ability
>to meet this goal:
>	C++ good.
>	Pascal bad.

I am a C person and I have to disagree with your standard.  In C++
(and, I think, ANSI C although I am not certain) it is possible to
declare new variables almost anywhere.  e.g.:

	main()
	{
	cout << "stuff" << endl;
	int i = 2;
	cout << "i is " << i << endl;
	}

This, you would agree, is declaring as close to the usage as possible,
but let's say the function is a little longer than that.  I want to
add a loop w/ the control variable "i".  Where can I check to see if
it has already been declared or not if all the variable declarations
are scattered throughout the code?

The biggest concession I will make to this practice is declaring 
variables at the top of the nearest enclosing block.  Which I
don't think Pascal can do anyway, aren't they limited to the 
enclosing function/procedure?

>As someone who has a few years real-world programming experience with
>each of C and Pascal, the ONLY times I've ever wished for nested
>procedures in C involved a combination of:
> - Repetitive operations of the same pattern within a single function,
>   that weren't repeated in any other function.

static function.

> - A lot of function-specific state information (i.e.- local variables)
>   required for this operation... too many to make each one an argument
>   of a procedure.

struct.

>In such cases, I use macros in C; not as elegant as nested procedures,
>but they do the job.

that works too.  (actually I use macros more than static functions, 
but then I don't always care about poluting the name space as much
as I should...)



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Blasting, bursting, billowing forth with	|
the power of ten billion butterfly sneezes,	|	-Richard Hartman	
Man, with his flaming fire,			|	hartman@uLogic.COM
has conquered the wayword breezes.		|

Newsgroups: comp.os.msdos.programmer