Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 17th, 2006, 1:16 PM   #1
b1g4L
Programmer
 
Join Date: Dec 2005
Location: SC
Posts: 38
Rep Power: 0 b1g4L is on a distinguished road
Send a message via AIM to b1g4L
assignment question

I'm confused by this assignment statement. Why is there two variables on the right, and what would this statement be equivilent to?

Node newNode = variable1, variable2;
b1g4L is offline   Reply With Quote
Old Mar 17th, 2006, 2:37 PM   #2
jaeusm
Programmer
 
jaeusm's Avatar
 
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3 jaeusm is on a distinguished road
It is equivalent to:
Node newNode = variable1;
Node variable2;
jaeusm is offline   Reply With Quote
Old Mar 17th, 2006, 5:43 PM   #3
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
Quote:
Originally Posted by jaeusm
Node newNode = variable1;
Node variable2;
Can't make it any more simplier!
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Mar 17th, 2006, 6:32 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Yes. Though the occurences of such a statement in the real world are few and far between, for reasons obvious.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Mar 17th, 2006, 8:30 PM   #5
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 839
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Just so it's crystal clear, you can think about it this way:

You can declare two or more variables on one line by separating them with a comma, for example:

int one, two, three;
This code will create the three uninitialized int variables, one, two, and three.

You can also initialize the variables at the same time you declare them:

int one = 1, two = 2, three = 3;
In the case of the code you posted, the first variable is initialized a value and the second is not. This is obviously bad practice, as Dameon pointed out, since it will confuse most people who are not familiar with your code.
titaniumdecoy is offline   Reply With Quote
Old Mar 17th, 2006, 8:33 PM   #6
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
I think though, it could save a lot of lines of code when making a program. I do initialize my variables like that when I program. Though, as said before, people who are novice at programming will be confused when reading it.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Mar 18th, 2006, 12:25 AM   #7
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 378
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
Oh comone , how many lines of code? 2, 3 ? 10 ?
I hate when people do : int a, b, c;
It's much better :
int a ; // a cute comment
int b ; // a cute comment
int c ; // a cute comment

Even if the variables have meaningful names for you, a bit of comment won't hurt.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Mar 18th, 2006, 9:34 AM   #8
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
Quote:
Originally Posted by xavier
Oh comone , how many lines of code? 2, 3 ? 10 ?
I hate when people do : int a, b, c;
It's much better :
int a ; // a cute comment
int b ; // a cute comment
int c ; // a cute comment

Even if the variables have meaningful names for you, a bit of comment won't hurt.
yea, when you write a < 100 line program. How about 20+ lines when you write a program thats large enough to take you weeks to write. Everyone has their way of writing code. And who said you can't have a comment when doing that. Why does someone have to comment every single variable? Even if they do, you can still write the comment on the same line where you intialized the variables. I dont see what the big deal is here, its the same variable type.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Mar 18th, 2006, 11:45 AM   #9
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 378
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
Well , i didn't mean ALL the lines obviously. Just that i consider writing variables on the same line bad practice.

But hey , it's a free world
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Mar 18th, 2006, 11:16 PM   #10
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
it's all good!
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC