B4A

miércoles, abril 07, 2010

Pharo/Squeak Tips - Counting lines of code

I will try to publish here some tips I found useful and that may be of help to others. Of course, some of them, will be very basic, but still may be useful for newbies.

Said that, a thing that I like to know is the approximate lines of code of my projects, the lines of code I write in a period of time, etc. 

To know that you can use the following code:

Being, in this case, 'G1' the two letters that identify all the classes of the project I want to measure.

The output looks like:


Ok, now you can measure how many lines of Smalltalk code you write at day! :)

7 comentarios:

Peter William Lount dijo...

Thanks Germán, I typed in your example and then created a class for it too. Plus I hooked in my SortCriteria objects so that I can see the results sorted descending by number of lines, then by class name, then by instance class/meta class. Oh I added in code that also counts each classes class. Made some changes so that the whole thing starts with Object rather than Class so that both instance methods and class methods are counted.

My aims library for zokutalk is just a hair under 100,000 lines so far. Lots more code to find from older images and to write but that is an interesting metric. I'll add it to my ProjectManager class that I use to manage my source code across images and dialects of smalltalk.

Thanks again.

Peter William Lount, editor smalltalk.org

Unknown dijo...

Hi Peter:

Thanks you very much by read my blog. I'm really glad that you liked my little code :)

Even when in our objects world the lines of codes are not a very important metric, anyway I like to have a clue about the size of my projects and the work I do in some period of time.

And the details and modifications you mention (using objects and sorting and having counters for methods (instance and class)) are very interesting also.

Thanks by read my blog!

Peter William Lount dijo...

Your welcome Germán. I found it interesting tinkering for couple of hours. Oh, might the number of message sends in a method be a better count than lines of code?

Unknown dijo...

Certainly is a possibility. Interesting, it's possible that measuring the message sends show better the amount of the work done....I must think about.

Thanks!

Peter William Lount dijo...

Yeah, measuring message sends is a better approach since in Smalltalk a statement can be spread over many text lines depending on how it's formatted. I suppose that's true for most computer languages.

In any event, the number of message sends, variable accesses and assignments in a method show a better measure of it's size, and it's complexity.

However, that said, clearly work can be done that actually shrinks the number of lines/message sends in a class yet the system is most certainly improved. So caution on how these metrics are used is advised.

LOC, lines of code, is primarily useful for new systems, not systems that are evolving or under maintenance.

Cheers, peter.

Mariano Martínez Peck dijo...

German, did you see: http://www.squeaksource.com/WebCodeStats.html

It is not really coupled with Web. In less than 5 minutes I have stats for my project ;)

Unknown dijo...

Hi Mariano:

Not tried it yet.

Thanks by the comment!