Syntax for variable names spanning multiple lines in C

I

Ian Collins

Sriram said:
Lets say that the variable name is quite small and due to multiple
nested if-else and a 4 space indentation per if-else, I end up in a
situation where I wud have to split my variable name?
Two solutions:

Use 2 space indents.

Don't nest too deep, extract functions.

Failing that, split expressions, not variable names. Once you split a
variable name, you loose your indentation.
 
T

Tor Rustad

Sriram Rajagopalan wrote:

int this_is_a_\
very_long_variable_name = 10;

The above gives a compilation error.

Good, after translation phase 2, this appear as

int this_is_a_ very_long_variable_name = 10;
Please suggest the means to do this if there is any.

This is a horrible idea, don't do it!

Having very long identifiers is a bad idea. First of all, identifiers
with external linkage may have only 6 significant initial characters
(C90). Even the internal identifiers in C99, may have no more than 63
significant initial characters. So, you are begging for bugs.. !

Second, readability, splitting identifiers on multiple lines, will not
increase the readability of your code, it will only tell others that
the code was written by a clueless person.

There are cases, where I have generated identifiers, not by use of line
splicing, but rather via the ## operator:

#define make_ident(a, b) a ## b
 
E

Eric Sosman

Sriram Rajagopalan wrote On 11/14/06 02:35,:
Lets say that the variable name is quite small and due to multiple
nested if-else and a 4 space indentation per if-else, I end up in a
situation where I wud have to split my variable name?

if (a)
if (b)
if (c)
if (d)
if (e)
if (f)
if (g)
if (h)
if (i)
if (j)
if (k)
if (l)
if (m)
x = va1\
ue;
else
dx = va\
lue;

IMHO, the code is already unreadable and its readability
is not salvaged by splitting an identifier and forcing the
reader's eye to make a saccade. Did you spot the error in
the above on your first reading of it?
 
K

Kenny McCormack

Eric Sosman said:
IMHO, the code is already unreadable and its readability
is not salvaged by splitting an identifier and forcing the
reader's eye to make a saccade. Did you spot the error in
the above on your first reading of it?

It looks fine to me, assuming, of course, that you have properly
declared and initialized variables: a,b,c,d,e,f,g,h,i,j,k,l,m,x,value,
and va1ue.

You do, don't you?
 
S

santosh

Kenny said:
It looks fine to me, assuming, of course, that you have properly
declared and initialized variables: a,b,c,d,e,f,g,h,i,j,k,l,m,x,value,
and va1ue.

Missing parenthesis.
 
J

james of tucson

Sriram said:
I was actually trying to limit
the number of characters per line of the source code to 80, for the
sake of better readability.

That would aggravate me more than a long line, for reasons not the least
of which is the 240 column xterm I get on the big monitor at the office,
or the 160 columns I get even with a big font here on my portable box...

Anyway, I think it would be much better if you just introduced a new
variable, assigned to it the value your long variable, and used that in
the routine. Or, if you refrained from using overly long identifiers to
begin with would be best, since presumably, readability is your goal.
Better to just explain what you're doing in a comment.
 
R

Random832

2006-11-14 said:
That would aggravate me more than a long line, for reasons not the least
of which is the 240 column xterm I get on the big monitor at the office,

Wouldn't it be better to have 3 80-column xterms?
 
R

Richard Bos

Eric Sosman said:
Sriram Rajagopalan wrote On 11/14/06 02:35,:

if (a)
if (b)
if (c)
if (d)
if (e)
if (f)
if (g)
if (h)
if (i)
if (j)
if (k)
if (l)
if (m)
x = va1\
ue;
else
dx = va\
lue;

IMHO, the code is already unreadable and its readability
is not salvaged by splitting an identifier and forcing the
reader's eye to make a saccade. Did you spot the error in
the above on your first reading of it?

While I agree with your point, IMO your illustration is flawed. I
wouldn't have spotted that error in my newsreader whether the nesting
was reasonable or not. It's a defect in the font I use. In my editor, I
use a different font, and I'd have a much better chance of spotting it.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top