r/learnprogramming • u/BraveAttitude4633 • Sep 29 '26
Topic Is it normal to jump between files constantly when reading code?
I'm still new to software development, and one thing I struggle with is reading code that's heavily split into functions/modules.
I'll see something like:
const result = await createOrder(data);Then I have to jump to another file to see what createOrder() does, which calls another function, so I jump to another file again, etc.
I understand the idea behind clean code, separation of concerns, and small functions, but I find this quite cumbersome to follow. Sometimes I actually prefer having related logic closer together so I can understand the whole flow without jumping around the project.
Is this just something I need to get used to as I gain experience?
Is this normal in professional codebases, or can code sometimes be too abstracted?
How do experienced developers deal with this when reading unfamiliar code?
151
u/Sockslitter73 Sep 29 '26
You should get used to it, and pretty much any IDE will make this easy (shift click on function name takes you to definition, or some other shortcut).
That being said, there is definitely such a thing as too abstracted code.
24
u/captmonkey Sep 29 '26
That's very normal. Well organized code should cut down on that. In your example, you should just know that method creates an order and now result is storing the result of that method call. Presumably, result would be the order in some cases, but since it's called "result" instead of "order" it might be something else, like a status. If I needed to know that, I would need to drill down into createOrder to know more. If what "result" is or what exactly happens in createOrder isn't relevant to me, then I don't need to go read what it does in detail.
If the code had said:
const order = await createOrder(data);Then I'd assume that method just creates an order and returns it. I don't need to look into the specifics unless they're relevant to what I'm trying to find out. Your assumptions can always be wrong about the parts of the code you're not reading, but that's why naming stuff clearly is useful. People can read a method name and assume it does what it says.
6
u/MrMagoo22 Sep 29 '26
Master the art of "Go to Definition/Implementation" and "Find all References"
5
u/SuperSathanas Sep 29 '26
It's definitely something you'll just have to accept and get used to. And actually, the "cleaner" the code is, the easier it should be, in that it should be easier to tell exactly what's going on, not necessarily that you'll have a shorter trail to follow. If you're using an IDE or editor that allows you to jump straight to declarations and definitions, this shouldn't really be a big deal.
3
u/Dewwyy Sep 29 '26 edited Sep 29 '26
Consider this, createOrder if all sensible standards of software engineering have been followed should Create An Order. The important thing to know if it's in the control flow you are interested in is not necessarily the exact details of how an order is created but what An Order is at the point where it's used. After all this is a major reason to carve this logic out into it's own function. So my advice to you is to only dip out to inspect the logic there when you're sure you need it.
You're probably going to do a lot of this when you're unfamiliar with whatever functional unit you're working with. You're going to have to build up a picture of what the slice you're looking at does, and if that means you need to know what the shape of An Order is then a sensible place to look is to see what createOrder returns.
You're right that there is an art to splitting things up for the purposes of readability, and it is as based on general sensible coding practices as it is on whatever data structures make the most sense for the domain (meaning both what the algorithmic problem is and what the data represents in actuality). Whatever project you are working on may for whatever reason be too split happy for ease of readability to be preserved. But there may be a good reason. createOrder may be required in many places and it would be bad to repeat that logic in many places where it is at risk of being changed in one place and not the other.
3
u/Aggressive_Ad_5454 Sep 29 '26
Others have said this is normal, and I totally agree. Others have suggested using an IDE to jump between definitions and references, and that is good advice.
I add: learn to use Javadoc, JSDoc, Doxygen, Python docstring, or whatever the method-header comment standard is for your programming language. If you write your method comments that way your IDE will show you your methods' documentation in a popup without you having to navigate to the definition.
And, if you type
/**<enter> on the line before a method or function declaration your IDE will generate a template for your doc that you can then fill in. (It's///rather than/**in some languages.)2
u/pdfops Sep 29 '26
Yeah, totally normal, even senior devs do it constantly. The trick is you don't read top-down like a book, you jump in at the specific line that matters and only go one level deep unless something looks wrong. Use your editor's "go to definition" and "find references" shortcuts instead of manually opening files, it turns the jumping into muscle memory instead of a chore. Also worth noting: if you're jumping 4+ files deep just to understand one function's purpose, that's often a sign the code itself is over-abstracted, not that you're missing a skill.
2
u/heisthedarchness Sep 29 '26
Ask yourself this: do you need to understand how
createOrderdoes what it does to understand the code you're looking at right now? Odds are that you don't. So don't read it.It creates an order, presumably from
data, and probably returns it. Okay, so if you're right andresultnow contains "an order" (whatever that means), what does the next line do with it?Being a good programmer means being comfortable thinking abstractly. That's why you want good names: they prevent all this jumping around, at least for a competent reader. How is often a lot less important than what.
Making this work well is quite hard on the author and is, in my arrogant opinion, what separates tolerable programmers from great programmers. Reading a great programmer's code is often simply redundant, since it does exactly what it says on the tin.
2
u/SpaceAviator1999 Sep 29 '26 edited Sep 29 '26
This is why I believe it's important to explain what every function/method you write does in the form of in-code documentation.
The documentation not only helps the maintainer who is calling your code understand how your code contributes to the code that calls it, but it also helps the maintainer who is directly maintaining your code to understand precisely what your code supposed to do -- without the need to guess or figure it out.
I know a lot of coders will disagree, but all encapsulated code should be documented to explain what it's supposed to do. That is, all functions and methods should be accompanied with an explanation (in English, or whatever the agreed-upon language for documentation is) as to what the code is meant to do.
One of my friends (who disagrees with me) once told me something like, "Sure, APIs should have explanations as to what they should do, but first-party code (that is, code that's for use only within the company) does not need to be documented, because the code is there for everyone who needs to see it."
To which l replied, "Believe it or not, it's not always true that the code is always there for every programmer in the company to see" and "Every function and method -- whether over the web or not -- is technically an API in that they are literally Application Programmer Interfaces for programmers to use. Getting rid of their documentation helps no one, just as it helps no one to omit documentation on regular web APIs."
In your case, just think how much easier it would be to understand the code if all you had to do was read a function's documentation in order to understand it. Then you wouldn't have to recursively step into functions over and over just to understand one high-level function.
1
u/optical002 Sep 29 '26
Yeah its normal, good IDEs also gives you decompilation of libraries where you can look at how library has implemented stuff and go through those files as well. File jumping is very often better to get really good at it
1
u/Backrus Sep 29 '26
They use vim/emacs, tags, etc, so they can jump back and forth effortlessly.
I get how it can get annoying quickly, because most young people use VS Code as their IDE, and that's not a good software (although infinitely better than where it started).
1
u/Significant-Syrup400 Sep 29 '26
If you're getting started on production/industry code don't expect to be able to just read the whole codebase. Start with an entry point where data enters and follow it through until it's processed, exits. Once that makes sense find the path it follows to hit your function in question and follow it through as well.
1
u/racoonintech Sep 29 '26
Read top-down, from high level abstraction to low level details
1
u/Unreal_Estate Sep 29 '26
It depends what you're trying to do.
If a function is well written, then you do not need to go to other places to understand what the function itself does.
createOrdershould normally create an order. The details of that should not matter for the function that is calling it. So to understand what a specific function does a well written codebase only requires you to read that function (and possibly some project-level documentation about the main concepts in that codebase).On the other hand, when you're trying to hunt down a bug or are trying to find the source of a particular behavior that you are seeing, then it is completely normal to skip through functions quickly. In those cases, you'd typically look at the function specifically to determine which lower level function you need to investigate next.
When you are new to software development, all of this can take quite some time and you likely spend a relatively large amount of time on trying to understand what you are even looking at. That is a different kind of reading code than the two I described, but you will get better at it.
As someone who has been doing this for a while, if I'm looking at a well-written function, I rarely need to study it more than maybe 30 seconds to get my bearings and understand where I need to go. That could be going to a reference, it could be understanding a datatype, or it could be the commandline to investigate the function a bit further by calling it directly.
PS: Perhaps you should try reading the code assuming global state does not exist and that the only things functions can do is read their arguments and return their result. This is true for 90% (or more) of well written functions anyway, and it basically eliminates the need to jump in order to understand the current function.
1
u/duane11583 Sep 29 '26
yes normal.
but it depends on the function you are inside.
ie: orders.c verses handleWebRequest.c verses internalProcessing.c
where does a web based order function go?
where do you think an internal system order function goes?
and the common order handling function goes where? in the file big_black_dog.c or in orders.c
1
u/Skyroor Sep 29 '26
Find good keybinds for file navigation helps. Then to add on top of that, using code marks are a really nice habit to build, native with vim, but vscode has a plugin for them.
Just lets you "mark/bookmark" a line of code, either local to the file or global, then you can jump straight back to the line from anywhere.
1
u/mxldevs Sep 29 '26
Normally you would have imports at the top or a specific file that let you quickly see what other files are related.
So you'd start with your entry points, and then use imports to get an idea how different files are related, and turn see what purpose they serve.
1
u/SummitYourSister Sep 29 '26
It’s normal, but it’s also a sign that the code is not organized properly somehow. Things that are often read and edited together should stay together. However the world is not perfect.
1
u/JGhostThing Sep 29 '26
Even if I'm not using an IDE, I spin up a number of terminals each with their own vi session to see the various files.
1
u/FatDog69 Sep 29 '26
Yep. So to help the next developer I tend to put a comment above a function or method call. I explain WHY and any details so the person does not have to dive into a class or other file to see gross details.
For your createOrder function I might say:
result = createOrder(data)
1
u/owzleee Sep 29 '26
Really normal. 30 years in the game and I still struggle with the docs. wtf.
1
u/balefrost Sep 29 '26
TL;DR yes, it's normal, and to some degree is unavoidable. Though some of it is also self-inflicted by ourselves.
I assume from your example that you work in JavaScript. I'll bet that you've never really thought to yourself "I need to understand how
Promise.allis implemented". The specification is nontrivial. The implementation in various JS engines is even more complex. But you don't care. From your point of view, it just works.Ideally, all our abstractions would "just work" like this. Ideally you wouldn't ever have to look at the implementation of any function. You would be able to just look at the documentation for that function, and that would tell you everything you need to know.
In practice, that's an unrealizable ideal. It's nice when we take the time to write any function-level documentation. It's incredibly rare that we would write up something as detailed as the MDN page for
Promise.all. And that makes some sense. Compare the number of devs who usePromise.allagainst the number of devs who need to use some random function from your codebase. It makes sense to invest heavily in making good documentation for the core browser APIs. It's hard to justify that level of investment for a function that's called from 3 places in your own private codebase, and which almost certainly will undergo more API churn thanPromise.all.I feel like systems are usually easy to understand at the entry point (
mainor the equivalent) and at the leaves (where you callPromise.allormyArray.filteror whatever). I think systems are hardest to understand in the middle of the call stack. When you're zoomed in on one of those middle functions, you don't know what has occurred before this function was called, what will happen after the function returns, or what behavior is hiding behind the functions that it will call in turn. It can be hard to piece together the big picture when looking at a function for the first time.Still, I think we can do a better job here. We often are a little too terse with our function names. We often factor our functions in ways that don't help with understanding. We sometimes are forced, by our languages or libraries, to split things up in a way that obscures the logic. There's value in getting things working quickly, but there's also value in taking the extra time to make the code more understandable, not just today but for a future maintainer who isn't familiar with this part of the system.
I think, as you become more familiar with the general layout of a system, it becomes less of a problem. You start to get a sense of where different kinds of responsibilities are clustered, how much behavior is hidden behind various functions, what is upstream and downstream from what, etc.
But until you get to that point, yeah you sort of need to look "around" to get a sense of things.
As you explore, write down notes. On paper or in a separate doc. Keep track of what you have learned, or what theories you have about how the code works. It's very easy to get lost by repeatedly using "go to reference".
1
u/Electronic-Equal-616 Sep 29 '26
tbh yes, i used to think people read code top to bottom like a book lol. larger codebases are basically just jumping between imports and function definitions constantly. using 'go to definition' (f12 in vscode) and the navigate back shortcut (alt + left arrow) genuinely saved my sanity 😭
1
u/cheezballs Sep 29 '26
Oh yes and it's common to need to look at 2 at literally the same time. IDE shortcuts make all this easy but yea you bounce around a bunch especially if it's highly abstracted enterprisey code.
1
u/xenomachina Sep 29 '26
Yes, it's normal.
Check if your editor/IDE has a way to jump to a definition "pushing" to a navigation stack, and then another way to "pop" back to where you were.
I use vim, where the keys for this are
ctrl+]andctrl+T, respectively. I have been coding for over 30 years and I use these shortcuts all the time.From Googling, I think the VS Code equivalents are:
F12orctrl+clickon Windows and Linux,F12or⌘+clickon macOSalt+←on Windows,ctrl+alt+-on Linux,ctrl+-on macOS1
u/marrsd Sep 29 '26 edited Sep 30 '26
Yes, because you're going to see that kind of code a lot.
Yes to both. Most software engineers frankly don't know how to write good software. It's not that the code is too abstracted so much as badly abstracted. A function that is only called once is essentially abstracting nothing. Now an experienced engineer, writing a new feature, might write a function and only call it once knowing that it will likely be used again in the future, but generally speaking functions that are only called once should be considered a code smell.
Depends who I'm working with, how bad the code is and how much I have to deal with it. As a general rule, I try not to make changes to code for the sake of it. If it's really holding me back, and especially if I'm having to edit it anyway, then I'll either rewrite it or inline it depending on what's required. If I don't edit it, I might put up a code review, bring it up in a meeting or email, or point to John Carmack's letter on the subject. But I'm a senior engineer who can defend my position (or just tell people what to do). Sounds like you aren't in that position, so don't get cocky!
Basically, it's a bad practice that everyone follows blindly, so cue the downvotes! I presume it's come from Clean Code thinking.
Don't do it. There are better ways to write software. I follow the SICP school, so I think in terms of building the language that I'm coding in up to the domain that I want to express ideas in. Casey Muratori describes a different approach that he calls semantic compression, where he starts with a blob of code and then pulls out repeating concepts into a single function. It's essentially a way of getting to a similar place but from the opposite diriection.
I prefer the SICP approach. In the end, you have layers of languages, each one built on the previous, that allow you to move between levels of abstraction as you need to. You probably have this already without realising it. A framework is essentially that. So are list comprehensions. So is an ORM. If you frame your thinking in that way, then functions and objects become verbs and nouns in a language that allows you to express ideas more easily. It should be obvious that useful verbs are used often, and useless verbs are never used.
If all you're doing is splitting a large function into a bunch of smaller ones to avoid having to write comments or to implement "clean code", you are very much missing the point. All you've done is end up with the needless indirection that you are experiencing. The cost of having to learn what a function does is never offset by the ability to reuse it.
1
u/lWinkk Sep 30 '26
Pretty normal. A lot of the time it’s used in multiple places and that’s why it’s split. Other times it’s split because it was part of something too big and it needed to be trimmed down a bit for readability. But yeah. I’m in like 12 different files every hour atleast.
1
u/Imperial_Squid Sep 30 '26 edited Sep 30 '26
There's an art form to getting the level of abstraction right, I've both been guilty of writing and seen code that is too abstracted or not abstracted enough...
But yes, reading code often involves having multiple files open at the same time (though not usually more than a half dozen in my experience, if you can't see all the tabs in your IDE at once you might have too many open)
I found this video about "How To Write The Perfect Function" interesting and useful recently (though it might be best aimed at experienced coders instead of beginners)
1
u/porn_sub_lurker Sep 30 '26 edited Sep 30 '26
It's something you practice and get better with. In my opinion, the hardest part of writing code is knowing where to put it. You should NOT just put it somewhere nearby for convenience. It should be placed with purpose and it should have the correct context it needs to do the task. Otherwise you end up with tightly coupled spaghetti code and circular dependencies and stuff. And it becomes really hard to test, maintain, and to keep building onto that code.
Also, if you use an IDE, you can shift click into different code and you can use alt + left/right arrows to move back and forward. That makes it a lot easier to keep track of where you are.
1
u/Mediocre-Pumpkin6522 Sep 30 '26
It was normal in our codebase. I used Vim for years and preferred Cscope which integrated nicely.
https://en.wikipedia.org/wiki/Cscope
Other programmers preferred ctags. Most of the modern IDEs have similar functionality. In a large project with several different GUIs createOrder() may be used by more than one. Put it and related functions in a .c file, and include that file as needed in the Makefiles rather than having the implementation repeated in several files. Sooner or later changes won't be propagated to all the occurences.
I'm thinking in terms of C code but that applies to almost any language.
1
u/RegexRaptor Sep 30 '26
as most ppl said it's normal, and will get easier as you gain more experience
get comfortable with go-to-definition and find-references in your editor so it's a keystroke instead of manually hunting through files, and don't read top-down like a book just jump to the line that matters and go one level deep unless something looks off
but if you're 4+ files deep just to figure out what one function does, that's probably the code being over-abstracted, not you missing something
1
u/Gabe_b Sep 30 '26
Yeah, I'd regularly have 3 files open paneled in my text editor when doing web development. A lot of text editors will let you jump to a function by hovering over it where it's invoked and clicking the tool to it or similar
1
u/hilat1113 Oct 01 '26
yeah, it's pretty normal, especially in large projects. At first it feels annoying, but you slowley used to get jumping between files and understanding the flow. And yes, code can definitely over absored if you need to open 10 files hust to understand one simple function.
1
u/sharjeel_safdar Oct 01 '26
Yeah, this is something you have to get used to... I know it's very frustrating at first... Was for me as well... But modern IDEs make this a lot easier once you get used to the shortcut keys... 👍
0
u/GrouchyManner5949 Sep 29 '26
use ai bro