Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 694091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:49:16+00:00 2026-05-14T02:49:16+00:00

Is there a good resource which describes the why behind PMD rule sets? PMD’s

  • 0

Is there a good resource which describes the “why” behind PMD rule sets? PMD’s site has the “what” – what each rule does – but it doesn’t describe why PMD has that rule and why ignoring that rule can get you in trouble in the real world. In particular, I’m interested in knowing why PMD has the AvoidInstantiatingObjectsInLoops and OnlyOneReturn rules (the first seems necessary if you need to create a new object corresponding to each object in a collection, the second seems like it is a necessity in many cases that return a value based on some criteria), but what I’m really after is a link somewhere describing the “why” behind a majority of PMD’s rules, since this comes up often enough.

Just to be clear, I know that I can disable these and how to do that, I’m just wondering why they are there in the first place. Sorry if there’s something obvious I missed out there, but I did a Google search and SO search before posting this. I also understand that these issues are often a matter of “taste” – what I’m looking for is what the argument for the rules are and what alternatives there are. To give a concrete example, how are you supposed to implement one object corresponding to every object in a loop (which is a common operation in Java) without instantiating each object in a loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:49:17+00:00Added an answer on May 14, 2026 at 2:49 am

    In each case, the rule can be a matter of specific circumstances or just “taste”.

    Instantiating an Object in a loop should be avoided if there are a large number of iterations and the instantiation is expensive. If you can move the code out of the loop, you will avoid many object instantiations, and therefore improve performance. Having said that, this isn’t always possible, and in some cases it just doesn’t matter to the overall performance of the code. In these cases, do whichever is clearer.

    For OnlyOneReturn, there are several ways to view this (with vehement supporters behind each), but they all basically boil down to taste.

    For your example, the OnlyOneReturn proponents want code like:

    public int performAction(String input) {
        int result;
        if (input.equals("bob")) {
            result = 1;
        } else {
            result = 2;
        }
        return result;
    }
    

    Rather than:

    public int performAction(String input) {
        if (input.equals("bob")) {
            return 1;
        } else {
            return 2;
        }
    }
    

    As you can see, the additional clarity of ReturnOnlyOnce can be debated.

    Also see this SO question that relates to instantiation within loops.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This site is pretty good but I'm wondering what other resources are out there.
Can anyone out there recommend a good online resource for CSS 'design patterns'? I
Is there a good resource for the rules around how the httpHandler path property
Is there any good internet resource describing different practices for merging/branching regardless of source
Are there any good resources (books, authoritative guides, etc.) for design patterns or other
Are there any 'good' resources for porting a VB.NET winforms application to C#? I'm
I'm looking at implementing an RDBMS. Are there any good resources out there about
Are there any good online resources for how to create, maintain and think about
Are there good reasons why it's a better practice to have only one return
Are there good efficiency savings using Sql Server 2005 over Sql Server 2000? Or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.