Article 5F9SM How can you read and follow code to actually understand it?

How can you read and follow code to actually understand it?

by
jsbjsb001
from LinuxQuestions.org on (#5F9SM)
I've read countless articles, forum posts, etc on this, like for example, following the main() function, but I still get lost every time. It's not so bad when it's code I've written, because I know what I was thinking at the time, or at least what I was trying to do. But when it comes to code written by others, even if I know what the program does when I run it, I still get completely lost trying to read and understand it, even if it's in C and is using concepts and constructs I've familiar with. It might be ok if it's the whole of two lines, and/or it just adds two numbers together and displays the result and that's about it. But anything even just semi-complex is like trying to read a spoken language I just don't speak or know any of.

But yet, if it's trying to figure something out at a "high level", like for example solving non-programming related technical problems, like general Linux problems for example, then I can 9 times out of 10 figure it out and solve it. If I read someone's post here where they're asking for help with some Linux problem (or sometimes non-Linux related technical problems too) I can read their post(s), follow what they're saying, and normally figure out at least where things are likely going wrong for them (provided it's a technical related subject I'm familiar with of course - can't claim to know everything), and at least most of the time, help them figure out a solution to it. A very recent example of what I'm saying, and in relation to a problem I was having (but didn't need to post a thread asking for help myself about); I very recently upgraded my system to OpenMandriva Lx 4.2 from 4.1, but it took three go's to actually not only get it installed, but get a working system. The first problem was that, I told it's installer to just format my root partition, and just add an entry to fstab for my home partition, but while it did do that, upon system restart it would drop into an emergency shell and wouldn't ask for my LUKS encryption password (as I encrypt my home partition, but not the root partition - since there's nothing sensitive on that). So I thought hmmm, wonder if the installer actually added my home partition to fstab? So I had a look at fstab, and yes it did, but it didn't specify any actual node, just the path to the node, but no device node (the device-mapper node). So I thought, "well I was thinking about repartitioning the drive anyway, so I'll just copy what's on my current home partition to my other drive, and repartition", so I did just that, and then set the relevant mount points in the installer. Then I restarted the machine again after the installer had said that OpenMandriva had been installed, and my machine booted into the UEFI BIOS settings instead. So I had a look at the boot order and there were no boot entries listed, so I booted back into the live system and had a look with efibootmgr, and that reported zero boot entries in NVRAM. So I mounted the root filesystem on the partition I'd created before (that OpenMandriva was supposed to be installed to), and sure enough, it was empty. So I thought, "this time I'll mount the partitions I'd created beforehand, then run the installer to [hopefully] install OpenMandriva this time", so I done just that, then for the third time once again run OpenMandriva's joke of an installer. Then once that had said it had finishing installing OpenMandriva onto my machine, I once again restarted it, and voila! OpenMandriva was not only installed, but booted up no problems. The point is: troubleshooting that, and figuring out the chain of events was fairly easy, but I just can't seem to transfer that to following other people's code no matter how (or how hard) I try and follow it.

I'd just like some practical advice on how I can follow other people's code without getting completely lost - particularly where people have used meaningless variable names that don't describe said variable(s) purpose (which makes it a thousand times harder again). I'm not looking for a debate on the best way to read code either, just how exactly I can read it, so I can follow and understand it. While I'm mainly asking in relation to C (since that's about the only language I've made any serious attempt to try and learn), as long as it's still applies to C as well, any advice that helps would be good. I might be doing a programming course within the next 3 - 6 months sometime (although while I think it includes C# :eek:, sadly it doesn't look like it'll be in C itself), so I'd really like to try and get as much of a head start as I can if that comes about. I have also tried (as suggested by others in my other programming threads here) to get a better handle on mathematics as well, so hopefully I've done enough on that front.

Thanks in advance for any help/advice.latest?d=yIl2AUoC8zA latest?i=F67n7y1JN-E:i2eiI2QwWc4:F7zBnMy latest?i=F67n7y1JN-E:i2eiI2QwWc4:V_sGLiP latest?d=qj6IDK7rITs latest?i=F67n7y1JN-E:i2eiI2QwWc4:gIN9vFwF67n7y1JN-E
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments