Anyone familiar with C++ tell me what this line of code does?

dighn

Lifer
Aug 12, 2001
22,820
4
81
declares int tsize, sets it to GA_TARGET.size()
declares int spos (uninitialized)
declares int i1 (uninitialized)
declares int i2 (uninitialized)

not very readable
 

Blueychan

Senior member
Feb 1, 2008
602
0
76
declares int tsize, sets it to GA_TARGET.size()
declares int spos (uninitialized)
declares int i1 (uninitialized)
declares int i2 (uninitialized)

not very readable

Thank you dighn, for whatever reason I kept seeing it as assigning 4 values on the right to tsize...sigh...going to bed.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Typical showoff coding that costs support time.
Having a single line per declaration makes it more readable and does not add anything to the size/speed of the final product.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Typical showoff coding that costs support time.
Having a single line per declaration makes it more readable and does not add anything to the size/speed of the final product.

QFT. Unfortunately C# followed javascript's lead and provides all sorts of opportunities for young hotshots to cram as many expressions as possible into a single statement, producing dense, difficult to read blocks of code that demonstrate their mastery of the language while at the same time making you want to punch their lights out.
 

you2

Diamond Member
Apr 2, 2002
6,884
1,962
136
It is not show off code; rather it is a lazy style of init temp variables in a function. One could argue as to whether it is poor style or not. With regards to costing support time; one could argue it is a trade off between development time and support time :)

If you are fluent in the language it adds nothing to the support though I suppose someone who is not familiar with the language might have problems with the expression.

There are all sorts of expression folks whine about such as:

i += 1;
i = i++;
i = ++i;
i = 1+ i;
i = i + 1;
of course none of the above are the same as
i -= i++
which is not the same as
i -= ++i
-
As to correct? Or costing support time ? Who knows; I suppose some formal study has been made somewhere but the sample population would have to be examined to determine bias.


Typical showoff coding that costs support time.
Having a single line per declaration makes it more readable and does not add anything to the size/speed of the final product.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
It is not show off code; rather it is a lazy style of init temp variables in a function. One could argue as to whether it is poor style or not. With regards to costing support time; one could argue it is a trade off between development time and support time :)

If you are fluent in the language it adds nothing to the support though I suppose someone who is not familiar with the language might have problems with the expression.

There are all sorts of expression folks whine about such as:

i += 1;
i = i++;
i = ++i;
i = 1+ i;
i = i + 1;
of course none of the above are the same as
i -= i++
which is not the same as
i -= ++i
-
As to correct? Or costing support time ? Who knows; I suppose some formal study has been made somewhere but the sample population would have to be examined to determine bias.

It's simpler than that. When you have to read and comprehend thousands of lines of code you didn't write, ample whitespace, minimal use of expression chaining, forgoing multiple declarations per line, forgoing 'var' when the type isn't clear from the context, that sort of thing, simply makes it a lot easier, and makes the work go a lot faster.

Terseness and compactness really have little to no value in code, imo.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Maintenance of code costs twice the time as development.
A developer can reduce some of that time by clean code and documentation
 

PingSpike

Lifer
Feb 25, 2004
21,758
603
126
Its not to surprising that c++ code gets written like this since it seems like the standard library functions were written at a time when keyboards wearing out from typing to much was a very real problem. :p

strcpy...why isn't it just stringcopy? To easy and the plebs could understand that? Why not just write it in greek and be done with it? :p

Other possible explanations are that the keyboards in the 80s were made out of stone and pressing the heavy stone keys was labor intensive and exhausted programmers. Or perhaps the fact that the computer had only recently been invented meant everyone still used hunt and peck and less characters saved hours of time that would have otherwise been spent staring at the keyboard shouting "W! Where is the W?!"
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Its not to surprising that c++ code gets written like this since it seems like the standard library functions were written at a time when keyboards wearing out from typing to much was a very real problem. :p

strcpy...why isn't it just stringcopy? To easy and the plebs could understand that? Why not just write it in greek and be done with it? :p

Other possible explanations are that the keyboards in the 80s were made out of stone and pressing the heavy stone keys was labor intensive and exhausted programmers. Or perhaps the fact that the computer had only recently been invented meant everyone still used hunt and peck and less characters saved hours of time that would have otherwise been spent staring at the keyboard shouting "W! Where is the W?!"

size of source code could have been a real issue when storage size were low and transmission speed of terminal connections (more popular back then I suppose) were slow. I read that linux commands like cp mv ls were made that way because terminal connections were so slow that saving letters actually mattered (yuck).
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
I know that MULTICS had such a limit back in 1980 when I worked with it.

Ancient C/Unix may have had limits on variable names.
Unix was derived from MULTICS
 
Last edited by a moderator:

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
Its not to surprising that c++ code gets written like this since it seems like the standard library functions were written at a time when keyboards wearing out from typing to much was a very real problem. :p

strcpy...why isn't it just stringcopy? To easy and the plebs could understand that? Why not just write it in greek and be done with it? :p


The initial versions of C only guaranteed uniqueness through 6 letters of function/variable names. If you look you'll notice 6 letters is the magic number for most of the C libraries function names.
 

PingSpike

Lifer
Feb 25, 2004
21,758
603
126
Interesting. I'd noticed the same thing about Linux commands and wonder if there was some sort of connection. I figured there (used to be) a good reason, although I didn't know what it was. I have to remember C has been around forever and C++ carried its idiosyncrasies forward.

When I started C# I kept going "Damn, this is a lot easier to read. It just says what it does."
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Interesting. I'd noticed the same thing about Linux commands and wonder if there was some sort of connection. I figured there (used to be) a good reason, although I didn't know what it was. I have to remember C has been around forever and C++ carried its idiosyncrasies forward.

When I started C# I kept going "Damn, this is a lot easier to read. It just says what it does."
FORTRAN & COBOL have been around forever.:wub:
C is the age of the current crop of senior programmers :'(

C++ is the age of the those coming out of school :D

C#/Java/<scripting languages> are the age of those who are learning what computers are not supposed to be doing:hmm: