Code analysis tools

Hi all,

I’m working on a tools code analysis for Xojo project, available in few days for MacOS. (price 20 euros for the standard version)

He collects some metrics (Loc, Complexity), have many rules (unused vars,memory not free,empty class,dead code,name convention,…)

Check also UI for (fonts, button size,…)

Before buy a windows licence, i want to check if a windows version have a potential market.

Write here or send pm message!

Thanks,

Simple video here:

will you also be offering a version where the source code is included?
Then I am definitly interested.

It will be interesting to see what comes from this since I can envision some very difficult problems you’ll encounter

  1. knowing if a var is “used” - local vars and params isn’t so hard (although you have to get scoping and also know what build target a person is going to use since you might have code that wraps a local var entirely in a #if that wont be compiled in so that code should be entirely ignored)
    properties are much harder since you may never have and code that directly references it BUT you use the property via introspection
    the name of the property may never appear anywhere in the code yet the property should not be considered “unused”

  2. the same holds true for methods since you could invoke them entirely via introspection and never have the name of a method in your code anywhere - such a method should not be marked as “dead code”

  3. memory leaks (I assume thats what you’re shooting for when you say “memory not free”?)
    within a single method this isn’t so bad (and in fact may not be worth checking because objects allocated in a method and assigned to local vars will go out of scope naturally)
    this one can be a bear to track down esp when its across many methods (ie/ in one code path you add a handler but exit whatever code via a different path and haven’t removed the handler)
    I could see you’d need to be able to predict the code flow at runtime from a static analysis - that’s a big chore

suppose you have this

sub mymethod()
dim z as new window
dim b as integer
dim x as boolean = true
if x then return

b = 1 '// dead code (the good term?)
end sub

Introspection aside… you would almost need a full blown compiler to detect “dead code” inside a method… Determining if an entire method is “dead” might be a bit easier… but scope (explicit AND inferred) will be super important to an accurate tool.

No offense… but I hope you plan on a “trial” version, so people can prove to themselves that it will work for them

unreachable might be a better term for that

there can be tricks to that one too
some tools handle reporting conditions where code like this results in unreachable branches

sub foo(bar as integer, baz as integer)
       if bar and baz > 0 then
                 return
       end if

       ' under what conditions is this code unreachable ?
       msgbox "foo !"
end sub

further this code is not always unreachable - only on macOS (so you might want to think about how to handle conditional compilation using #if (which leads into you having to track constants in scope since ANY constant in scope can be used for #if)

sub mymethod()
dim z as new window
dim b as integer
#if Target macOS
return
#endif

b = 1 '// dead code (the good term?)
end sub

z = nil is not needed and makes no sense here.
The window stays allocated as you didn’t close it, but usually methods do not close windows they create as the window needs time show to user and do something.