Lines of code
-
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.
-
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
-
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.
-
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
Software metrics tools for C/C++ [^]
Steve _________________ I C(++) therefore I am
-
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
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/publitorOur kids books :The Snot Goblin, and Book 2 - the Snotgoblin and Fluff
-
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
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.
-
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.
-
You could always write a utility to count semi-colons in all files in a directory to give you a rough estimate.
int x ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
x = 42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -
int x ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
x = 42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;it is still 42 :^)
Yusuf May I help you?
-
int x ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
x = 42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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.
-
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.
Does that handle
for
loops?for
(
int i = 0 ;
i < 10 ;
i++
)
{
...
} -
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
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
-
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
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!
-
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
-
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
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
-
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
>>> how many were generated by a tool? For some of the people I work with, this is 100%!
==================================== Transvestites - Roberts in Disguise! ====================================
-
283,000 at the last formal build. I know because we track a variety of project metrics on each build using the (free) SourceMonitor[^] tool. I'm more interested in average cyclomatic complexity has gone down (which is good as it means that the code is getting less crufty) or up (which implies that some of the changes in the build are more complex than they need to be) rather than LOC, but we get that as well.
Anna :rose: Having a bad bug day? Tech Blog | Anna's Place | Tears and Laughter "If mushy peas are the food of the devil, the stotty cake is the frisbee of God"
-
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.
Oh, and semi-colons in verbatim strings:
string sql =
@"
SELECT COUNT(*) FROM table1 ;
SELECT COUNT(*) FROM table2
" ;