Advice for overcoming insurmountable coding tasks?

  • Thread starter Silicon-Based
  • Start date
  • Tags
    Coding
In summary: C++ or C. If it is C++ or C, bite the bullet and learn it. It doesn't take that long to learn, you already spent 2 months and not going very far.In summary, the newcomer has difficulty understanding and using a program written in C.
  • #1
Silicon-Based
51
1
I've joined a group which studies cold atoms a little over two months ago. I was asked to write a Markov Chain Monte Carlo script, which I did, and which turned out really promising. I've been programming in Python for almost a year now so this wasn't too difficult to do. Shortly thereafter, the PI introduced me to a PhD student in the group who has been developing a large program in C on his own. Of course, C is much faster than Python for such types of computations, so I'm meant to use his program from now on (after implementing my script into it). His program also uses a range of data structures such as binary trees, which speed up the computations a lot, but which I don't know anything about having only taken one basic class on intro to programming for physicists in Python.

The issue is, it's been almost two months now but I'm still unable to comprehend how the program actually works. I really don't understand what struct or pointers do. I don't understand or can hardly keep track of how each of the (many tens of) files talk to each other anyway. It took me several days just to get used to using Linux, Git, and the program each. I'm being asked questions relating to the program I cannot answers, or asked to modify the program in ways I cannot to. I've been almost entirely useless to the group for a while now. The only useful thing that I can do is to actually use the program to generate data and plot it. If I was writing my own program in Python I could probably add new features without much trouble, but that's of course not an option.

How would you recommend trying to understand such a program? It feels frustrating to be expected to do things I'm pretty much unqualified to do and failing. The PhD student isn't particularly useful too.
 
Last edited:
Technology news on Phys.org
  • #2
Silicon-Based said:
but I'm still unable to comprehend how the program actually works

Ask.
 
  • Like
Likes jim mcnamara
  • #3
The canonical book to learn those subjects is

The Art of Computer Programming, Volume 3, by Donald Knuth.
https://www.amazon.com/dp/B01AY4ZHLI/?tag=pfamazon01-20

I also expect that there must be several online coursed on video if you search for them.
 
  • #4
This stuff is complicated and takes time to learn. Don't get discouraged. I would sit down with either the PhD student or your PI (or both) and explain to them what you told us. Then ask them to explain in detail how it all fits together. If you don't understand - ASK. It may make you feel like an idiot for a while, but it is the only way to learn.
 
  • Like
Likes phinds and jim mcnamara
  • #5
I had a coworker in that predicament. He got my C program and had to get up to speed to maintain it.

He mapped out the functions and what they did starting at the main function and working down level by level.

Running a working version in a debugger would help you really understand the flow and what is going on. You can step into or over function calls look at the data and to piece together how it works.

Later, breakpoints can be added to step through specific parts of the code.

Alternatively, you can add logging code to trace program operation. Something like log4c perhaps although custom print functions are simpler.
 
  • #6
I guess the first step is obvious, you've got to learn C. I wouldn't waste time reading the code or trying to modify it until then.

I found a "crash coarse" out there. Maybe that would be enough?

https://stuff.mit.edu/iap/2007/c/CrashCourseC.html
 
Last edited:
  • #7
I am new in programming learning C++. Question is what is the language mostly used at your place of work? If it is C++ or C, bite the bullet and learn it. It doesn't take that long to learn, you already spent 2 months and not going very far. I am learning C++ as my first language since 40 years ago, it's NOT that hard. I finish pointers(the only part so far that is confusing and tricky) and getting into Struct next week. I scanned through like 10 pages, looked to be very straight forward. I only started exactly 2 months ago.

I study only C++, not C. I have 4 books, The best is one is C++ From Control Structures through Objects by Tony Gaddis. I use the 6th edition which you can download on line. You can buy used really cheap. I paid less than $10 including shipping. It's the best book for beginners. People here are very helpful also.

Take the time to learn, trying to take the short cut likely ending up wasting more time. I am sure if you started learning C right when you are assigned to the project, you might be able to contribute to the group now.

Ha ha, for me, my question is should I learn Python or Java next as I am approaching the finishing line at least for starter of C++.
 
  • #8
Learn basic C (not C++), and read a good introductory book on data structures. This is worth doing in general if you want to know anything about how to write complex computer programs going forwards. C is a difficult language because it is not independent of the hardware it runs on, and it requires you to understand EXACTLY what is going on in the computer's memory at all times. Failure to do so will result in bugs you can never resolve. Basic data structures (pointers, linked lists, strings, sorting, etc) is required of all computer science students and for a reason. If this is too much to do on your own, just take a data structures class online from a reputable instructor. You will suffer--this is not a trivial learning curve--but the gain will be great.
 
  • Like
Likes yungman
  • #9
harborsparrow said:
Learn basic C (not C++), and read a good introductory book on data structures. This is worth doing in general if you want to know anything about how to write complex computer programs going forwards. C is a difficult language because it is not independent of the hardware it runs on, and it requires you to understand EXACTLY what is going on in the computer's memory at all times. Failure to do so will result in bugs you can never resolve. Basic data structures (pointers, linked lists, strings, sorting, etc) is required of all computer science students and for a reason. If this is too much to do on your own, just take a data structures class online from a reputable instructor. You will suffer--this is not a trivial learning curve--but the gain will be great.
Do you have suggestion on online classes for programming? I am at the point of studying a little bit beyond one semester of C++. I want to look at options of on line classes even if I have to pay for it. I even looked at the class offered in State U around my area since they have to do on line classes anyway so I don't have to actually go to the classes, but I have not seen something like intermediate C++ class. Self studying and asking questions here might not be a long term solution.

BTW, why C, not C++?
 
  • #10
The last I checked, MIT has put a lot of their classes online for free. I know also that Princeton Univ. and Univ. of Penn. have also put lots of the comp. sci. classes online. The good thing about an online course is, maybe you can gauge out front if that professor's style works for you. Not ever teacher matches every student's learning style.

I would start with C only--it's already difficult enough even without object orientation and all the other stuff added to turn C into C++. And then later, once you are confident with C, move on to C++ if you really want to. C++ can be particularly frought because it allows multiple inheritance, a pitfall all the other object oriented languages which came later managed to avoid or prevent. The thing with C (of C++) is, it doesn't hide the computer's hardware architecture from you, and it doesn't do anything at all to help you with memory management (which is why C programs are so subject to what we call "memory leaks" where the programmer fails to reclaim used memory correctly, or segmentation faults and all that crap). You just won't get those problems in more modern languages such as Java.
 
  • Like
Likes yungman
  • #11
How does on line classes work, they have video lectures? I never took online class before, do you get to ask questions? I studied up to but not yet Classes, Inheritance, Polymorphism. From talking to my grandson that just took a C++ class, it is a little more than one semester. So far, it's not difficult, but I think it's going to get harder fast.

I am just starting to look into this. I don't know what my ultimate goal is as I am not looking for a career, I am done with that. Just keep my mind busy. I just bought a book on gaming
https://www.amazon.com/gp/product/032151291X/?tag=pfamazon01-20

and data structure:https://www.amazon.com/gp/product/0071353453/?tag=pfamazon01-20

So I might study those after finishing up the last few chapters on Classes, Inheritance and Polymorphism.
 
  • #12
I know this professor (Dr. Chris Murphy) and he is really really a good teacher. His course would be ideal if you can handle it (not sure what level you are at):

https://www.edx.org/course/data-structures-and-software-design

Unfortunately, it seems to be using Java. If you have not done object oriented concepts yet, you won't be ready for this one.
 
  • #13
harborsparrow said:
I know this professor (Dr. Chris Murphy) and he is really really a good teacher. His course would be ideal if you can handle it (not sure what level you are at):

https://www.edx.org/course/data-structures-and-software-design

Unfortunately, it seems to be using Java. If you have not done object oriented concepts yet, you won't be ready for this one.
No, I am not ready, I don't know Java, I am just getting into OOP. Too bad they don't have any C++ class.

thanks
 
  • #14
harborsparrow said:
C++ can be particularly frought because it allows multiple inheritance, a pitfall all the other object oriented languages which came later managed to avoid or prevent.
Multiple inheritance is not a 'pitfall', it is a powerful feature which is also implemented by many other OO languages (including nearly all of those in common use today).
 
  • Like
Likes strangerep
  • #15
pbuk said:
Multiple inheritance is not a 'pitfall', it is a powerful feature which is also implemented by many other OO languages (including nearly all of those in common use today).
Is learn OOP harder? I am about to get into Classes in Chapter 13. The first sentence in the chapter is " So far in the previous chapters, all you learn are Procedural Programming..."

! Ha ha, thanks a lot! Now you are telling me! I thought I have been learning OOP as C++ is OOP.

Is Classes, Inheritance and Polymorphism harder to learn. I want to know to gauge how to approach them. So far, other than pointers, reinterpret>cast( In a lot of ways are pointers) and some binary files, it's been not hard to learn. Do I need to site myself up for the next two chapters?

I am glad I chose C++, I think you suggested me to buy the Schaum's Data Structures with C++, I also bought the book by Gaddis C++ for gaming. It's nice to have books on more advanced subjects using C++, so I don't have to learn another language yet. I can't wait to finish my current book and get on to another one.

Thanks
 
  • #16
yungman said:
Ha ha, thanks a lot! Now you are telling me! I thought I have been learning OOP as C++ is OOP.
The part of C++ that you've been working on doesn't have much to do with OOP. Other than working with STD string objects (as opposed to C-style character arrays), you haven't been exposed to classes very much.

The reason that much of what you've been learning is straightforward is that it was not all that different from other procedural languages that you've worked with before, just using different syntax.
yungman said:
Is Classes, Inheritance and Polymorphism harder to learn.
I'm going to say that they will be about the same in difficulty, since you don't have prior experience to draw upon. When you start writing your own classes, there can be a lot of stuff going on under the hood, such as constructors, copy constructors, and destructors showing up, seemingly out of the blue.

If you take it slowly, with patience, maybe not too hard.
 
  • Like
Likes yungman
  • #17
Mark44 said:
The part of C++ that you've been working on doesn't have much to do with OOP. Other than working with STD string objects (as opposed to C-style character arrays), you haven't been exposed to classes very much.

The reason that much of what you've been learning is straightforward is that it was not all that different from other procedural languages that you've worked with before, just using different syntax.
I'm going to say that they will be about the same in difficulty, since you don't have prior experience to draw upon. When you start writing your own classes, there can be a lot of stuff going on under the hood, such as constructors, copy constructors, and destructors showing up, seemingly out of the blue.

If you take it slowly, with patience, maybe not too hard.
Thanks, I was so worry about getting into the later chapters.

BTW, I am having a ball with the debug-->windows-->Intermediate. This is everything I want, type in the expression and I get the value! That tricked me when I kept type in the program instead. All the other debug windows don't let me type anything, just show me what's going on( well in memory, I can put the address I want to see).

thanks
 
  • #18
harborsparrow said:
multiple inheritance, a pitfall all the other object oriented languages which came later managed to avoid or prevent

Python has multiple inheritance, and while it can certainly be misused, I have found plenty of good use cases for it over the years I have been programming in Python.

According to the Wikipedia article on multiple inheritance, other languages that support multiple inheritance include Common Lisp, Go, OCaml, Perl, Ruby, and Scala. So your claim here does not appear to be correct.
 
  • #19
1) Let the PI know immediately that there is a problem and that you need help. Do not blind-side him.
2) Trying to understand a large, sophisticated, program can be very hard for the best of us, especially if it is poorly documented or if the originator is not helpful. Doing that with an unfamiliar language and operating system can be unrealistic.

Try to work with your PI to get a team that will guarantee success. You need a very experienced programmer on the team. There is no reason for you to be tortured.
 
Last edited:
  • Like
Likes Jarvis323 and Tom.G
  • #20
I remember - there was this program that mapped all the calls and definitions in a multi-file project and printed out the map. But I cannot remember what it was called! Useful gadget, though.
 
  • Like
Likes FactChecker
  • #21
You can run the code through something like Doxygen and get some documentation. If the comments in the code are in a Doxygen format, the resulting documentation may be very helpful.
 
  • #22
One thing that you should get clear first is how much of the code you really need to understand. Maybe you only need to make a function for your own algorithm and call it from the existing code. Or maybe you only need to make a small change in the code without understanding how the rest of it is working.
 

1. How do I approach a coding task that seems impossible to complete?

The first step is to break down the task into smaller, more manageable chunks. This will make it less daunting and easier to tackle. Then, prioritize the chunks based on their importance and start working on them one by one. This will help you stay organized and focused.

2. What resources can I use to help me overcome an insurmountable coding task?

There are various resources available such as online tutorials, forums, and coding communities where you can seek help and guidance from experienced coders. You can also consult with your colleagues or mentor for their insights and suggestions.

3. How can I stay motivated and avoid giving up when facing a difficult coding task?

It's important to remember that coding is a continuous learning process and challenges are a part of it. Remind yourself of your ultimate goal and the satisfaction you will feel once you overcome the task. Take breaks when needed, and don't be afraid to ask for help.

4. What strategies can I use to problem-solve when stuck on a coding task?

One strategy is to step away from your computer and take a break. Sometimes, a fresh perspective can help you come up with new ideas. You can also try talking through the problem with a colleague or writing it down to better understand it. Additionally, try breaking down the problem into smaller parts and solve them one by one.

5. How can I prevent feeling overwhelmed when facing an insurmountable coding task?

To prevent feeling overwhelmed, it's important to stay organized and prioritize your tasks. Make sure to take breaks and avoid working for long periods without any rest. You can also try using different problem-solving techniques, such as brainstorming or visualizing the problem, to help you approach it from a different angle.

Similar threads

  • Programming and Computer Science
Replies
7
Views
488
Replies
6
Views
658
  • Programming and Computer Science
Replies
5
Views
855
  • Programming and Computer Science
Replies
28
Views
734
  • Programming and Computer Science
Replies
0
Views
772
  • Programming and Computer Science
Replies
7
Views
668
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
1
Views
732
Replies
3
Views
339
Replies
6
Views
1K
Back
Top