http://www.joelonsoftware.com/articles/Wrong.html
This is a fantastic article!
I think it's the first thing I read that articulates why operator overriding is a terrible thing.
I also agree with his version of "Hungarian Notation" - as I was reading it, I was thinking "why aren't I doing this?" It could save me a TON of headaches! And I do do it sometimes, but without really thinking about it.
Anybody who is/wants to program should read this complete, despite its length!
He says:
Quote
char* dest, src;
This is legal code; it may conform to your coding convention, and it may even be what was intended, but when you've had enough experience writing C code, you'll notice that this declares dest as a char pointer while declaring src as merely a char, and even if this might be what you wanted, it probably isn't. That code smells a little bit dirty.
I thought that this code would declare both dest and src as char*. What he meant was:
char *dest, src;
which would declare dest as char* and src as char.
Quote from: MyndFyrex86] link=topic=8846.msg112413#msg112413 date=1174338591]
He says:
Quote
char* dest, src;
This is legal code; it may conform to your coding convention, and it may even be what was intended, but when you've had enough experience writing C code, you'll notice that this declares dest as a char pointer while declaring src as merely a char, and even if this might be what you wanted, it probably isn't. That code smells a little bit dirty.
I thought that this code would declare both dest and src as char*. What he meant was:
char *dest, src;
which would declare dest as char* and src as char.
Both
char *dest, src;
and
char* dest, src;
are equally right/wrong. They're both syntactically right, but are almost guaranteed to produce the wrong result.
This is one of the reasons I like to stick my *'s with the variables! char *dest, src and char* dest, src are the same thing.
Quote from: rabbit on March 19, 2007, 10:00:11 PM
This is one of the reasons I like to stick my *'s with the variables! char *dest, src and char* dest, src are the same thing.
For me, it's a reason I don't declare variables on the same line:
char *dest;
char src;
Pretty obvious :)
That's not the main reason, it's just a personal thing.
I just think single line declarations of multiple variables just looks ugly :\
Quote from: MyndFyrex86] link=topic=8846.msg112413#msg112413 date=1174338591]
He says:
Quote
char* dest, src;
This is legal code; it may conform to your coding convention, and it may even be what was intended, but when you've had enough experience writing C code, you'll notice that this declares dest as a char pointer while declaring src as merely a char, and even if this might be what you wanted, it probably isn't. That code smells a little bit dirty.
I thought that this code would declare both dest and src as char*. What he meant was:
char *dest, src;
which would declare dest as char* and src as char.
That's quite similar to something that happened quite often in programming class:
Dim i, j as Integeri would be a Variant and J would be an Integer, whereas they were both (obviously) intended for Integers.
I'm with iago, I never declare more than one variable per line. It's just an awkward thing to do, imho.
Quote from: Warriorx86] link=topic=8846.msg112507#msg112507 date=1174412541]
I'm with iago, I never declare more than one variable per line. It's just an awkward thing to do, imho.
Yeah, I agree. I do it sometimes when the code I'm writing isn't meant to be reused or used for an extended period of time, but if what I'm writing is "serious business," then I declare one per line. I've seen it cause too many problems.
Quote from: Warriorx86] link=topic=8846.msg112507#msg112507 date=1174412541]
I'm with iago, I never declare more than one variable per line. It's just an awkward thing to do, imho.
So do your guys' classes that might have 10 member variables of which 8 are the same type have 10 lines?
private string m_first;
private string m_last;
private string m_suffix;
private string m_adr1;
private string m_adr2;
private string m_city;
private string m_state;
private string m_zip;
Or:
private string m_first, m_last, m_suffix, m_adr1, m_adr2, m_city, m_state, m_zip;
I don't really see how the second is more awkard then the first.
Yes if I theoretically ever found the need to use 10 strings as members for my class it'd probably look like that.
Word up. These are good ways to organize your code. Organization is one of the biggest problems in programming. Thanks for posting this article, iago.
Quote from: MyndFyrex86] link=topic=8846.msg112541#msg112541 date=1174436692]
So do your guys' classes that might have 10 member variables of which 8 are the same type have 10 lines?
private string m_first;
private string m_last;
private string m_suffix;
private string m_adr1;
private string m_adr2;
private string m_city;
private string m_state;
private string m_zip;
Or:
private string m_first, m_last, m_suffix, m_adr1, m_adr2, m_city, m_state, m_zip;
I don't really see how the second is more awkard then the first.
I would declare them the first way, definitely. But it's a personal thing.
First way for me as well.
Same, using vertical space never bothers me, but I almost always go back and change my code if a line is longer than my horizontal page width.
Haha, good read. Anything I ever wrote was always horrible. Try looking at the ncurses code for slackchat (if i recall correctly, the pscr() function to be specific) ;P
I would, if I could find Slackchat anywhere.
http://www.javaop.com/~tmp/index.htm