Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 1,151 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: for loop special case broken [Re: jcl] #417119
02/08/13 16:19
02/08/13 16:19
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Thank you very much for taking the time to explain. It's highly appreciated. I'm still interested in the technical background. If answering my questions takes too much time feel free to ignore them.

Originally Posted By: jcl
"Fixing" it would require to re-write the for and while loop handling in the compiler...

I still don't understand the way you implemented for loops and why a "wait" is a special case here. For loops are nothing else but syntactical sugar. Any for loop like
Code:
for (expr1; expr1; expr3)
{
   body;
}

can easily replaced by
Code:
expr1;
while (expr2)
{
   body;
   expr3;
}

The only pitfall here is that if you have a "continue;" in the body you have to replace it with a "expr3; continue;". But that's it. Once you got the while loop you get the for loop almost for free. It shouldn't even be necessary to touch the actual compiler code for this.
Originally Posted By: jcl
You just don't program in this way when you want clean code
What's unclean about it? I wonder why noone had the idea for a macro like
Code:
#define each_frame for (;; wait(1))

This would effectively prevent you from programming endless loops because you forgot a wait. E.g.
Code:
each_frame
{
   draw_quad(...);
}


Originally Posted By: jcl
In fact we would put a lot of effort in ending up with a worse software than before.
I have to keep this in mind for my work.
Boss: There is a bug in your code. Fix it!
Me: No, introducing special cases will only reduce maintainability and make the software worse.
grin


Always learn from history, to be sure you make the same mistakes again...
Re: for loop special case broken [Re: Uhrwerk] #417125
02/08/13 17:53
02/08/13 17:53
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
wait is not a normal function (i think it hasn't even a real function structure)
so handling this is not so easy

and just change your code to this:
Code:
for (my-frame = 0; ; my->frame += time_step;)
    wait(1);



Visit my site: www.masterq32.de
Re: for loop special case broken [Re: MasterQ32] #417129
02/08/13 18:53
02/08/13 18:53
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I'm well aware of the fact, that wait is a "special" function and I'm even able to rewrite a simple for loop. I'm even not insisting on fixing this. JCL will know if a fix makes sense or does not.

The thing is that I want to understand what's going on - out of curiosity.


Always learn from history, to be sure you make the same mistakes again...
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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