Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, exile, Ayumi), 1,085 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 4 1 2 3 4
Re: How many Lines? [Re: LarryLaffer] #302468
12/19/09 18:16
12/19/09 18:16
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
but you can always use simple macros to stay away from that but i agree in some points making it 3 lines is better rather than making 1 line in more cpmlex way.

also linecount explain nothing and doesnt make a project better, what counts here is efficency and understanabilty of the algorithms.

i have a project with 3321 line in 9 files, it was around 15k lines in 4 files, and doing the same thing.

Last edited by Quadraxas; 12/19/09 18:16.

3333333333
Re: How many Lines? [Re: Joey] #302470
12/19/09 18:32
12/19/09 18:32
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Code:
a ^= b;
b ^= a;
a ^= b;



Joey, what does this sign mean? "^="? Couldn't find it in tha manual and not with google...

Re: How many Lines? [Re: Pappenheimer] #302473
12/19/09 19:13
12/19/09 19:13
Joined: Jul 2004
Posts: 1,205
Greece
LarryLaffer Offline
Serious User
LarryLaffer  Offline
Serious User

Joined: Jul 2004
Posts: 1,205
Greece


INTENSE AI: Use the Best AI around for your games!
Join our Forums now! | Get Intense Pathfinding 3 Free!
Re: How many Lines? [Re: LarryLaffer] #302478
12/19/09 19:46
12/19/09 19:46
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
Quote:
but that's dangerous practise, because like that a could overflow and produce unwanted results.
hm... at a first glance i think that it should work correctly even if an overflow happens.

Quote:
so why not just create an inline function or a macro performing this task?
XOR swap shouldn't be used anymore. modern optimizing compilers will produce a better solution automatically from the three variable swap.

Re: How many Lines? [Re: LarryLaffer] #302492
12/19/09 21:33
12/19/09 21:33
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
Originally Posted By: LarryLaffer

Let me give you another example. I see a lot of people use bitwise expressions so that they can use single-byte variables (f.e. a char) to store information for 8 different flags (true or false booleans). I'd rather use an array of 8 booleans to do this, to make the code more readable, even if C's booleans take 8 bits each. But that's just me..


i agree. I hate it when people do it because it deviates from the standard "look" of the rest of the code, so when reading through it, or even trying to reuse the code there is an unfamiliar convention about it.

Re: How many Lines? [Re: lostclimate] #302537
12/20/09 11:09
12/20/09 11:09
Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
TripleX Offline
Expert
TripleX  Offline
Expert

Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
A very difficult topic, but generally i agree to lostclimate / larrayLaffer (Even though I also use 8 different flags in one byte).

Generally I do not see an advantage (in software/game development for modern computers) if a code gets unreadable in favor of very small optimizations in speed. Probably only 20 more vertices on a model can aborb the effect of a little bit more efficient (see ^= or boolean flags) code.

Nevertheless you should never stop optimizing your code if it's possible to accomplish with effect in affordable time. But As a software-developer I can not explain to my customer that the development of a tool took so long, because several code parts were optimized and now run in a time of 100ns instead of 120ns - which included a lot of research work.

This does not mean, that simple optimization should not be done (for example the swawp above, as a define), but if you do now know such speed-ups - this won't be the reason why your program works slow.


For portable mobile-phone games / apps all above is senseless.

Re: How many Lines? [Re: LarryLaffer] #302559
12/20/09 13:37
12/20/09 13:37
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
In general I'm against optimizations done during the coding process itself. Most of the time there's a straightforward solution which works quite well. Optimizing time-critical code is another question.

But some people don't even code proper "normal" code (not optimized!) which gets lengthened and stretched half-way across the globe without getting to the point.

edit: you're right, Larry, your code will work, given that the overflow and underflow don't throw an exception and are reversible - but in c this should be the case, doesn't it?

Last edited by Joey; 12/20/09 13:39.
Re: How many Lines? [Re: Joey] #302642
12/21/09 02:55
12/21/09 02:55
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Originally Posted By: Joey
In general I'm against optimizations done during the coding process itself. Most of the time there's a straightforward solution which works quite well. Optimizing time-critical code is another question.
I'll agree with that, I see too many people breaking projects trying to reduce too many lines of code without rigorous testing to make sure it still does what it did originally.

General rule of thumb:
If code works, don't change it
If it could be changed for the better,
spend more time planning before just crunching,
Use the benefits your've found for your next project

currently working on 3 projects, 102k lines of code

Re: How many Lines? [Re: MrGuest] #302649
12/21/09 04:43
12/21/09 04:43
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
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
Re: How many Lines? [Re: EvilSOB] #302755
12/21/09 21:05
12/21/09 21:05
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
that's weird. i've actually never seen a person formatting source code like you. i've seen several people not formatting it at all, but this is... interesting ^^. but if it works for you, why not.

i must agree on that. as long as i can read my code, i feel that most programmers can read and understand it in more or less the same time, depending on skill. why? i can read and understand almost every code and its function, some fragments take longer, some less time. since i don't think that i'm coding harder stuff than everyone else out there, nor that i code especially ugly or weird stuff i project my own experience onto others. i also don't comment that much - i'm sure you all know the citation "if you can say it with code, code, else comment".

obfuscating code on purpose might has its use but personally i think it's none of a good or fair practice. and then again it's two keystrokes in a proper de to indent it the way everyone is used to.

if you're counting source code lines (to come back to topic) it all comes down to the skill of the programmer. in big teams this sloc might give some kind of idea, but then again i'd rather not say rasternudel or what he was called here with his force return float4 stuff would have a bigger project on the run and even if it was a TSLOCer.

Page 3 of 4 1 2 3 4

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1