Discussion:
Finding unused / un-referenced code
Patroklos Papapetrou
2014-10-08 09:30:08 UTC
Permalink
Hi everyone

AFAIK , Sonarqube can report on many cases of unused code.
For Java :
http://nemo.sonarqube.org/coding_rules#q=unused|qprofile=java-sonar-way-with-findbugs-93000|activation=true|languages=java
For C :
http://nemo.sonarqube.org/coding_rules#q=unused|qprofile=c-sonar-way-44762|languages=c

Most of them are related to private or protected fields or private methods
that are not used.
We are very interesting on finding unused or un-referenced code within a
project. This practically means that even public methods that are not
references should be reported.
I know that this kind of rule has several concerns ( at least for Java ) .
I've been through several projects where frameworks demand the existence of
public or protected methods for injection purposes so I understand that
many false-positives might be created. So this rule should be highly
customizable which is against the philosophy of SonarQube rules ( make them
as simple as it gets )

To stop thinking aloud, are there any plans for such kind of rule, or any
ideas on how it could be implemented? Does this rule make sense to other
languages like C or C#

Any thoughts are greatly appreciated

Thanks,

Patroklos Papapetrou

SoftwareGarden.io

Linkedin <http://www.linkedin.com/in/ppapapetrou> | Twitter
<http://twitter.com/ppapapetrou76> | *Author
<http://softwaregarden.io/my-books> *| Speaker
<http://lanyrd.com/profile/ppapapetrou/> | Blog <http://softwaregarden.io>
| Google+ <https://plus.google.com/+PatroklosPapapetrou> | GitHub
<https://github.com/ppapapetrou76> |
Jean-Pierre Fayolle
2014-10-08 11:28:20 UTC
Permalink
Hello Patroklos,



This rule definitively makes sense for other languages likes Cobol and ABAP.



ABAP especially, because SAP obliges regularly his customers to migrate of versions, which means you have to make a special project to check existing code and adapt it to the new SAP core. It is not rare to see companies with 25% or 40% of dead (unused) code, so you can imagine the cost of migrating unused code is high while completely useless.



The notion of application does not make sense in Cobol (I explained that in a post http://qualilogy.com/en/sonar-cobol-what-you-need-to-know/). So, which program uses which copy-book or calls which other program is something that cobolists are interested to know. Although, this means analyzing a whole portfolio of applications, not just one cobol library.



Another thing is that Cobol or Abap developers don’t like to delete existing code, so you can find a lot of code in comments or unused code. This means that you can get whole sections of code inside a program that are not called but still weights on readability, changeability, maitainability, etc.

A trick used by (usually experienced) ABAP developer is to isolate a portion of code with

If 1=0


 dead code

Endif



This feature would be also useful for PL/SQL or Oracle Forms, but rather on the DB side: which stored procedures or tables or views are not used. This would mean being able to extract some DB representation of objects and to analyze it.



You also need some cross reference capacities (but I think SonarSource has it in its projects). This could also allow Fan In/Fan Out on source code and other architectural rules, like ‘Avoid calling the DB layer from the presentation layer’. Now, it usually comes with a cost of analysis performance if you have to store all the links between all the components into the Sonar DB.



Do not hesitate to ask for further precision.

Regards,



Jean-Pierre FAYOLLE

Senior Consultant

<http://www.qualilogy.com/>

www.qualilogy.com



From: Patroklos Papapetrou [mailto:ppapapetrou76-***@public.gmane.org]
Sent: miércoles, 08 de octubre de 2014 11:30
To: user-***@public.gmane.org
Subject: [sonar-user] Finding unused / un-referenced code



Hi everyone



AFAIK , Sonarqube can report on many cases of unused code.

For Java : http://nemo.sonarqube.org/coding_rules#q=unused|qprofile=java-sonar-way-with-findbugs-93000|activation=true|languages=java

For C : http://nemo.sonarqube.org/coding_rules#q=unused|qprofile=c-sonar-way-44762|languages=c



Most of them are related to private or protected fields or private methods that are not used.

We are very interesting on finding unused or un-referenced code within a project. This practically means that even public methods that are not references should be reported.

I know that this kind of rule has several concerns ( at least for Java ) . I've been through several projects where frameworks demand the existence of public or protected methods for injection purposes so I understand that many false-positives might be created. So this rule should be highly customizable which is against the philosophy of SonarQube rules ( make them as simple as it gets )



To stop thinking aloud, are there any plans for such kind of rule, or any ideas on how it could be implemented? Does this rule make sense to other languages like C or C#



Any thoughts are greatly appreciated



Thanks,



Patroklos Papapetrou

SoftwareGarden.io

<http://www.linkedin.com/in/ppapapetrou> Linkedin | <http://twitter.com/ppapapetrou76> Twitter | Author <http://softwaregarden.io/my-books> | Speaker <http://lanyrd.com/profile/ppapapetrou/> | <http://softwaregarden.io> Blog | <https://plus.google.com/+PatroklosPapapetrou> Google+ | GitHub <https://github.com/ppapapetrou76> |




Comprobado por AVG - www.avg.com
Versión: 2014.0.4765 / Base de datos de virus: 4037/8346 - Fecha de publicación: 10/07/14
Jean-Pierre Fayolle
2014-10-08 11:28:20 UTC
Permalink
Hello Patroklos,



This rule definitively makes sense for other languages likes Cobol and ABAP.



ABAP especially, because SAP obliges regularly his customers to migrate of versions, which means you have to make a special project to check existing code and adapt it to the new SAP core. It is not rare to see companies with 25% or 40% of dead (unused) code, so you can imagine the cost of migrating unused code is high while completely useless.



The notion of application does not make sense in Cobol (I explained that in a post http://qualilogy.com/en/sonar-cobol-what-you-need-to-know/). So, which program uses which copy-book or calls which other program is something that cobolists are interested to know. Although, this means analyzing a whole portfolio of applications, not just one cobol library.



Another thing is that Cobol or Abap developers don’t like to delete existing code, so you can find a lot of code in comments or unused code. This means that you can get whole sections of code inside a program that are not called but still weights on readability, changeability, maitainability, etc.

A trick used by (usually experienced) ABAP developer is to isolate a portion of code with

If 1=0


 dead code

Endif



This feature would be also useful for PL/SQL or Oracle Forms, but rather on the DB side: which stored procedures or tables or views are not used. This would mean being able to extract some DB representation of objects and to analyze it.



You also need some cross reference capacities (but I think SonarSource has it in its projects). This could also allow Fan In/Fan Out on source code and other architectural rules, like ‘Avoid calling the DB layer from the presentation layer’. Now, it usually comes with a cost of analysis performance if you have to store all the links between all the components into the Sonar DB.



Do not hesitate to ask for further precision.

Regards,



Jean-Pierre FAYOLLE

Senior Consultant

<http://www.qualilogy.com/>

www.qualilogy.com



From: Patroklos Papapetrou [mailto:***@gmail.com]
Sent: miércoles, 08 de octubre de 2014 11:30
To: ***@sonar.codehaus.org
Subject: [sonar-user] Finding unused / un-referenced code



Hi everyone



AFAIK , Sonarqube can report on many cases of unused code.

For Java : http://nemo.sonarqube.org/coding_rules#q=unused|qprofile=java-sonar-way-with-findbugs-93000|activation=true|languages=java

For C : http://nemo.sonarqube.org/coding_rules#q=unused|qprofile=c-sonar-way-44762|languages=c



Most of them are related to private or protected fields or private methods that are not used.

We are very interesting on finding unused or un-referenced code within a project. This practically means that even public methods that are not references should be reported.

I know that this kind of rule has several concerns ( at least for Java ) . I've been through several projects where frameworks demand the existence of public or protected methods for injection purposes so I understand that many false-positives might be created. So this rule should be highly customizable which is against the philosophy of SonarQube rules ( make them as simple as it gets )



To stop thinking aloud, are there any plans for such kind of rule, or any ideas on how it could be implemented? Does this rule make sense to other languages like C or C#



Any thoughts are greatly appreciated



Thanks,



Patroklos Papapetrou

SoftwareGarden.io

<http://www.linkedin.com/in/ppapapetrou> Linkedin | <http://twitter.com/ppapapetrou76> Twitter | Author <http://softwaregarden.io/my-books> | Speaker <http://lanyrd.com/profile/ppapapetrou/> | <http://softwaregarden.io> Blog | <https://plus.google.com/+PatroklosPapapetrou> Google+ | GitHub <https://github.com/ppapapetrou76> |




Comprobado por AVG - www.avg.com
Versión: 2014.0.4765 / Base de datos de virus: 4037/8346 - Fecha de publicación: 10/07/14
Juan Ignacio Barisich
2015-03-20 13:49:58 UTC
Permalink
Hi everybody.
Is there any news about this?
We are using UCDetector (http://www.ucdetector.org/), an Eclipse plugin that
detects un-referenced classes and methods.
It would be nice to get this feature on SonarQube.
So, ¿are there plans to implement something like this?

Thanks you
Regards



--
View this message in context: http://sonarqube.15.x6.nabble.com/Finding-unused-un-referenced-code-tp5028894p5033522.html
Sent from the SonarQube Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Continue reading on narkive:
Search results for 'Finding unused / un-referenced code' (Questions and Answers)
23
replies
I like to write. How often should I write a week?
started 2006-10-20 14:08:51 UTC
books & authors
Loading...