OK, I may be a few posts out of date here but I cant see why
I should be "paid" three times the amount for
Code:
//Switch two variables
a+=b;
b=a-b;
a-=b;

OR

//Switch two variables
a+=b;
b=a-b;
a-=b;



When I can happily use
Code:
//Switch two variables
a^=(b^=(a^=b));
OR

//Switch two variables
a-=(b=(a+=b)-b);



And Im sorry Quadraxas, but I gotta dis-agree with...
Originally Posted By: Quadraxas
...what counts here is efficency and understandabilty of the algorithms.

Why is the understandability important?
As long as YOU can understand YOUR OWN code, who cars if its a bastard for others?
(unless you are writing a tutorial of course)

I myself am in the middle of an entry for the summer retro comp.
(so everyone else may as well give up and abandon their projects ....please?)
And its only at 2400 lines over 9 files ATM, but it would be much larger
if I formatted my code differently. Here is a typical example...
Code:
CAR* retrieve_car(int index)	//retrieve a car (regardless of city-number)
{	if((index<0)&&(index>MAX_STORAGE))			return(NULL);	//invalid index number
	CAR *thiscar=NULL;		if(storage.car[index])		{	storage.count--;
		thiscar = storage.car[index];		storage.car[(index--)+1]=NULL;	}
	for(index=1; index<MAX_STORAGE; index++)	//reshuffle table to remove blanks
	{	if((storage.car[index])&&(!storage.car[index-1]))
		{	storage.car[index-1]  = storage.car[index];		storage.car[index] = NULL;
			storage.city[index-1] = storage.city[index];						}	}
	return(thiscar);		/*return CAR or NULL if not found*/						}


It may seem ugly to most people, hell, its ugly to me, and Im its FATHER...
But, it makes easy sense and readability to me, as I (mentally) break my code up into line-minimised "logical" blocks.
Like so...
Code:
CAR* retrieve_car(int index)	//retrieve a car (regardless of city-number)
{
////------------------------- function validity checking ------------------////
	if((index<0)&&(index>MAX_STORAGE))			return(NULL);	//invalid index number
////------------------------- get data from storage -----------------------////
	CAR *thiscar=NULL;		if(storage.car[index])		{	storage.count--;
		thiscar = storage.car[index];		storage.car[(index--)+1]=NULL;	}
////------------------------- tidy up storage space -----------------------////
	for(index=1; index<MAX_STORAGE; index++)	//reshuffle table to remove blanks
	{	if((storage.car[index])&&(!storage.car[index-1]))
		{	storage.car[index-1]  = storage.car[index];		storage.car[index] = NULL;
			storage.city[index-1] = storage.city[index];						}	}
////------------------------- return retrieved data -----------------------////
	return(thiscar);		/*return CAR or NULL if not found*/						}


It actually looks a hellishly lot more ugly here in the forum than in SED BTW.

Its all a matter of personal preference.
My code ends up as tight (closely packed that is), easily clone-able, largely self-contained "hunks" of code,
which has quite few lines, but lots of code packed in them...

The reasons behind this style of programming lies in the origins of the EvilSOB.
Unfortunately, I began coding professionally back in the early 90's and it was a cut-throat place.
Employers "owned" your source-code, so some coders (like myself) developed our own
coding techniques to "obfuscate" our code.
So if another (see cheaper) coder was employed later to 'enhance' our old code,
they had to be VERY good to figure out how our code did what it did....
Usually it was cheaper for the employers to call US back to update our own code.
With us calling the shots on the paypacket this time...

Thats the coding environment I grew up in, and much of it is still indelibly etched into my soul,
regardless of how obsolete the reasons for it are now...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial