Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code style: use generics everywhere, remove dead code, resource leaks, javadoc etc. #775

Closed
bencomp opened this issue Jul 28, 2014 · 22 comments
Labels
Component: Code Infrastructure formerly "Feature: Code Infrastructure"
Milestone

Comments

@bencomp
Copy link
Contributor

bencomp commented Jul 28, 2014

Eclipse reports over 800 warnings in the current Dataverse code. That's a lot better than the 4500+ in recent 3.6.2 code, but too many.

These include

May I also recommend to add a bit of Javadoc to every method longer than, say, 10 lines? It makes understanding the code without looking at each and every line easier.

Bad habit found in v3.6: using a raw Map with 2 values of different classes instead of a new Class with two members, one of each type.

Map someMap = getMap();
TypeOne item1 = (TypeOne) someMap.get(0);
TypeTwo item2 = (TypeTwo) someMap.get(1);

With the proper use of generic types I'm sure you don't crazy stuff like that anymore, do you? ;)

@bencomp
Copy link
Contributor Author

bencomp commented Jul 28, 2014

Related issue, but different code style aspects: #26

@pdurbin
Copy link
Member

pdurbin commented Jul 28, 2014

@bencomp and I discussed this ticket at http://irclog.iq.harvard.edu/dataverse/2014-07-28 and we agreed that this ticket shouldn't be about any particular IDE (Eclipse, Netbeans, etc.). The tool we use should not require an IDE so that we can easily run in from Jenkins. The MongoDB project uses checkstyle, for example (config at https://github.com/mongodb/mongo-java-driver/blob/3.0.x/config/checkstyle.xml ) and FindBugs is also popular.

@pdurbin
Copy link
Member

pdurbin commented Sep 25, 2014

I just created a draft Dataverse Coding Standards and Style Guide: https://docs.google.com/document/d/1KTd3FpM1BI3HlBofaZjMmBiQEJtFf11jiiGpQeJzy7A/edit?usp=sharing

We need to agree on our standards and style before we commit them to the Developers Guide.

@bencomp
Copy link
Contributor Author

bencomp commented Oct 7, 2014

Can I add to this that any debug or info messages and stacktraces are not written to System.out, but are logged using a Logger? Looking at System.out might work in unit tests, but in Glassfish's server.log, all these lines are just lines without a source or status. (Using meaningful messages helps, but finding the source of any messages is more helpful to both developers and administrators, I think.)

@pdurbin
Copy link
Member

pdurbin commented Oct 7, 2014

@bencomp this is a good idea and I just added it to the Google doc I mentioned before. I just changed it so the public can add comments and I added you as someone who can edit. I think it'll be easier to have the discussion there.

@bencomp
Copy link
Contributor Author

bencomp commented Oct 31, 2014

To add to the list above: unchecked conversions are also needed when EntityManager.createQuery(String q).getResultsList() is used instead of EntityManager.createQuery(String q, Class<T> c).getResultsList().

@pdurbin
Copy link
Member

pdurbin commented Oct 31, 2014

Right, we should be using the createQuery methods on EntityManager that return TypedQuery.

@akio-sone
Copy link
Contributor

Hi Phil,
one more thing I came across my mind about this topic is the(?)
line-ending style for newly created files for Dataverse.

What is Dataverse's rule about the line-ending style for the GitHub
right now? No rule or just LF (*nix style)?

Then, how about a case of modifying an existing file, i.e., allowing a
developer to reset existing line styles to the official one or keeping
existing lines styles as they are?

Yesterday when I vagrant-ed up the Dataverse project, it failed because
my local copy of a shell script (download.sh) has the CR+LF-(Windows
style ) ending for some reason as shown below:

==> default: /tmp/vagrant-shell: ./download.sh: /bin/sh^M: bad
interpreter: No such file or directory

As far as I checked about the Git plugin of NetBeans, there was no
option to select a line-ending style project wise although adding a
start-up option (e.g., -J-Dline.separator=LF) seems one way to override
NetBeans' default ( use the line-ending style of the platform).

On 9/25/2014 10:54 AM, Philip Durbin wrote:

I just created a draft Dataverse Coding Standards and Style Guide:
https://docs.google.com/document/d/1KTd3FpM1BI3HlBofaZjMmBiQEJtFf11jiiGpQeJzy7A/edit?usp=sharing

We need to agree on our standards and style before we commit them to the
Developers Guide.


Reply to this email directly or view it on GitHub
#775 (comment).

Akio Sone
Odum Inst.
UNC at Chapel Hill

@akio-sone
Copy link
Contributor

I just added "Use Unix line endings (LF)" to the doc:
https://docs.google.com/document/d/1KTd3FpM1BI3HlBofaZjMmBiQEJtFf11jiiGpQeJzy7A/edit?usp=sharing

On Wed, Nov 5, 2014 at 12:24 PM, Sone, Akio asone@email.unc.edu wrote:

Hi Phil,
one more thing I came across my mind about this topic is the(?)
line-ending style for newly created files for Dataverse.

What is Dataverse's rule about the line-ending style for the GitHub right
now? No rule or just LF (*nix style)?

Then, how about a case of modifying an existing file, i.e., allowing a
developer to reset existing line styles to the official one or keeping
existing lines styles as they are?

Yesterday when I vagrant-ed up the Dataverse project, it failed because my
local copy of a shell script (download.sh) has the CR+LF-(Windows style )
ending for some reason as shown below:

==> default: /tmp/vagrant-shell: ./download.sh: /bin/sh^M: bad
interpreter: No such file or directory

As far as I checked about the Git plugin of NetBeans, there was no option
to select a line-ending style project wise although adding a start-up
option (e.g., -J-Dline.separator=LF) seems one way to override NetBeans'
default ( use the line-ending style of the platform).

On 9/25/2014 10:54 AM, Philip Durbin wrote:

I just created a draft Dataverse Coding Standards and Style Guide:
https://docs.google.com/document/d/1KTd3FpM1BI3HlBofaZjMmBiQEJtFf
11jiiGpQeJzy7A/edit?usp=sharing

We need to agree on our standards and style before we commit them to the
Developers Guide.


Reply to this email directly or view it on GitHub
#775 (comment).

Akio Sone
Odum Inst.
UNC at Chapel Hill

Philip Durbin
Software Developer for http://dataverse.org
http://www.iq.harvard.edu/people/philip-durbin

@pdurbin
Copy link
Member

pdurbin commented Apr 8, 2015

On a related note, I just learned of a Java code coverage library called JaCoCo ( http://www.eclemma.org/jacoco/ ) at http://www.programmingthrowdown.com/2015/04/episode-41-nodejs.html that's super easy to use. You just add the following to your pom.xml and run mvn package to produce reports like in the screenshot below:

shapefilehandler_-_2015-04-07_22 11 35

        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.4.201502262128</version>
        </dependency>
        <dependency>
...
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.4.201502262128</version>
                <configuration>
                    <destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</destfile>
                    <datafile>${basedir}/target/coverage-reports/jacoco-unit.exec</datafile>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

@bencomp
Copy link
Contributor Author

bencomp commented Apr 8, 2015

@pdurbin even red bars in such a report look a lot better than encountering // TODO: implement test in a test class. I'd say go ahead 👍

I'm tempted to add "limit length of methods" to the style guide, but I don't know the reasons for creating ~300 line methods

@bencomp
Copy link
Contributor Author

bencomp commented Apr 14, 2015

@pdurbin will you add the JaCoCo bit to the pom?

@pdurbin
Copy link
Member

pdurbin commented Apr 14, 2015

@pdurbin will you add the JaCoCo bit to the pom?

I'd love to. I think we need to decide where to put the output, however. I consider the output from JaCoCo to be similar to the "maven site" output I played with in the DVN 3.6 days. You can see the output of that experiment at http://dvn.github.io/dvn-mavensitepoc/ ( repo link: https://github.com/dvn/dvn-mavensitepoc ).

Along these lines I just pushed 184e687 so this gets updated on every build: https://apitest.dataverse.org/guides/developers/database/schemaspy/relationships.html

@mercecrosas mercecrosas added this to the In Review - 4.0.x milestone Apr 14, 2015
bencomp added a commit to bencomp/dataverse that referenced this issue Jul 14, 2015
Change INFO messages to WARNINGs when something went wrong;

use log message templates instead of concatenation, and the Throwable variant when
a Throwable is passed.

Improve formatting, add some javadoc.
bencomp added a commit to bencomp/dataverse that referenced this issue Jul 31, 2015
Instead of using `Object[]` with various types and needing knowledge of
the type and meaning of the members of the array, use SummaryData and
BlockData.

Also, don't use raw types and unchecked conversions.
bencomp added a commit to bencomp/dataverse that referenced this issue Jul 31, 2015
Manually added diamond operators in files.
bencomp added a commit to bencomp/dataverse that referenced this issue Jul 31, 2015
Change INFO messages to WARNINGs when something went wrong;

use log message templates instead of concatenation, and the Throwable variant when
a Throwable is passed.

Improve formatting, add some javadoc.
bencomp added a commit to bencomp/dataverse that referenced this issue Jul 31, 2015
Changes include converting `Query` to `TypedQuery<...>`.
@pdurbin
Copy link
Member

pdurbin commented Jul 31, 2015

In ccea087 I enabled mvn -DcompilerArgument=-Xlint:unchecked test on Travis builds at https://travis-ci.org/IQSS/dataverse so now it will be easier to see and link to "unchecked conversion" warnings, as I just did at #2425 (comment)

@kcondon
Copy link
Contributor

kcondon commented Sep 11, 2015

These issues have been raised internally. Closing and individual issues will be followed up on separately. Closing.

@kcondon kcondon closed this as completed Sep 11, 2015
sekmiller added a commit that referenced this issue Sep 17, 2015
Improve log messages in DOIEZIDServiceBean (fixes #2277) #775
sekmiller added a commit that referenced this issue Sep 17, 2015
Add more generics to Guestbook related classes (#775)
@bencomp bencomp mentioned this issue Apr 8, 2016
11 tasks
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 7, 2018
As JaCoCo has been a direct dependency in *compile* scope, at four places
accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.
Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 7, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 7, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 14, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 14, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 15, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 21, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 21, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 21, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 21, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
poikilotherm added a commit to poikilotherm/dataverse that referenced this issue Nov 29, 2018
As JaCoCo has been a direct dependency in *compile* scope.

At a few places accidentially some classes from transitive dependencies from JaCoCo have been used
instead of the classes used commonly within the codebase.

Removing the JaCoCo direct dependency as only the plugin is used at build/test time. It is sufficient for Maven to have the
plugin included with its version number - this is handled as a transitive dependency during the build internally by Maven.

Hopefully this created no harm, but better fix this now.
@bencomp bencomp mentioned this issue Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Code Infrastructure formerly "Feature: Code Infrastructure"
Projects
None yet
Development

No branches or pull requests

6 participants