Programming is coming to me but I forget how I solved the problem...

In summary, the author describes how to program more effectively by commenting and providing a detailed specification of the code.
  • #1
shivajikobardan
674
54
I'm surprised that automatically programming is coming to me. It blows my mind. I could not think of any logic in the past months and now I am able to solve puzzles in programming. But the toughest part is I forget how I solved the problem too quickly.
For example, the blackjack program. I forgot what thinking process I used to solve that problem. How do I avoid this issue?
 
  • Like
Likes symbolipoint
Physics news on Phys.org
  • #2
That's a reason to be adding comments to your code.

In addition to well-commented code, in real-world programming, you will generally start with a written specification for the code, which documents the tasks to be completed and the algorithms that will be used.
 
  • Like
  • Informative
Likes dlgoff, shivajikobardan and symbolipoint
  • #3
berkeman said:
That's a reason to be adding comments to your code.
what he said (very small).jpg


When you write a new program, I recommend putting in a comment block that describes what it is that you are doing. Here's what appears to be a rather extreme example. It may seem like overkill to do this kind of stuff, but You would not BELIEVE how useful this kind of thing has been to me over the years as I have tracked down bugs and made changes. Small comment blocks in front of each section of code repeats what is said in this long header comment. This block shows the complete action of this section of a particular subroutine in what is a very large overall program.

Code:
       '   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -
        '
        ' for each thumb
        '   1) if the thumb file in the thumb file folder differs from the one in
        '      the active thumb file directory, copy the one in the thumb folder
        '      over on top of it. If they're the same then do nothing.
        '
        '   2) GONE (reorganized out of existence but left in to avoid having
        '      to renumber all the rest of what follows)
        '
        '   (this 3 replace old 3 and 4)
        '
        '  3a) if a folder does not exist for that wood, create one and move all
        '      of the appropriate JPEG files to it
        '  3b) else if the folder exists, check to see if all JPEG files are
        '      the same and if so, you're done but if not, then copy over any that
        '      are not already there and remove any that shouldn't be there
        '
        '   4) GONE (reorganized out of existence but left in to avoid having
        '      to renumber all the rest of what follows)
        '
        '   5) create a <name>.htm file for that wood
        '           5.1) if file already exists, kill it
        '           5.2) create new file
        '           5.3) put appropriate text at the beginning
        '           5.4) insert a reference to the fact sheet if there is one
        '               (and if there is one, copy it over)
        '           5.5) add pointers to all of the JPEG files and add further
        '                HTML files for each HREF in the original and add an
        '                entry for each referenced JPEG file
        '           5.6) put the appropriate text at the end
        '           5.7) if this is a new letter, put in a reference tag for it
        '
        '   6) if there are any "see also" names that come before this name,
        '      then insert them into the _@02 main page index.htm file being created
        '
        '  7a) put an href and an img src reference to the
        '      thumbnail into _@02 main page index.htm (USED TO BE more complex
        '      with two smaller index files)
        '
        '  7b) save the wood name and number of pictures (without enlargements)
        '
        '   8) if there is a corresponding htm file in "HTML with comments",
        '      then analyze it and the new one and make sure they have exactly
        '      the same set of href's and img src's and if they do, then
        '      copy over the one from "HTML with comments" to replace the new
        '      one but if they don't then copy over the "HTML with comments"
        '      one with an underscore at the front of the name, and do a
        '      debug.print of that name to alert the user.
        '
 
  • Like
Likes berkeman

Similar threads

  • STEM Academic Advising
Replies
5
Views
949
  • Programming and Computer Science
Replies
33
Views
2K
  • STEM Academic Advising
Replies
7
Views
1K
Replies
14
Views
687
  • STEM Academic Advising
Replies
5
Views
952
  • STEM Academic Advising
Replies
3
Views
1K
  • STEM Academic Advising
Replies
5
Views
141
Replies
6
Views
975
  • STEM Academic Advising
Replies
7
Views
2K
  • STEM Academic Advising
Replies
11
Views
764
Back
Top