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. Lines of code

Lines of code

Scheduled Pinned Locked Moved The Lounge
question
33 Posts 20 Posters 3 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.
  • B Bart

    A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

    bart

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

    Hah, found this C#, Visual Basic and C++ .NET Line Count Utility[^]

    bart

    1 Reply Last reply
    0
    • B Bart

      A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

      bart

      M Offline
      M Offline
      Member 96
      wrote on last edited by
      #12

      I remember caring about that waaaay back in the day. These days it's pretty irrelevant with all the template generated lines etc. The app I'm working on today has over 20 projects in the solution. Lines of code must be zillions by now. ;)


      "Creating your own blog is about as easy as creating your own urine, and you're about as likely to find someone else interested in it." -- Lore Sjöberg

      1 Reply Last reply
      0
      • B Bart

        A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

        bart

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

        What's a line of code? I can break a statement onto many lines, and I can put many statements on one line. A C/C++/C# source file may contain no linefeeds at all (only pre-processor directives require them). Counting statements might make some sense, but even that is fairly pointless. Just say "42".

        1 Reply Last reply
        0
        • B Bart

          A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

          bart

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

          Why should you even care, you will be responsible for it no matter where it comes from. What if you wrote the code generator, does that get special status. Talk about stupid questions! And no I have no idea and could care even less.

          B 1 Reply Last reply
          0
          • M Mycroft Holmes

            Why should you even care, you will be responsible for it no matter where it comes from. What if you wrote the code generator, does that get special status. Talk about stupid questions! And no I have no idea and could care even less.

            B Offline
            B Offline
            Bart
            wrote on last edited by
            #15

            Hold said horse. He was only a mate and just asked out of curiosity. He was wondering how I understood all that foreign tongue stuff. He is probably a bit like DD's boss. (No, he didnt touch my PC)

            bart

            B M 2 Replies Last reply
            0
            • B Bart

              A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

              bart

              J Offline
              J Offline
              jesarg
              wrote on last edited by
              #16

              You could always write a utility to count semi-colons in all files in a directory to give you a rough estimate.

              P 1 Reply Last reply
              0
              • B Bart

                OK, so how many lines is your current project? I bet you are like me AND YOU DONT KNOW!

                bart

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #17

                Use a regular expression file search tool to count the number of semicolons in your project, and exclude the files that are designer created. First, copy all the files to a temp directory. Then search that directory for all the designer files; delete those files. Searching for the number of semicolons should then give you a pretty accurate estimate of number of lines. If you want actual lines rather than lines of code, you could use the same regular expression approach to count the number of line endings. Actually, that approach wouldn't work with me. Most of my code is XAML (hand typed, not designer generated), so there are no semicolons to count. An alternative approach would be to decide how many characters an average line takes up (say, 80), then divide the file size by that number to get the approximate number of lines. Might have to use half that number if the text uses one of those "double wide" character encodings.

                Visual Studio is an excellent GUIIDE.

                1 Reply Last reply
                0
                • B Bart

                  A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

                  bart

                  S Offline
                  S Offline
                  Steve Mayfield
                  wrote on last edited by
                  #18

                  Software metrics tools for C/C++ [^]

                  Steve _________________ I C(++) therefore I am

                  1 Reply Last reply
                  0
                  • B Bart

                    Hold said horse. He was only a mate and just asked out of curiosity. He was wondering how I understood all that foreign tongue stuff. He is probably a bit like DD's boss. (No, he didnt touch my PC)

                    bart

                    B Offline
                    B Offline
                    bryce
                    wrote on last edited by
                    #19

                    fair enough - you do have to be careful about what you mate gets to touch *grin* Bryce

                    MCAD --- To paraphrase Fred Dagg - the views expressed in this post are bloody good ones. --
                    Publitor, making Pubmed easy. http://www.sohocode.com/publitor

                    Our kids books :The Snot Goblin, and Book 2 - the Snotgoblin and Fluff

                    1 Reply Last reply
                    0
                    • B Bart

                      Hold said horse. He was only a mate and just asked out of curiosity. He was wondering how I understood all that foreign tongue stuff. He is probably a bit like DD's boss. (No, he didnt touch my PC)

                      bart

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

                      In which case he owes you a beer while you describe what you do, I'm betting you can drag it out for a couple of beer but you are going to have to watch out for that glazed look that come into their eyes.

                      1 Reply Last reply
                      0
                      • B Bart

                        OK, so how many lines is your current project? I bet you are like me AND YOU DONT KNOW!

                        bart

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #21

                        There are plenty of free VS add ins that generate that number for you.

                        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                        1 Reply Last reply
                        0
                        • J jesarg

                          You could always write a utility to count semi-colons in all files in a directory to give you a rough estimate.

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

                          int x ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                          x = 42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                          Y A 2 Replies Last reply
                          0
                          • P PIEBALDconsult

                            int x ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                            x = 42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                            Y Offline
                            Y Offline
                            Yusuf
                            wrote on last edited by
                            #23

                            it is still 42 :^)

                            Yusuf May I help you?

                            1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              int x ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                              x = 42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                              A Offline
                              A Offline
                              AspDotNetDev
                              wrote on last edited by
                              #24

                              I would say semicolon counting is still more accurate for counting lines of code than line endings. And like others have said, counting the number of lines is no measure of quality (the above code being of crap quality, but a large number of lines). Or the two method could be combined into something like this:

                              int numberOfLines = Regex.Matches(@"\;( |\t)*(\r|\n|\\\\|\\\*)", fileText).Count;

                              But then some trickster could get you with this:

                              public void DoIt()
                              {
                              int x
                              = 5; int
                              y = 10;}

                              However, if the guy just wants to tell his friend how much code he wrote, this method (or similar approximations) should work fine.

                              Visual Studio is an excellent GUIIDE.

                              P 2 Replies Last reply
                              0
                              • A AspDotNetDev

                                I would say semicolon counting is still more accurate for counting lines of code than line endings. And like others have said, counting the number of lines is no measure of quality (the above code being of crap quality, but a large number of lines). Or the two method could be combined into something like this:

                                int numberOfLines = Regex.Matches(@"\;( |\t)*(\r|\n|\\\\|\\\*)", fileText).Count;

                                But then some trickster could get you with this:

                                public void DoIt()
                                {
                                int x
                                = 5; int
                                y = 10;}

                                However, if the guy just wants to tell his friend how much code he wrote, this method (or similar approximations) should work fine.

                                Visual Studio is an excellent GUIIDE.

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

                                Does that handle for loops?

                                for
                                (
                                int i = 0 ;
                                i < 10 ;
                                i++
                                )
                                {
                                ...
                                }

                                1 Reply Last reply
                                0
                                • B Bart

                                  A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

                                  bart

                                  A Offline
                                  A Offline
                                  alex barylski
                                  wrote on last edited by
                                  #26

                                  Run a metrics calcuation tool before you write a single line of code. Whenever you generate code automagically using some tool, run it again before and after. Calculate your averages, it's not that hard. Google SLOCCount it's a linux tool that calculates SLOC for many languages, I use t all the time :) Cheers, Alex

                                  1 Reply Last reply
                                  0
                                  • B Bart

                                    A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

                                    bart

                                    M Offline
                                    M Offline
                                    Mark_Wallace
                                    wrote on last edited by
                                    #27

                                    Just reply "I wrote all the good ones, and tool who sits by the window wrote the rest".

                                    I wanna be a eunuchs developer! Pass me a bread knife!

                                    1 Reply Last reply
                                    0
                                    • B Bart

                                      OK, so how many lines is your current project? I bet you are like me AND YOU DONT KNOW!

                                      bart

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

                                      I don't know; I also don't care. "Lines of code" is a meaningless statistic, and has been since Cobol and Fortran stopped being the standard languages. Is a line with just an "{" or "}" a "line of code"? Or is

                                          MySqlCommand cmd = new MySqlCommand("UPDATE " + TableNames.my\_RoleAndPerformance.ToString() +
                                                                              " SET role=@R, dateNextChangeRole=@NCR, data=@D, ValidationCode=@VC" +
                                                                              " WHERE UserId = @ID");
                                          cmd.Parameters.AddWithValue("@R", role);
                                          cmd.Parameters.AddWithValue("@NCR", dateNextChange);
                                          cmd.Parameters.AddWithValue("@D", data);
                                          cmd.Parameters.AddWithValue("@VC", validationCode);
                                          cmd.Parameters.AddWithValue("@ID", userId);
                                      

                                      One "line of code", since it will not work without the entire sequence? Forget "lines of code", think "functional blocks", think "tested and peer reviewed", think deadlines, bug count, any performance measure that actually means something!

                                      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

                                      "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

                                      1 Reply Last reply
                                      0
                                      • B Bart

                                        A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

                                        bart

                                        S Offline
                                        S Offline
                                        Stuart Dootson
                                        wrote on last edited by
                                        #29

                                        As I program in C++ generally, I'll just use this command at the root of my source tree:

                                        ack --cpp -c ; | wc -l

                                        This counts all semi-colons, which is a reasonable approximation for the total lines in the project. I never differentiate between auto-generated/me-generated lines.

                                        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                                        1 Reply Last reply
                                        0
                                        • B Bart

                                          A friend watched me writing code for a project asked: So, how many lines of code is that? How many did you write and how many were generated by a tool? I didnt know..... How can I find out?

                                          bart

                                          C Offline
                                          C Offline
                                          Chris Quinn
                                          wrote on last edited by
                                          #30

                                          >>> how many were generated by a tool? For some of the people I work with, this is 100%!

                                          ==================================== Transvestites - Roberts in Disguise! ====================================

                                          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