4 ms·
I do not mean to detract from the author's work in any way, but how does one maintain a 2180 line file easily? I find these to be very difficult to grep and gro
by kaladin-jasnah 4y ago
I do not mean to detract from the author's work in any way, but how does one maintain a 2180 line file easily? I find these to be very difficult to grep and grok, even if I am the author of the entire file.
- signa11 4y ago''' ... but how does one maintain a 2180 line file easily? I find these to be very difficult to grep and grok, even if I am the author of the entire file. ''' not sure about others, but i am using emacs with various tools f.e. for c++ these days, clangd as lsp-server, for c (long time ago) it was mostly cscope (via xcscope.el iirc) etc. etc.
- rileymat2 4y agoWhen I have a large file, using multiple panes on the same file was a big step forward. It took me far longer than it should have to realize that. Edit: Although 2k lines in file does not quite qualify as large in a lot of the projects. (Not that I like it, I prefer to break them up)
- signaru 4y agoWhen it can't be avoided there were (rare) times that I used #includes to split what would have been one long source file into multiple files. (2k lines is still within my 1 file threshold, but I generally aim for less than 1k lines). Interestingly, C# has partial classes which I have also rarely manually used (automatically generated for forms).
- pjmlp 4y agoNot only forms, nowadays it gets plenty of use via Roslyn code generators.
- pipeline_peak 4y agoThe IDE component that displays the project hierarchy is necessary at this level. Visual studio displays all methods of all classes in the current file with combo boxes making it a lot easier to navigate.
- kaladin-jasnah 4y agoOh, this is a great idea! I have to look into adding this to Emacs.
- Jorengarenar 4y agoNot necessary to use IDE either, there is e.g. Tagbar plugin for Vim
- dataflow 4y agoI was working on a 1.7k LOC file as I read your comment. To be honest I'm not sure I understand the question (how would splitting the file into two change anything in your view?), but one thing that I find helpful in general is my editor's ability to collapse method/class/etc. definitions. That lets me work on the function I want without being distracted by other definitions. Perhaps that's the answer to your question? But that's useful at 200 lines too, not just 2000 lines.
- sakras 4y agoHonestly, 2200 LOC is really not very much. I’ve dealt with 15 kLOC source files before, and have seen upwards of 30 before. I don’t think breaking it up would add much in the way of clarity given the volume of code, at that point splitting it up is just about optimizing compile times. In regards for how to grok and grep code like that, it’s just a skill like any other. I got very good at reading code and forming a mental model of it.
- flohofwoe 4y agoModern text editors and IDEs have plenty of features to better find your way around in large source files. One objective advantage of putting the entire implementation code of a C or C++ library into one source file is that you can entirely get rid of private interface headers (also, as other have said, 2kloc in one file isn't really all that much).
- maxnoe 4y agoThe simulation code we use is a 88kLOC Fortran77 file which is in continuous development since the eighties. And that's just the main file, it uses several libraries for lower level operations.