Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Largest Code File?

Largest Code File?

Scheduled Pinned Locked Moved The Lounge
question
35 Posts 27 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M michaelbarb

    I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

    So many years of programming I have forgotten more languages than I know.

    K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #2

    michaelbarb wrote:

    I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file?

    By who?? Anytime you put a limit on th enumber of lines, you're asking for trouble. What if the limit's 1000 lines and you need to insert 3 more lines to fix something? The size of the code file is irrelevant. You can have a large file, well written and maintained, that works fine. You could also have a small file with 20 lines that's crap and needs to be thrown away. From a UI perspective, it does sound too busy. From that angle, I'd consider redesigning it. This whole thing smells of an old, legacy code app that can't/won't be refactored from some reason.

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    M 1 Reply Last reply
    0
    • K Kevin Marois

      michaelbarb wrote:

      I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file?

      By who?? Anytime you put a limit on th enumber of lines, you're asking for trouble. What if the limit's 1000 lines and you need to insert 3 more lines to fix something? The size of the code file is irrelevant. You can have a large file, well written and maintained, that works fine. You could also have a small file with 20 lines that's crap and needs to be thrown away. From a UI perspective, it does sound too busy. From that angle, I'd consider redesigning it. This whole thing smells of an old, legacy code app that can't/won't be refactored from some reason.

      If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

      M Offline
      M Offline
      michaelbarb
      wrote on last edited by
      #3

      These were rules of thumb and not intended to be hard fast limits. More like best practice rules where there are all kinds of reasons to break them but better if you do not. It was only written a year ago.

      So many years of programming I have forgotten more languages than I know.

      1 Reply Last reply
      0
      • M michaelbarb

        I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

        So many years of programming I have forgotten more languages than I know.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #4

        As small as possible, and no smaller. Maybe the project began with .net v1 when partial classes weren't supported?

        1 Reply Last reply
        0
        • M michaelbarb

          I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

          So many years of programming I have forgotten more languages than I know.

          Sander RosselS Offline
          Sander RosselS Offline
          Sander Rossel
          wrote on last edited by
          #5

          Single responsibility principle. A class should do a single thing, meaning it has one reason to change (or something like that). I find that my classes are rarely larger than a few 100 lines. I recently wrote one of about 600 lines and it felt like an absolute beast to me. I can't really put an upper limit on lines per file, but 24,000 in a single class is WAY TOO MUCH. Period. That's just unmanageable. The tab containers, for example, should've been in their own files. You look at the solution and you see OrderForm.cs, TabControl.cs, MyTextBox.cs, OrderRepository.cs, etc. and you know what kind of work you can expect. Looking at a solution and seeing only OrderForm.cs, but with 24,000 lines tells you nothing of what is going on or where to find it.

          Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

          1 Reply Last reply
          0
          • M michaelbarb

            I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

            So many years of programming I have forgotten more languages than I know.

            R Offline
            R Offline
            raddevus
            wrote on last edited by
            #6

            You are making me feel so much better about my WinForm app. Mine does tons of stuff and I am always embarrassed about it because I know the MainForm is so large. I just checked Visual Studio and the MainForm.cs and I see that it is (only) 1356 lines of code. :rolleyes: Before I read of the 24,000 line WinForm I was very embarrassed :-O But now, I feel very good. :laugh: Now I will make an extreme statement: 24,000 lines is utterly and totally and completely ridiculous!!!! What kind of monster creates something like that. 1356 lines is quite bad enough you know. All that scrolling to the bottom. My eyes often cross. But 24,000 lines!!! X| You are correct in questioning that. My app has more than 17 other forms in it (so user can focus on one thing at at time) and a few other Dialog (forms) that are split out. I'm attempting to communicate that this is a large app that has to do a lot. it's configuration and a reporting tool (which probably should've been two tools also). The original developer surely could've broken up the large 24,000 lines a bit, and you are correct to think they could've. EDIT Also, if we calculate about 60 lines on 8.5x11 paper then the code is about 400 pages long printed out. I wonder what that app could be doing that it takes that much code? Must be amazing. Or there is a lot of code that maybe isn't needed. Very interesting. If a person typed 400 page novel in one year I'd be impressed. But wow, 400 pages of code. That's more than 1 page of code spewed every day. Impressive output! :-D

            1 Reply Last reply
            0
            • M michaelbarb

              I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

              So many years of programming I have forgotten more languages than I know.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              I have several thoughts. File length may be some sort of measure that is weakly correlated to how much of a mess the code is, but if it is used a target then it loses its value as a measure. If turning a long code file into several short ones just means introducing unnatural/forced "file breaks" (kind of like a line break but more dramatic, indeed this same principle applies to a line length limit) at random points, nothing has been gained by doing it. Cutting up a mess just results in a cut-up mess, cutting up a non-mess *creates* a mess. Long files are a bit annoying to navigate, but so is "lots of files in a project". Having closely related things spread of different files is more annoying to keep straight and navigate between and choose where to add new stuff. Having some incidental not-quite-so-closely-related things in the same file isn't really a *problem* but more like something that will trigger some people's compulsive need to organize. If a form has hundreds of controls, which I'm not saying is great to have, but *if it has*, then it's going to have a long code-behind file automatically, just to put the event handlers and basic control-related logic there. 24k lines sounds like there's a bunch of other stuff in there too that maybe could reasonably be somewhere else, maybe. But I don't know.

              1 Reply Last reply
              0
              • M michaelbarb

                I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                So many years of programming I have forgotten more languages than I know.

                R Offline
                R Offline
                Rick York
                wrote on last edited by
                #8

                I don't have any hard guidelines but I like to stay under about 20KB when possible. Sometimes it just isn't and I don't start splitting things up if I get close to that. I feel your pain though. We have a code module here that is over 2MB long and almost 90K lines. It is full of ifdefs and several large functions have three or four implementations in it with only subtle differences. We hold this up as an example of how not to do things ever and a justification for why we are trying to rewrite everything it was involved in. It is truly horrendous.

                "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

                1 Reply Last reply
                0
                • M michaelbarb

                  I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                  So many years of programming I have forgotten more languages than I know.

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #9

                  Very recently, a single-file that contained ... a guess we can call it a "data layer", with no less than 270 class-global OracleCommand definitions to start with, followed by almost 200 DataAdapters, 200 DataSets, a few Data Readers. With the useless comments that went with them, that's just the first 1,000 lines of this 16,000-line horror show. ...and that's just the "data layer". Even though data is all this one file handles, I really wouldn't call it a "data layer". It's more an amalgam of data, UI validation methods, and business rules.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

                  1 Reply Last reply
                  0
                  • M michaelbarb

                    I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                    So many years of programming I have forgotten more languages than I know.

                    K Offline
                    K Offline
                    kmoorevs
                    wrote on last edited by
                    #10

                    Back in the day, on a few occasions I exceeded the maximum size allowed by the compiler. (if I remember correctly it was 64K) :-\ :^) :^) Thank goodness for partials! :) I don't see anything wrong with large files but 24K lines seems excessive. What's the actual file size?

                    "Go forth into the source" - Neal Morse

                    enhzflepE 1 Reply Last reply
                    0
                    • M michaelbarb

                      I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                      So many years of programming I have forgotten more languages than I know.

                      B Offline
                      B Offline
                      BillWoodruff
                      wrote on last edited by
                      #11

                      Th combination of jumbo file size and gazillion controls suggests to me a programmer strategy called "lifetime employment insurance." cheers, Bill

                      «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                      M G 2 Replies Last reply
                      0
                      • M michaelbarb

                        I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                        So many years of programming I have forgotten more languages than I know.

                        M Offline
                        M Offline
                        Mycroft Holmes
                        wrote on last edited by
                        #12

                        Thank Ghu for WPF where user controls are the norm and it is trivial to use a different UC for each tab. I have not had more than a couple of hundred lines of code (and even that seems really big) in a single file for years.

                        Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

                        1 Reply Last reply
                        0
                        • M michaelbarb

                          I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                          So many years of programming I have forgotten more languages than I know.

                          M Offline
                          M Offline
                          Matthew Dennis
                          wrote on last edited by
                          #13

                          19K+ .asp file. Not .aspx, and poorly written, bad cut and paste, no comments, no documentation. I survived. I think it was around 200-300 lines of .aspx when I was done. A lot of cut and paste.

                          "Time flies like an arrow. Fruit flies like a banana."

                          1 Reply Last reply
                          0
                          • M michaelbarb

                            I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                            So many years of programming I have forgotten more languages than I know.

                            A Offline
                            A Offline
                            Amarnath S
                            wrote on last edited by
                            #14

                            I have seen legacy code with a C++ function (within a much bigger C++ code file) having about 2000 lines of code. Surprise - the first 1999 lines of this function were commented out, and the only working statement in this function was

                            return true;

                            :-D

                            1 Reply Last reply
                            0
                            • K kmoorevs

                              Back in the day, on a few occasions I exceeded the maximum size allowed by the compiler. (if I remember correctly it was 64K) :-\ :^) :^) Thank goodness for partials! :) I don't see anything wrong with large files but 24K lines seems excessive. What's the actual file size?

                              "Go forth into the source" - Neal Morse

                              enhzflepE Offline
                              enhzflepE Offline
                              enhzflep
                              wrote on last edited by
                              #15

                              I'd hoped to read a tale that resembled mine. Fortunately, you've supplied the fun by talking about a file that will just fit into a 16bit seg. I tried to save my file one day and *pow* no-go. I'd also hit the 64k limit and now had to transition to some other text editor since my syntax-highlighting one could no longer chew on what I fed it. CRAP! Bloody Notepad it is then for this x86 assembly.

                              K 1 Reply Last reply
                              0
                              • M michaelbarb

                                I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                                So many years of programming I have forgotten more languages than I know.

                                M Offline
                                M Offline
                                Member 9167057
                                wrote on last edited by
                                #16

                                Hard limits don't quite make sense. It all depends on the circumstances. Huge methods or huge units are generally a code smell, but they may make sense. That's true for pretty much every one-liner. DRY is a great principle all right, but I've had cases where repeating myself (with some changes) was better for the code base than to pipe everything through that one function. Heck, even "goto is evil", the universal truth of structured programming can be wrong in some cases. My verdict would be, while your case is likely badly maintained code, it may be, by a tiny off-chance, actually the way to go. And hard line limits shouldn't be relied upon in any circumstances.

                                1 Reply Last reply
                                0
                                • M michaelbarb

                                  I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                                  So many years of programming I have forgotten more languages than I know.

                                  OriginalGriffO Offline
                                  OriginalGriffO Offline
                                  OriginalGriff
                                  wrote on last edited by
                                  #17

                                  I don't place a "lines limit" on files - heck, I don't count lines or use line numbers anyway - but I do modularize code as much as possible: For a complex form, that means using UserControls instead of "raw controls" to group together related items and separate concerns; using TabPages to simplify displays (and each page generally contains just a Usercontrol); that kinda thing. That reduces the complexity of each individual system, adds reusability, and improves maintenance. A single large form is generally a mistake: it leads to spaghetti, and to overwhelmed users - too much data in a single place makes code very hard to use.

                                  Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                  R 1 Reply Last reply
                                  0
                                  • M michaelbarb

                                    I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                                    So many years of programming I have forgotten more languages than I know.

                                    C Offline
                                    C Offline
                                    CPallini
                                    wrote on last edited by
                                    #18

                                    Been there, done that, I feel your pain.

                                    1 Reply Last reply
                                    0
                                    • M michaelbarb

                                      I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                                      So many years of programming I have forgotten more languages than I know.

                                      D Offline
                                      D Offline
                                      dan sh
                                      wrote on last edited by
                                      #19

                                      If I am paid per file I create, then 1 line per file. If I am paid by size of file, everything in one file with a novel about my life in comments. If I am paid to write a decent piece of code, then whatever makes logical sense.

                                      "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

                                      1 Reply Last reply
                                      0
                                      • M michaelbarb

                                        I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                                        So many years of programming I have forgotten more languages than I know.

                                        S Offline
                                        S Offline
                                        Spoon Of Doom
                                        wrote on last edited by
                                        #20

                                        First place I worked at had a huge codebase, where files between 100k-200k lines were the rule, rather than the exception. And no, that's not a typo, I'm talking six figures line count - and with pretty much no comments that could take up space. This was code that, before my time there, went through at least two translations from different programming languages, done by automated tools and only touched up where it broke after that. I don't know if it was a direct consequence, but there were also a lot of constructs like

                                        function a(x, y)
                                        {
                                        return b(x, y);
                                        }

                                        function b(x, y)
                                        {
                                        return c(x, y);
                                        }

                                        function c(x, y)
                                        {
                                        return d(x, y);
                                        }

                                        function d(x, y)
                                        {
                                        //do something with x
                                        //maybe do something else with x, if the 4 lines of if conditions happens to come out true
                                        //ignore y because who needs that apparently
                                        return mysteriousStuff;
                                        }

                                        which added some, but not all of the length. There's a *lot* more there I could rant about, but I'll stick to unnecessary length. Suffice it to say, there's a reason that a) I went somewhere else and b) the company apparently doesn't exist anymore.

                                        1 Reply Last reply
                                        0
                                        • M michaelbarb

                                          I was recently given a Windows form application to work on. It was done as a single form with over 24,000 lines in the code behind file. I was taught that no file should be over 1,000 lines. Maybe 2,000 if a lot of repetition was required. What do others feel about the maximum size of a single file? Not also the single form had nested tab containers with over 600 controls on this singe form. They went as much as 5 deep. It was an abuse of the Window Forms framework in many aspects. My question is only about code file size.

                                          So many years of programming I have forgotten more languages than I know.

                                          R Offline
                                          R Offline
                                          realJSOP
                                          wrote on last edited by
                                          #21

                                          The largest file I've ever encountered was 32,000 lines. The true horror was that it was a partial class extension with nothing but ONE method that implemented a giant switch statement. Yes, a 32,000 line switch statement. 32,000 lines!

                                          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                          -----
                                          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                          -----
                                          When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                          M 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups