473,804 Members | 2,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PROS/CONS: #define BEGIN {

A colleague of mine is proposing that we use a set of preprocessor
definitions to make our C code more readable:

#define BEGIN {
#define ENG }
#define EQ ==
etc.

My initial reaction is "Yuck!" (Not too different from the FAQ, which just
says "Bleah").

Aside from that, what are some good reasons to do this, or not to do this?
A few negatives I come up with include:

* Won't work with some tools, such as
- syntax-aware editors
- metrics
- static analysis tools
- coding style enforcement
- code indenters/reformatters
- pretty printers

* Does not check for mismatches (e.g., "{" vs. "END").

* Does not prevent use of {, }, ==, etc., just adds alternatives.

* Requires re-training of C developers who are used to standard C syntax.
Nov 14 '05
57 7531
Why not go all the way? With a little cleverness, you could have BASIC.
--
#include <standard.discl aimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
Nov 14 '05 #11
In <dY************ ******@newssvr1 9.news.prodigy. com> "Mike Malone" <mr*@prodigy.ne t> writes:
A colleague of mine is proposing that we use a set of preprocessor
definitions to make our C code more readable:

#define BEGIN {
#define ENG }
#define EQ ==
etc.

My initial reaction is "Yuck!" (Not too different from the FAQ, which just
says "Bleah").

Aside from that, what are some good reasons to do this, or not to do this?


ANY usage of the C preprocessor that messes with the language syntax
should be avoided, unless the redeeming benefits are great enough to
compensate for the loss in program readability. And this kind of silly
substitutions have exactly zilch redeeming benefits.

Apparently, the original implementation of the Bourne shell was made
using a header file named "algol.h", whose purpose should be obvious
from its name. The end result was that no one wanted to maintain that
program, so it had to be retranslated to proper C.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #12
Bart wrote:
Peter Hickman wrote:
converts this:

if(x == 1) {
puts("The value is 1");
}

into this:

IF x eq 1 THEN BEGIN
puts("The value is 1");
END

They will produce the same output but the punctuation now takes up much more space.
Proper English words are, in my opinion,
more readable than lots of punctuation,
even if it takes more space
and C does seem to have far too many unnecessary symbols,
such as semicolons.

The C syntax looks like something
that was hastily knocked up one afternoon
and nobody has updated it since.


It certainly was *not*.
It was very carefully crafted
to take advantage of the ASCII character set
and to minimize the number of keystrokes
which you would realize was a very important consideration
if you had ever tried to program at a teletype terminal.
However that *is* the C language and most seem happy with it.

Tinkering with bits of syntax using DEFINEs
is likely to be unsatisfactory;
the above example seems a mix of FORTRAN, PASCAL and C.

Either use a different language
or a formal language extension that uses software
to convert your favorite syntax into standard C (my pet project).


I agree that the C preprocessor
is a poor language translation tool.
Nov 14 '05 #13
On Wed, 15 Dec 2004 00:05:18 +0100, "KiLVaiDeN"
<Ki*******@CaRa MaiL.CoM> wrote:
"Bart" wrote...
Proper English words are in my opinion more readable than lots of
punctuation, even if it takes more space, and C does seem to have far
too many unnecessary symbols, such as semicolons.


I think it'd be very annoying after a while to see tons of "BEGIN"
everywhere on the code..

Imagine something like ( useless code ) :

while(true)
{
do_something();
if(something is true)
{
do_something_el se();
increment_somet hing();
}
else
{
decrement_somet hing();
do_nothing();
}
}

Would translate into something like :

while(true)
BEGIN
do_something();
if(something is true)
BEGIN
do_something_el se();
increment_somet hing();
END
else
BEGIN
decrement_somet hing();
do_nothing();
END
END

Really the first one looks more readable to me !

I admit I'm not a fan of 'begin', I would code your fragment as
something like (loosely taken from Algol68):

do
do_something
if something then
do_something_el se
increment_somet hing
else
decrement_somet hing
do_nothing
endif
end

The original C has:

5 extra semicolons (perhaps one more after final } needed?)
5 extra lots of () for functions
1 () pair for the 'if'
2 extra {, the other replaced by 'then'
1 extra } just before 'else', the others replaced by 'endif'/'end'
1 () pair around 'true' ('while true' is redundant, 'do' will start an
endless loop)

As I said in my original post, lots of unnecessary punctuation in C,
perhaps 20 symbols in this short fragment, without which the code
looks much cleaner, especially printed with bold keywords.

As for extra typing, the original C source had some 177 bytes, my code
about 143 bytes (without 'while true'), and with endif/end removed,
python-like, as they could be made redundant, would be about 130 bytes
(all using tabs not spaces).

Of course I'm not expecting to persuade anyone reading comp.lang.c
that C syntax is anything other than wonderful… just a few
observations.

Bart.

Nov 14 '05 #14

"Bart" <48**@freeuk.co m> wrote in message
news:61******** *************** *********@4ax.c om...

<snip>
5 extra semicolons (perhaps one more after final } needed?)
5 extra lots of () for functions
1 () pair for the 'if'
2 extra {, the other replaced by 'then'
1 extra } just before 'else', the others replaced by 'endif'/'end'
1 () pair around 'true' ('while true' is redundant, 'do' will start an
endless loop)
You seem to be of the opinion that the "extra" punctuation is a bad point.
I, for one, do not think of it as such.

For instance, the language you use omits '(' and ')' for function names, but
i do not suppose that this is also the case when you want to apply a few
parameters. Furthermore, in 'C'

int foobar(void);

int some_var = foobar();

is something completely different than

int foobar(void);

some_var = foobar;

This difference does not seem to be translated into your language. It also
shows that at least some of the parenthesis aren't "unnecessar y".
As I said in my original post, lots of unnecessary punctuation in C,
perhaps 20 symbols in this short fragment, without which the code
looks much cleaner, especially printed with bold keywords.
Ah... A matter of taste. Well, tastes differ.
As for extra typing, the original C source had some 177 bytes, my code
about 143 bytes (without 'while true'), and with endif/end removed,
python-like, as they could be made redundant, would be about 130 bytes
(all using tabs not spaces).
Using tabs do to indenting is a *very* bad idea. I've seen more source that
looked like garbage (but wasn't) due to this. As an aside, i could not care
less about a few extra bytes of *source* code. A few extra bytes of *object*
code may keep me awake at night, though.
Of course I'm not expecting to persuade anyone reading comp.lang.c
that C syntax is anything other than wonderful. just a few
observations.


Well, at least you did not convince me.
Nov 14 '05 #15
On Tue, 14 Dec 2004 22:43:36 +0000, Bart wrote:
On Tue, 14 Dec 2004 10:05:06 +0000, Peter Hickman
<pe***@semantic o.com> wrote:

converts this:

if(x == 1) {
puts("The value is 1");
}

into this:

IF x eq 1 THEN
BEGIN
puts("The value is 1");
END

They will produce the same output but the punctuation now takes up much more space.

Proper English words are in my opinion more readable than lots of
punctuation, even if it takes more space, and C does seem to have far
too many unnecessary symbols, such as semicolons.


Where are C's semicolons unnecessary? Even Pascal uses them in a similar
way. The main difference in (imperative) languages are those that treat
end of line as a terminator. This has its own drawbacks and later
(imperative) languages tend to avoid it. If you don't do that you need
something to act as a separator/terminator.
The C syntax looks like something that was hastily knocked up one
afternoon and nobody has updated it since.
Well I might agree with you on that concerning the switch statement. :-)
However that *is* the C language and most seem happy with it.


We do recognise that there are things that could be designed better in C,
like operator precedence and integral promotions. Many people bemoan
declaration syntax. But the basic syntax and symbology of statements and
operators works pretty well, and it is hard to find anything that doesn't
serve a purpose. E.g. consider

if (isupper(ch)) *p = ch;

Take those ()'s for the if away and you get

if isupper(ch)*p = ch;

which isn't the same thing, or would be hard to parse consistently as the
same thing in the general case.

Lawrence
Nov 14 '05 #16
On Wed, 15 Dec 2004 12:46:56 +0100, "dandelion" <da*******@mead ow.net>
wrote:
int some_var = foobar(); ....some_var = foobar; This difference does not seem to be translated into your language. It also
shows that at least some of the parenthesis aren't "unnecessar y".
some_var=foobar presumably takes the address of the function, which is
probably better written explicitly as some_var=&fooba r.

You must admit C does have an awful lot of semicolons: perhaps 90% or
more associated with end-of-line (EOL) yet typing EOL is not enough, I
must also type ;, because a few statements take more than one line. I
must spend half my time playing pendantics with my compiler instead of
developing my application.

....Ah... A matter of taste. Well, tastes differ.


Yes, of course. The OP's colleague presumably had migrated from PASCAL
or wherever and couldn't cope with all the {,} in C (I think in
PASCAL these are comment symbols!).

It is highly unlikely ISO C will change it's syntax for my benefit or
for others (although syntax is so easy to change), so I guess I will
soon have to be writing raw C as well.

Bart
Nov 14 '05 #17

"Bart" <48**@freeuk.co m> wrote in message
news:9q******** *************** *********@4ax.c om...
On Wed, 15 Dec 2004 12:46:56 +0100, "dandelion" <da*******@mead ow.net>
wrote:
int some_var = foobar(); ...
some_var = foobar;

This difference does not seem to be translated into your language. It alsoshows that at least some of the parenthesis aren't "unnecessar y".


some_var=foobar presumably takes the address of the function, which is
probably better written explicitly as some_var=&fooba r.


That would give me a pointer-to-a-pointer-to-a-function.

http://www.eskimo.com/~scs/C-faq/q1.34.html
You must admit C does have an awful lot of semicolons: perhaps 90% or
more associated with end-of-line (EOL) yet typing EOL is not enough, I
must also type ;, because a few statements take more than one line.
And I can have as many statements on a line as I wan't to. Not that I
generally
do that, but we *are* talking about 'C', which allows it. Hence the
semicolon.

Besides, 'end of line' is code '0x0A' on some systems, '0x0A, 0x0D' on
others
and a third variety does it using '0x0D'. Using your preference, a (say)
Unix
source cannot compile on a (say) Macintosh and neither will compile on a
Windblows machine.

And to top the bill, I like to leave white-lines between blocks of code to
improve readability. I frequently chop up looooooooong calls into separate
lines for the same reason, and do the same with lenngthy versions of
conditions in if(), while() and friend. Those extra newlines (excusez le
mot) would be part of the language in your setup.

I would not like that. And that's putting it (very) mildly.
I must spend half my time playing pendantics with my compiler instead of
developing my application.
Strange. I don't.
Ah... A matter of taste. Well, tastes differ.


Yes, of course. The OP's colleague presumably had migrated from PASCAL
or wherever and couldn't cope with all the {,} in C (I think in
PASCAL these are comment symbols!).


Nope. that '(*' and '*)', IIRC.
It is highly unlikely ISO C will change it's syntax for my benefit or
for others (although syntax is so easy to change), so I guess I will
soon have to be writing raw C as well.


So get used to it or choose another language. There's enough of them around.
Alternative: grab the gcc sources and add a front-end. Then see how popular
it gets.
Nov 14 '05 #18
"dandelion" <da*******@mead ow.net> wrote:
"Bart" <48**@freeuk.co m> wrote in message
news:9q******** *************** *********@4ax.c om...
On Wed, 15 Dec 2004 12:46:56 +0100, "dandelion" <da*******@mead ow.net>
wrote:
int some_var = foobar(); ...
some_var = foobar;
That isn't legal as it stands. You cannot assign a pointer to an int
without a cast.
This difference does not seem to be translated into your language. It also
shows that at least some of the parenthesis aren't "unnecessar y".


some_var=foobar presumably takes the address of the function, which is
probably better written explicitly as some_var=&fooba r.
This is a matter of taste.
That would give me a pointer-to-a-pointer-to-a-function.
No, it wouldn't. Either way takes the address of a function. Strictly
speaking, only &function would be correct, but since there's nothing you
can do with a function except call it or take its address, the ampersand
has been made optional.
You must admit C does have an awful lot of semicolons: perhaps 90% or
more associated with end-of-line (EOL) yet typing EOL is not enough, I
must also type ;, because a few statements take more than one line.
If you want BASIC, you know where to find it. It may come as a surprise
to you, btw, that in C statements can span several lines. I don't know
about you, but I find this a very useful feature.
And I can have as many statements on a line as I wan't to.
That, too, but that's not the reason why the last statement on a line
must end in a semi-colon.
Besides, 'end of line' is code '0x0A' on some systems, '0x0A, 0x0D' on
others and a third variety does it using '0x0D'.


Non sequitur. This is as true for preprocessor statements now as it
would be for normal statements, and that has never been a problem.
I must spend half my time playing pendantics with my compiler instead of
developing my application.


Strange. I don't.


Neither do I. Perhaps Bart should spend more time learning the language
and less time griping about it.
Ah... A matter of taste. Well, tastes differ.


Yes, of course. The OP's colleague presumably had migrated from PASCAL
or wherever and couldn't cope with all the {,} in C (I think in
PASCAL these are comment symbols!).


Nope. that '(*' and '*)', IIRC.


Not true. { and } are the original comment delimiters in Pascal (it's
Pascal, btw, not PASCAL; it's named after Blaise P., not an acronym); (*
and *) were introduced (no idea at what time) for the sake of systems
which don't have { and } in their charset, much as ??< and ??> (and now
<% and %>) in C.

Richard
Nov 14 '05 #19

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message

<snip>
That would give me a pointer-to-a-pointer-to-a-function.
No, it wouldn't. Either way takes the address of a function. Strictly
speaking, only &function would be correct, but since there's nothing you
can do with a function except call it or take its address, the ampersand
has been made optional.


:-( *Bad*.

<snip>
And I can have as many statements on a line as I wan't to.


That, too, but that's not the reason why the last statement on a line
must end in a semi-colon.


And all the other statements do not have to? Wow. That's new.
Besides, 'end of line' is code '0x0A' on some systems, '0x0A, 0x0D' on
others and a third variety does it using '0x0D'.


Non sequitur.


I wasn't making any conclusions from it , I merely point it out. And no, it
would not be a major problem, but it would need to be specified. Besides,
the C-syntax is rather a far cry form the CPP syntax.
This is as true for preprocessor statements now as it
would be for normal statements, and that has never been a problem.
So *this* is the Non Sequitur. If something isn't a problem in Prolog, it
may *well* be a problem in Lisp.

I notice you snip the most important reason for not having 'newline' as a
statement delimiter without marking snippage. Unmarked snippage is
considered bad form on many froups.

May be construed as telling less than the whole thruth...
I must spend half my time playing pendantics with my compiler instead of developing my application.


Strange. I don't.


Neither do I. Perhaps Bart should spend more time learning the language
and less time griping about it.
>Ah... A matter of taste. Well, tastes differ.

Yes, of course. The OP's colleague presumably had migrated from PASCAL
or wherever and couldn't cope with all the {,} in C (I think in
PASCAL these are comment symbols!).


Nope. that '(*' and '*)', IIRC.


Not true.


Gimme a break!
<snip>
(* and *) were introduced (no idea at what time) for the sake of systems
which don't have { and } in their charset


So '(*' and '*)' mark comment. Thanks.

To Bart i'll admit i misread {,} for (,).
Nov 14 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

112
10370
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please, share your experience in using IDENTITY as PK .
2
2027
by: Zhou Lei | last post by:
Hi friends I'm a newbie learning XSLT to transform an XML to some other documents. Now I have some questions, anyone could give me some suggestions on them? 1. If we save our documents in XML rules and these files should be published on Internet through WWW, what we can benefit from the XML files? And what are the drawbacks (is it too complex or time-consuming because we have to define a new set of XML elements to save the documents, and...
5
7644
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating business components that can be consumed by WebForms, WinForms, mobile devices, etc? Is it even fair to compare the such technologies? - How about for cases when you need to display dynamic elements on the form/grid (as compared to knowing data elements...
2
2825
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the code in stored procedures (im advocating encryption of them). When deploying an application however stored procedure seem to add another level of complexity to installation. In future we also plan to have an basic ASP app with some of the...
5
1824
by: JayCallas | last post by:
I have a requirement where I need to perform a query for position information. But for some types of entries, I need to "expand" the row to include additional position rows. Let me explain with an example: An index is a security that is made up of components where each component has a "weight" or a number of shares. So if I have 1 share of the index, I have X shares of each component. AAPL is an Equity, CSCO is an Equity, SPY is an...
3
4232
by: Andrea | last post by:
Hello everyone, I'd like to know which are the main pros and cons of using XML implementation in business organizations. >From a technical perspective, I find XML powerful, but looks like it is being pushed more from technical people than from businessmen... So, some questions: 1. Pros and cons
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.