Asking for code review - contract programming

chopchop yetanethorfake_addr at gmail.com
Wed Jan 12 15:36:05 UTC 2022


On Tuesday, 11 January 2022 at 17:40:48 UTC, Ali Cehreli wrote:
> In general, adding two Coordinates is suspicious to me:
You are right, there should be Coordinate and Vector somehow

> Accounting for the walls with +1, -1, etc. looks scary to me. I 
> wonder whether the playground could be detached from the walls 
> and you could use the familiar 0 indexed access. Perhaps by 
> slicing inside a bigger area or by a special type that hides 
> that logic from us.
Yes, that's a bit disturbing at first. I just re-read Ground, in 
fact there is a lack of consistency in the use of those +1, which 
is probably confusing. I will work on it.
But I kept the walls as part of the playground, because indeed 
they are, and the snake can reach "into" the wall. This is of 
course a GameOver condition, but perfectly legit! I realized with 
those "+1" that loosing is part of the game :)
I discovered that the real problem is when the snake tries to 
reach "beyond" the wall, which is then a programming error, and 
there is a contract on that.

>use the new contract
I did not know about the new syntax! I am definitely going to use 
it.

> What do you think? Can the industry guidelines be sufficient to 
> make D safe enough? Otherwise, a D program can spend a long 
> time during a GC cycle. (So can other languages where 
> destruction of even a single object can spend a lot of time but 
> nobody pays attention to that.) Also, the program can run out 
> of memory unless run-time dynamic allocation is banned by 
> guidelines.
>
> Ali
I would say, planes don't do sharp turn :) Maybe small UAVs 
(drones) would be more sensitive to delays. Reliability is more a 
factor. But how much delay are we talking about? More like 1ms, 
10ms, 100ms, 1sec? I mean, if you can give an example of a 
program and its delay, it's interesting.

Then my project has limited focus, GC is another thing. A lot of 
components for aero subsystems are in C, and BetterC retains 
unittesting... and contract if I am not mistaken? Also those 
subsystems have very precise requirements which can most often 
translate into static arrays, etc. There would be so much to 
explore...






More information about the Digitalmars-d mailing list