Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Program Announcements / Line Counter - a personal code helper for your DBP project

Author
Message
Code Dragon
17
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 14th Feb 2007 14:10 Edited at: 16th Feb 2007 17:33
Need help organizing your code? Then this is your lucky day!

This handy program reads your DBP project and gives you a nice code report. It tells you how many lines of code you have - physical and logical. It also tells you how many of them are remarks and blank spaces. It also shows how many functions and source files you have. It even finds the number of lines of code in each individual function and recommends the biggest and most obfuscated ones for refactoring. If that isn't enough, it even detects how obfuscated a project is in terms of spagetti points.

To use it just drag and drop your dbpro file on the exe of this program:



I highly recommend making a new DBP project just for this because you'll need the exe after its compiled. Please compile this in hidden mode. This is most compatible with CodeSurge, but I'm working on making it work with any IDE though. If it doesn't run when you drag and drop you may need to recompile your project - it needs the _Temp.dbsource file.

With simply dragging and dropping the dbpro file onto the exe, the program gave itself a code report:



Tips for refactoring functions

Here's some tips on getting less spagetti points.

Sequental Operations

If you have a function with lots of independent operations, put each operation in a seperate function and call them from the original.

This code (Where a b c and d are several lines of code)



can be turned into this:




Pipelines

If you have a function where one operation is the input to the next, put them all in separate functions and use parameters and return values.

This code (Where a b c and d are several lines of code)



can be turned into this:



Big nests (not the bird kind)

If you have a function that has control logic nesting so deeply you can't even count the number of indentations, take the inner loops and pull them out in a separate function.

This code (Where a b c are loops and d is several lines of code)



can be turned into this:



Please post how many spagetti points your project earns, we need to know how many points the average project is so we have something to compare the points with. Good luck de-obfuscating!

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Feb 2007 14:46
How about adding a few debug tools too.

For example, auto-indenting and nest error finding?

Often I accidentally delete an Endif or something, and debugging that can take ages - but if something told you what nest level each line is in, and alerted you when it thinks somethings wrong. That feature would save me (and no doubt a few folk) some serious headaches.

''Stick that in your text and scroll it!.''
tiresius
21
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 14th Feb 2007 18:07 Edited at: 14th Feb 2007 18:14
It doesn't work for me, it couldn't find the DBPRO file or the _Temp.dbsource. Even with itself using codesurge. I dunno. I hacked it though to be specific to my project. Here are the results.



Oh by the way, it is spelled spaghetti.


I have way more comments than listed, so a couple suggestions:
1. Have it count remstart and remend
2. Have it count comments that are at the end of code lines too or separated by ":"

I'm not a real programmer but I play one with DBPro!
Code Dragon
17
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 14th Feb 2007 19:09
Do you have the dbpro file and _Temp.dbsource in the same folder? I don't see why it wouldn't find the dbpro file as long as you drag and dropped, but that would do it for _Temp.dbsource. I also see the spaghetti points didn't work. Do you have the latest version of DBP?

I'm working on the nest error finder, it should be able to tell you exactly which line you need to insert the end structure.

tiresius
21
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 14th Feb 2007 20:19 Edited at: 14th Feb 2007 20:20
I had both files in the same directory, and had the line counter exe there as well. I did drag and drop the dbpro file right onto it. I had to make a change to a couple function names, like count() and trim$ were already listed for 3rd party plugins.

The spaghetti counter- perhaps my hack prevented it from working since I don't call get_source() or get_project(), I just call count() (or my version countLines()) and feed it the full path. Actually I hardcoded files=8 and my spaghetti points are 28,231.

Not sure what it measures other than function size. But just because a function is large doesn't mean it is unreadable. And it doesn't even count the use of goto or gosub either.

I'm using version 1.061. Perhaps the directory path commands work differently than in 1.064

I'm not a real programmer but I play one with DBPro!
Code Dragon
17
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 14th Feb 2007 20:32
Problem solved. Somehow an editing error removed 1 character from my code and messed it all up. It deleted the backslash in the code that returns the file name without the path. I've edited the top post with the new code.

Code Dragon
17
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 16th Feb 2007 14:01 Edited at: 16th Feb 2007 17:30
Support for remstart and remend added.
It also counts statements after "then" in if...then statements as separate logical lines.

Login to post a reply

Server time is: 2024-05-05 10:36:41
Your offset time is: 2024-05-05 10:36:41