Less then five minutes ago, the following was uttered on the forum:
WOAH!
Everyone, everywhere, this is not factual, but oddly enough, widely permeated. Yes C can be cryptic, yes C can be low level, but that does not, I repeat, does not, give one permission to write code that looks like something off of an ancient Egyptian wall.
There's this:
and then there's this:
The first is just horrible. The second could be considered equally as cryptic, but at least it is self-documenting (and hanging out with C for any extended period of time, it is easily recognizable as a string copy).
One letter variable names outside of loops are horrible. Double letter variable names mm, ii, jj, kk are worse!
Sloppy unreadable code is sloppy unreadable code, regardless of the language.
Quote
[it is entirely unreadable because] the code most be in c run not c++ thats why it looks like this
WOAH!
Everyone, everywhere, this is not factual, but oddly enough, widely permeated. Yes C can be cryptic, yes C can be low level, but that does not, I repeat, does not, give one permission to write code that looks like something off of an ancient Egyptian wall.
There's this:
int i,j,x,sum=0,rat=0,s=0,f=0,q,summ=0,p,r,t,m,n,tm;
/*.......*/
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(i!=j)
{if((ku[i][j]!=ku[j][i])||(ku[i][j]==0&&ku[j][i]==0))
tm+=1;}
and then there's this:
while (*s != '\0'){
*r++ = *s++;
}
The first is just horrible. The second could be considered equally as cryptic, but at least it is self-documenting (and hanging out with C for any extended period of time, it is easily recognizable as a string copy).
One letter variable names outside of loops are horrible. Double letter variable names mm, ii, jj, kk are worse!
Sloppy unreadable code is sloppy unreadable code, regardless of the language.
14 Comments On This Entry
Page 1 of 1
LaFayette
16 May 2010 - 01:07 PM
I'm no C programmer but isn't this how you do a cool string copy:
But you are right. C code isnt inherently hard to read. It's just that there are a lot of C programmers that like to do stuff the cryptic way. Especially when naming variables and functions..
while(*r++ = *s++);
But you are right. C code isnt inherently hard to read. It's just that there are a lot of C programmers that like to do stuff the cryptic way. Especially when naming variables and functions..
Locke
16 May 2010 - 02:45 PMLaFayette, on 16 May 2010 - 02:07 PM, said:
But you are right. C code isnt inherently hard to read. It's just that there are a lot of C programmers that like to do stuff the cryptic way. Especially when naming variables and functions..
The code is self-obfuscating at that point.
Not to mention a total bitch to edit...
alias120
16 May 2010 - 05:13 PM
Part of the reason why I hate reading C++ tutorials that use C. Half of the time even the author will write very cryptic C that makes me spend more time trying to read the code than understand it.
-alias
-alias
AdamSpeight2008
18 May 2010 - 06:44 AM
You must use some arcane usage of the term self documenting that I'm not aware of, to say that this is self documenting.
while (*s != '\0'){
*r++ = *s++;
}
NickDMax
18 May 2010 - 07:44 AM
Well null terminators are actually a pretty common C pattern for dealing with arrays of "unknown size". Given that snippet you might be doing a string copy... it is definitely *some kind* of memory copy operation, but there is really no telling without the rest of the code.
dorknexus
19 May 2010 - 02:25 PM
When I hear people complain about the readability of C I just say "Could be worse. Could be a Lisp dialect." That usually sends them screaming.
depricated
28 May 2010 - 03:53 PMWolfCoder, on 18 May 2010 - 07:38 PM, said:
There is no such a thing as "self documenting".
Sure there is.
Good variable names would be self documenting.
While the earlier loop was clearly copying a string, that could be made self documenting by a few simple changes
from
while (*s != '\0'){
*r++ = *s++;
}
to
string copyString(char *originalString)
{
char[] copyOfString;
while(*originalString != '\0')
{
copyOfString++ = originalString++;
}
return copyOfString;
}
(pardon I haven't used C in like a year or so. . . if context is off, sorry)
NickDMax
17 June 2010 - 11:56 AM
@depricated, I see your apology but, before someone takes you code seriously I should point out that it is very incorrect.
First that is not how arrays are defined in C or C++, Even if it WERE you need to specify a size or initialize it to some string literal.
Then this line: copyOfString++ = originalString++; is not even close to correct. And then the return is not very self documenting at all as you said you would return a string and then returned a char[] -- which might get converted to a string but the compiler (it should actually) but that is not very "self documenting".
I understand what you are saying that if you use proper variable naming and writing the code as though it were to be "Read" is "self documenting" -- add to that the use of comments and a tool like doxigen or javadocs and you can have some pretty good code.
First that is not how arrays are defined in C or C++, Even if it WERE you need to specify a size or initialize it to some string literal.
Then this line: copyOfString++ = originalString++; is not even close to correct. And then the return is not very self documenting at all as you said you would return a string and then returned a char[] -- which might get converted to a string but the compiler (it should actually) but that is not very "self documenting".
I understand what you are saying that if you use proper variable naming and writing the code as though it were to be "Read" is "self documenting" -- add to that the use of comments and a tool like doxigen or javadocs and you can have some pretty good code.
Page 1 of 1
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 |
Tags
My Blog Links
Recent Entries
Recent Comments
Search My Blog
24 user(s) viewing
24 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



14 Comments









|