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

AI Thread Summary
Automatically programming can be surprising and rewarding, as it leads to the ability to solve complex puzzles, such as creating a blackjack program. However, a common challenge is forgetting the thought process behind the solutions. To mitigate this issue, it is essential to add comments to the code. Well-commented code not only aids in understanding the logic used but also serves as a valuable reference when debugging or making changes in the future. Starting with a written specification can further clarify the tasks and algorithms involved. Implementing detailed comment blocks can enhance clarity, making it easier to track down bugs and understand the structure of the program. This practice, while it may seem excessive, proves beneficial over time as it provides a roadmap of the code's functionality and intent.
shivajikobardan
Messages
637
Reaction score
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
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
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.
        '
 
guys i am currently studying in computer science engineering [1st yr]. i was intrested in physics when i was in high school. due to some circumstances i chose computer science engineering degree. so i want to incoporate computer science engineering with physics and i came across computational physics. i am intrested studying it but i dont know where to start. can you guys reccomend me some yt channels or some free courses or some other way to learn the computational physics.
I'm going to make this one quick since I have little time. Background: Throughout my life I have always done good in Math. I almost always received 90%+, and received easily upwards of 95% when I took normal-level HS Math courses. When I took Grade 9 "De-Streamed" Math (All students must take "De-Streamed" in Canada), I initially had 98% until I got very sick and my mark had dropped to 95%. The Physics teachers and Math teachers talked about me as if I were some sort of genius. Then, an...
I am currently in the second (and final) year of my MS in Physics. I've just started my research, which focuses on identifying Dark Matter through Beyond the Standard Model (BSM) extensions. My supervisor has directed me to learn model building using FeynRules and subsequent calculations via MadGraph or other simulators. I've successfully built models for QED and QCD, and I am now working on Weak Interactions, Electroweak theory, and symmetry breaking. My immediate goal for the next few...

Similar threads

Replies
24
Views
2K
Replies
5
Views
1K
Replies
1
Views
1K
Replies
7
Views
3K
Replies
9
Views
2K
Replies
26
Views
5K
Replies
3
Views
2K
Back
Top