Practices for navigating and changing “long” code files?

Many a times I have to deal with code files which are quite long – about 5 screen pages at the minimum. Almost always there is something towards the top/bottom that I need to refer when I’m at the bottom/top (respectively). It’s a mammoth overhead to constantly scroll back-n-forth between the file parts.

It’s a cognitive overload to just remember each and everything throughout the file and it’s quite necessary to be able to refer to parts of the file.

Yes, the Outline view in some editors like Eclipse/NetBeans helps, but sometimes they will work well only for parts recognizable by that parser. Sometimes outline views don’t show up e.g. when coding in CoffeeScript or JavaScript using closures/namespaced functions etc. The fallback is then just manual scroll overhead.

So as programmers what are some of the techniques/practices that can be employed to reduce this ridiculous overhead?

Yes, I can shorten the files, but specifically javascript libraries like Backbone.js etc. are all as one file since you really can’t split them into multiple file due to lack of Java-like packages. So under the constraints of inability of splitting a file and the outline views not working, what are some of the techniques I can use to navigate through long source files? I work a lot on Eclipse/Netbeans and Aptana and sometimes Vi (but seldom in production environments). It’d be great to be able to split a window into two and see the same file on one side and code in the other. Not doable with Eclipse/NB/Aptana IMO. Vi, yes but can’t use it all the time.

PS: As of now, I split the file among multiple editors e.g. Eclipse and Aptana. It’d be great to have it at one place, but is that the best that we can do? 🙂

UPDATE – Seems Eclipse has way for doing this and can be found here

7

So as programmers what are some of the techniques/practices that can be employed to reduce this ridiculous overhead?

under the constraints of inability of splitting a file and the outline views not working, what are some of the techniques I can use to navigate through long source files?

Open the file in several different editor windows (or different editors) – have each section of interest in a different window. If you, like many developers, have two or more monitors, you can put each window on a different monitor for reference.

I don’t know about Eclipse/NB/Apatana, but Visual Studio has a split bar – this allows you to see several different portions of a file in one window. Perhaps your editor of choice has this feature as well.

1

The most important thing to reduce this problem is to provide good abstractions for your methods. If you need to look at what Foo does everytime, then that is a good reason to refactor the code, to either rename the method, or break up the method into different ones. (Breaking up is useful when you have a complex control flow based on the input)

If you don’t want to refactor, typically in visual studio I use goto definition and the back button on my mouse to navigate around to the various points. You might be able to use similar shortcuts in your IDE to avoid having to manually look around so much.

4

Here’s the rules which allows keeping files of 10kloc in size with 100 classes in each file in c++ code:

  1. Use emacs + esc-< + C-s for going to beginning of file and then searching a class by search words “class MyClass” and “::mymemberfunction”. It requires remembering the name of the class or member function you want to find.
  2. notepad has the same feature in C-f
  3. other ides probably have ability to find text from single file which you have already open; going to beginning of file is more difficult to find…

I develop in Object Pascal/Delphi and once I came up with an idea (I called it Wident) for simplifying navigation in the long files. Basically it’s about having a quick two-direction search of the identifiers at caret (I used Ctrl-Alt-[arrows]). You press for example Ctrl-Alt-Down, the tool detects the keyword at the caret pos and goes to the next mentioning of the keyword. Since after the jump your caret is placed at the same word only at different position, the next pressing will jump to the next reference (Ctrl-Alt is held so you just repeat pressing Down key). Although at this point you can be far away from your starting point, you can return to it easily. The caret is still at the name, so Ctrl-Alt-Up pressed twice will do the magic.

And this is just an example. Actually it’s like quickly creating new dimensions in navigation while keeping full control of where you are. This works because the names of variables, functions, types and their references is what connects pieces of software semantically.

Although I use the tool developed for Delphi IDE, in other editors similar functionality can be implemented just by assigning new keys to the corresponding functions. For example, in notepad++ they are “Find (Volatile) Next” and “Find (Volatile) Previous”.

Personally I rely on my memory. I remember the scroll bar position where I am looking at some important code. Ofcourse, you can only scroll to approximate location, but in most cases a PgUp / PgDown gets you right there. After a while, it becomes a habit.

You can easily remember about 4-5 scroll locations for a file. It would work great for files upto apprx. 2-3kloc. After that, the scroll bar would reach its minimum size and start losing its precision.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật