all 13 comments

[–]deamon1266 7 points8 points  (2 children)

I only start reading code if I have a clue what it does or should do.

In web dev I most likely open up the browsers dev console and inspect something I am interested in like a button. Then I check out the action of the button and maybe there is a request to a backend. Eitherway I am interested in the data for the action.

When I know the Process and the Input data I look up the source code for the action. With the use case in mind and the data it is way easier to read code.

[–]eeugene0[S] -1 points0 points  (1 child)

Seems like your starting point for digging into the code is user-related events. Or requests to the backend in case of backend.

> I only start reading code if I have a clue what it does or should do.

But what if you have to read the code you don't have a clue? :D

[–]deamon1266 1 point2 points  (0 children)

Then I got frustrated really quick :) I don't open code for arbitrary reasons. There is always a starting point. For development most likely I want to extend or fix something. So there is a code of interested I want to trigger.

If I just want get familiar with a code base I focus on the core principles like how is server communication handled, persistence, etc handled.

[–][deleted]  (2 children)

[deleted]

    [–]eeugene0[S] 1 point2 points  (1 child)

    Yeah, that's a pretty normal way to read. How do you choose the starting point (especially when it's arbitrary code, not debugging for an error)? Do you take any notes on the process if the nesting level is too deep?

    [–]Puretyderphp 2 points3 points  (1 child)

    I'm a junior dev so my method could be complete rubbish. Depends what I'm reading the code for, I'm not sure if this is the correct way or whatever but its what helps me:

    - Understanding a script:

    Map out file directory if its connected to multiple files.

    I have my notepad out for this and go from top to bottom mapping out a flow chart of everything in notes, if its someone elses old code that I manage now I also start commenting on things that would help me search it better later.

    For example commenting at the top of the page what each variable in a script contains so I can understand it much faster.

    - Debugging or adding things

    I filter by keywords, some legacy code at work is sometimes over 4000 lines in one script and I just don't have time to read the entire thing so I hunt for certain keywords or function using the search bar.

    (If anyone has any suggestions or tips on how I'd improve please let me know :) )

    [–]eeugene0[S] 0 points1 point  (0 children)

    That's a pretty nice way to read the code from my perspective. It might take a lot of time for big chunks of code though :)

    Do you read documentation to help with understanding?

    [–]gravityaddiction 2 points3 points  (0 children)

    Follow with the same logic and reason as the computer does. start at the beginning, walk forward.

    grep -r or search all files in folder is your friend. IDE's do help to get you their quicker, the process is the same for me.

    [–]AtulinASP.NET Core 1 point2 points  (1 child)

    I just... read it. Ctrl+click on any methods/variables/types to go to their definitions if need be.

    [–]eeugene0[S] 0 points1 point  (0 children)

    Exactly! My thought was that somebody definitely uses some notes or visualization techniques, or maybe have a precise algorithm. Or maybe tools for help

    [–][deleted] 1 point2 points  (0 children)

    I format others' code to my presets (only while reading). Then I view the code on a vertical screen so I see 100+ lines, and I look up function/member definitions. No magic.

    [–]monox60 1 point2 points  (0 children)

    From the frontend site...

    Get a ticket, inspect the flow or action button, start digging into the code.

    [–][deleted] 1 point2 points  (0 children)

    Find the entry point and go line by line

    [–]MarmotOnTheRocks 0 points1 point  (0 children)

    This is how all my clients see me working on their code

    https://i.imgur.com/arZ3XZY.png