How do I count the total number of lines of code I wrote in VB.NET? - vb.net

I wrote an application in VB.NET and since I charge by the line, I would like to calculate how many lines I wrote. I have about 100 different Visual Basic files with my code. How do I count all the lines?

You could do a regex search for a line-break char that isn't followed by another linebreak (excluding blank lines)
Alternatively there's this app http://cloc.sourceforge.net/ (I haven't used it, I just found it)

On the command line:
(for /r %x in (*.vb) do #type "%x") | find /v /c ""

If you're using Visual Studio 2005 or earlier then there's a line counter add-in at WndTabs.com.

This can be done in PowerShell:
Example 1
Example 2
I also recommend the excellent NDepends suite as well. For one, I think it will clearly illustrate why lines of code is a very difficult thing to measure, and not necessarily a good measure of quality, or amount of work in a codebase.

Line Counter on SourceForge is a VB.NET application that counts the lines for you in your application. I was going to say you could write your own VB.NET application to do this, but luckily it has already been done. It's sweet how the Internet works that way.
Also, charging by the line? Newline must be your friend! LOL.

I really hope you're joking about charging by the line, but if not, there are a number of prepackaged free utilities and scripts that will do these sort of quick-and-dirty metrics for you, like the Line Count Utility.
P.S. Please consider a different way of charging your customers!

I have just come up to this question myself. Although this is a 10 yr old question.
Well try this, on your VB.NET, just go to ANALYZE menu and just click Calculate Code Metrics for your project and your done. :)

On a Unix-like platform:
find . -name *.vb | xargs wc -l

Related

Sizeable screenshot UI code

I am in need of someway to access the UI for the screenshot command in OSX (Cmd+Shft+4) and I would like to be able to activate the UI with a UI button that will screenshot the region selected and save it to a temp location.
Thanks in advance ;)
If there's a direct way to do this from Cocoa, maybe someone will chime in... but I doubt it exists. You can, however, get any behavior you want from the "screencapture" command line utility; it does exactly the same as Cmd-Shift-3 or 4 with a gazillion options. Just type "man screencapture" in Terminal to see all the flags.
But this would require you to run a bash script from your app. If you haven't done that before, well, google it, or check out the many threads here on SO... Opinions vary on how complicated it should be, from a one-liner call to system() to fully thread-safe error reporting NSTask and all kinds of answers in between.
I'd recommend using one of the NSTask answers which keep themselves to half a dozen lines, but YMMV.

Is there any interactive console for some strong language for everyday work of processing strings?

starting to work as an IT man lately
with some programing background,
there are so many occasions where there's a need for processing large amount of data.
mainly strings i guess..
for example:
there's 2 large sets of lines, and we need all the lines in both of the sets
replacing one or more white characters in a row, to one line break...
taking the 4th to 7th character of each line and print them in one line with comma as a delimiter
these are not the best examples, but generally any kind of parsing, manipulating and query of texts.
it's very often that the task is extremely easy in any programing language, but it is just to frustrating to open the IDE of such language....
i'm looking to some way to write code (with intelisence/autocomplete), in an easy fast window...... with simple input and output textboxes....
do you understand my need? can you think of anything that can help?
i know some of the problems can be solved using excel.. but i really prefer some good old programing.... unless someone is strongly believe i'm wrong.
if i will build something myself, there will be an option to add any amount of unlimited multiline textboxes. they'll be automatically named, although the name is changeable (the names will be the the name of the variables).
you can as well add any number of output textboxes that have names...
and you have the editor window, in which you write the procedure..... and it will have some interactive intelisence like interface...
can you see what i'm saying? do you know anything similar?
Seems like Python would be fine for this.
Has an interactive keyboard interface, quite nice abstraction facilities,
and strings as objects with good libraries for processing such strings.
It sounds like a lot of what you want can be handled with regular expressions using sed, awk, or perl in a standard console. Autocomplete will be pretty limited, but your scripts will be short anyway - to deal with your third case above, for example:
sed 's/^...\(....\).*/\1/g' < input.txt | tr "\n" ',' > output.csv
What you can do is use an interactive regex tester. There's many online like this one.
You could also look into tools like Data Wrangler from Stanford, which are designed to be more accesible but as powerful as traditional shell tools.
(Note that your first issue - intersecting sets of lines - is a bit different, and would be solved in the shell with comm. This page has a good explanation of how to use comm to perform set operations like "all the files in this file not in this file" or "only the files in this file also in this other file".)

profile an awk command?

Probably a silly question, since awk commands are usually pretty compact and do just one or two operations...
Is there a way to profile and awk command? ie. if it uses gsub, split, sorting associative arrays, is there an easy way to find out which part is bogging down the whole operation?
EDIT: Specifically I am looking for executing time for each subcommand, not how many times it was called. is this possible?
From the gawk man page:
pgawk is the profiling version of gawk. It is identical in every way
to gawk, except that programs run more slowly, and it automatically
produces an execution profile in the file awkprof.out when done. See
the --profile option, below.
so the answer would be yes if you are using the GNU implementation.
And to forstall your next question, the man page goes on to say
dgawk is an awk debugger. Instead of running the program directly, it
loads the AWK source code and then prompts for debugging commands.
Unlike gawk and pgawk, dgawk only processes AWK program source provided
with the -f option. The debugger is documented in GAWK: Effective AWK
Programming.
There's an awk implementation with a debugger similar to gdb, called dgawk.
You say you want execution time for each subcommand.
Here's how I do it, regardless of language:
Give it enough workload so it runs long enough, and time it with a watch (N seconds).
Then do it again, and while it's running, hit Ctrl-C.
Do backtrace to examine the stack, and copy that into a text editor.
Do that several times, like 10.
Any subcommand will appear on the stack for the fraction of time it spends.
So if sort is taking 50% of the time (N/2 seconds), it will appear on about 5 of those samples.
This tells you about big time-takers, not little ones. I assume you are looking for the big ones.
(Some people say this isn't accurate, which is baloney. Sure the amount of time isn't very accurate - it doesn't need to be. The accuracy you need is in location - pinpointing where the problem is, and that's what it does.)
ADDED: You can almost do this with pgawk. If you run your program in profiling mode, each time you hit Ctrl-C (or whatever) it prints the call stack to the output file. The only problem is, it prints the function names but not what lines they are called from, which you might actually need.
Here is the fine documentation about profiling gawk.
Build a profiling version of gawk for gprof, or use the kernel-based oprofile. You can then see in a lot of detail how much time is spent in various internal functions in gawk in response to your script and its data. Functions like gsub and split map to functions inside gawk.
For instance gsub and other functions are handled by the do_sub function in this source file:
http://git.savannah.gnu.org/cgit/gawk.git/tree/builtin.c
So you would look for how much time is spent in do_sub.
You want to compile and link gawk with the -pg GCC option. Successful runs of the program will then dump a profiling file gmon.out from which gprof will produce a report.
I highly recommend oprofile also, but going into it little out of scope for this answer.

MonoDevelop Code Wrapping C#

With MonoDevelop C#, when I press the Format Code button (CTRL+SHIFT+F) the IDE will take a multi line statement and create a long single one. For lambda and LINQ statements, this can be counter productive.
I am looking for a way to have the IDE format the code, but if a command is on seperate lines, to leave it on seperate lines.
I think this should get filed as a bug in MonoDevelop, not as a question on StackOverflow.

Print complete control flow through gdb including values of variables

The idea is that given a specific input to the program, somehow I want to automatically step-in through the complete program and dump its control flow along with all the data being used like classes and their variables. Is their a straightforward way to do this? Or can this be done by some scripting over gdb or does it require modification in gdb?
Ok the reason for this question is because of an idea regarding a debugging tool. What it does is this. Given two different inputs to a program, one causing an incorrect output and the other a correct one, it will tell what part of the control flow differ for them.
So What I think will be needed is a complete dump of these 2 control flows going into a diff engine. And if the two inputs are following similar control flows then their diff would (in many cases) give a good idea about why the bug exist.
This can be made into a very engaging tool with many features build on top of this.
Tell us a little more about the environment. dtrace, for example, will do a marvelous job of this in Solaris or Leopard. gprof is another possibility.
A bumpo version of this could be done with yes(1), or expect(1).
If you want to get fancy, GDB can be scripted with Python in some versions.
What you are describing sounds a bit like gdb's "tracepoint debugging".
See gdb's internal help "help tracepoint". You can also see a whitepaper
here: http://sourceware.org/gdb/talks/esc-west-1999/
Unfortunately, this functionality is not currently implemented for
native debugging, but I believe that CodeSourcery is doing some work
on it.
Check this out, unlike Coverity, Fenris is free and widly used..
How to print the next N executed lines automatically in GDB?