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

1. How can I improve my memory for programming problem-solving?

One way to improve your memory for programming problem-solving is to practice regularly. The more you work on programming problems, the more familiar you will become with common patterns and techniques, making it easier to remember solutions in the future. Another helpful tip is to take breaks and give your brain time to rest and process information. Additionally, using mnemonic devices or creating visual aids can also aid in memory retention.

2. Is there a specific method or approach I should use when solving programming problems?

There is no one correct method or approach for solving programming problems, as different problems may require different strategies. However, some common techniques include breaking the problem down into smaller, more manageable parts, testing and debugging as you go, and utilizing pseudocode to plan out your solution before writing actual code. It may also be helpful to seek guidance from more experienced programmers or refer to online resources for problem-solving techniques.

3. How can I prevent myself from forgetting how I solved a programming problem?

To prevent yourself from forgetting how you solved a programming problem, it can be helpful to document your thought process and solution as you work through it. This could include writing comments in your code, creating diagrams or flowcharts, or keeping a journal of your problem-solving strategies. Additionally, revisiting and reviewing past solutions can reinforce your memory and help you retain important techniques and approaches.

4. I often struggle to remember syntax and specific functions while programming. What can I do to improve this?

One way to improve your memory for syntax and specific functions is to practice regularly and actively engage with the material. Instead of just copying and pasting code, try to understand why certain syntax or functions are used and how they contribute to the overall solution. You can also create cheat sheets or flashcards to help you remember commonly used syntax and functions. Additionally, as you become more familiar with a programming language, your memory for its syntax and functions will likely improve.

5. Are there any exercises or techniques I can use to improve my problem-solving skills?

There are many exercises and techniques that can help improve your problem-solving skills for programming. One effective exercise is to work on coding challenges or practice problems that require you to think critically and creatively. Another technique is to pair program with someone else, as this can expose you to different ways of thinking and problem-solving. Additionally, regularly reviewing and reflecting on your past solutions and thought processes can help identify areas for improvement and strengthen your problem-solving skills.

Similar threads

  • STEM Academic Advising
Replies
5
Views
935
  • Programming and Computer Science
Replies
33
Views
2K
  • STEM Academic Advising
Replies
7
Views
979
Replies
14
Views
650
  • STEM Academic Advising
Replies
5
Views
926
  • STEM Academic Advising
Replies
3
Views
1K
Replies
6
Views
936
  • STEM Academic Advising
Replies
7
Views
1K
  • STEM Academic Advising
Replies
11
Views
670
  • STEM Academic Advising
Replies
9
Views
1K
Back
Top