[SOLVED]is it bad style to do a = b = getVal()?

Get answers to all your basic programming questions. No Ogre questions, please!
iblues1976
Gnome
Posts: 379
Joined: Fri Sep 16, 2011 4:54 pm
x 10

[SOLVED]is it bad style to do a = b = getVal()?

Post by iblues1976 »

Hi,

is it considered a bad style to do this

Code: Select all

leftDX = leftX = getX(); 
thanks,
Francisco

NOTE TO MODS ( I moved from help to back to basics. I think I placed in help by mistake. I deleted the other one.)
Last edited by iblues1976 on Thu Feb 23, 2012 4:09 pm, edited 1 time in total.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: is it bad style to do a = b = getVal()?

Post by Mind Calamity »

It's good style if it looks good to you, and you can understand it better that way instead of using 3 lines (though you'd never catch me doing that - I'd rather do 10 clean lines than 1 confusing).

And you certainly won't find it in the OGRE source, so I guess you could consider it bad style by the OGRE coding guidelines.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 535

Re: is it bad style to do a = b = getVal()?

Post by Kojack »

And you certainly won't find it in the OGRE source
Line 46 of Samples\ShaderSystem\include\ShaderSystem.h has:

Code: Select all

*left = *bottom = -1.0f; *right = *top = 1.0f;
:) :)

(Only one I could find with a quick search).
Czar
Kobold
Posts: 35
Joined: Sat Nov 05, 2011 12:18 am

Re: [SOLVED]is it bad style to do a = b = getVal()?

Post by Czar »

I personally prefer to avoid that way but there is nothing bad about it so long as you understand it.
Trioxin
Halfling
Posts: 63
Joined: Thu Jul 15, 2010 6:04 am
x 6

Re: [SOLVED]is it bad style to do a = b = getVal()?

Post by Trioxin »

If you feel that it's bad style, ask yourself more importantly, will you still remember what it means if you don't look at that source code again for 12 months?


Personally though, I would say yes, it is bad practice.
I'm a firm believer that if code needs any comments at all to explain what's happening, it should be reworked, so I would rather have half a page of variable declarations than one clever line.
Many times I've got a little too engrossed in my work and hammered out some code to do something exceptionally useful.

Six months later I start working on a project that could really benefit from that technique, only to go back to it and find the whole thing a hacked together, unreadable mess that's nigh on impossible to cleanly copy paste without reworking it for modularity.

For that reason I've learned from my mistakes and now I write my code in a way that's easier to read than it is clever and compact.
Sure it's more effort, but I always thank myself later.