Computer Science Canada My Minesweeper. |
Author: | Nemo296 [ Wed May 19, 2010 8:50 am ] |
Post subject: | My Minesweeper. |
This is a project I had to do for my programming class. I was hoping some people would be able to give me some suggestions to make my coding more effecient. This is a source code. |
Author: | Nemo296 [ Thu May 20, 2010 1:02 pm ] |
Post subject: | RE:My Minesweeper. |
40 views and no comments, sad. All I did was ask for some advice on how to make it more efficent. |
Author: | Tony [ Thu May 20, 2010 1:27 pm ] | ||
Post subject: | RE:My Minesweeper. | ||
Just 7 downloads of the source file though. Anyway, good use of constants, arrays, procedures. Recursion! This is quite well done. Some of the naming could be better chosen ("var Thing" ?). And there is some magic in certain places. What's going on here?
So maybe some comments regarding the intent would be useful. What is it that you are looking to make "more efficent[sic]"? If you are talking about speed of execution, don't say "everything". |
Author: | DemonWasp [ Thu May 20, 2010 1:31 pm ] |
Post subject: | RE:My Minesweeper. |
It's pretty efficient as-is; you've used arrays, procedures and Turing's API pretty effectively. Some tips:
Other than that, this is markedly superior to the typical output of high-school-level CS classes. |
Author: | chrisbrown [ Thu May 20, 2010 1:35 pm ] |
Post subject: | RE:My Minesweeper. |
If you remove delay (200), your program will finish 1/5th of a second faster. Seriously though, if by efficiency you mean minimizing the number of operations, I don't see anything that stands out. The only costly block is in your Display procedure, and since you only call that when the mouse is clicked, it's already pretty optimal. If it runs in realtime (without any lag), there's no need to improve. If you want some advice in terms of good coding practices, avoid using magic numbers throughout your code. What if I want the size of each cell to be 20 pixels instead of 16? Or red text instead of black? Those should be constants. There is more to be said about the general structure of the program, but that's probably beyond your skill level at this point. Keep coding, and you'll pick up on better ways to do things. |
Author: | Nemo296 [ Fri May 21, 2010 8:12 am ] |
Post subject: | Re: RE:My Minesweeper. |
DemonWasp @ Thu May 20, 2010 1:31 pm wrote: It's pretty efficient as-is; you've used arrays, procedures and Turing's API pretty effectively. Some tips:
Other than that, this is markedly superior to the typical output of high-school-level CS classes. What are these "Magic Numbers" you speak of? Is it like numbers that should probably be constants but arn't? |
Author: | DemonWasp [ Fri May 21, 2010 9:22 am ] |
Post subject: | Re: RE:My Minesweeper. |
Nemo296 @ Fri May 21, 2010 8:12 am wrote: What are these "Magic Numbers" you speak of? Is it like numbers that should probably be constants but arn't?
Yes, exactly. While it's usually okay to have a number like +1 or 0 or -1 just laying about in your program, it's probably best to put anything like 17.2 into a variable that can then be used to modify your program's behaviour without making edits everywhere. |
Author: | Tony [ Fri May 21, 2010 11:03 am ] |
Post subject: | RE:My Minesweeper. |
http://en.wikipedia.org/wiki/Magic_number_%28programming%29 |