You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by "Thomas Mueller (JIRA)" <ji...@apache.org> on 2012/07/23 12:41:33 UTC

[jira] [Created] (OAK-202) Simplify the code when possible

Thomas Mueller created OAK-202:
----------------------------------

             Summary: Simplify the code when possible
                 Key: OAK-202
                 URL: https://issues.apache.org/jira/browse/OAK-202
             Project: Jackrabbit Oak
          Issue Type: Improvement
            Reporter: Thomas Mueller
            Priority: Minor


Sometimes it's possible to simplify the code, for example: 

- making methods static when possible, so a reader knows the method doesn't change the state of an object 

- the "else" is unnecessary if the "if" block always returns

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OAK-202) Simplify the code when possible

Posted by "Thomas Mueller (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OAK-202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13421251#comment-13421251 ] 

Thomas Mueller commented on OAK-202:
------------------------------------

Based on feedback I got by email seems some people think I committed revision 1364664. It wasn't me :-)

https://fisheye6.atlassian.com/changelog/jackrabbit?cs=1364664

my changes were:

https://fisheye6.atlassian.com/changelog/jackrabbit?cs=1364616
https://fisheye6.atlassian.com/changelog/jackrabbit?cs=1364573

I wonder whether we could have automatic links to revisions?
                
> Simplify the code when possible
> -------------------------------
>
>                 Key: OAK-202
>                 URL: https://issues.apache.org/jira/browse/OAK-202
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>            Reporter: Thomas Mueller
>            Priority: Minor
>
> Sometimes it's possible to simplify the code, for example: 
> - making methods static when possible, so a reader knows the method doesn't change the state of an object 
> - the "else" is unnecessary if the "if" block always returns

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OAK-202) Simplify the code when possible

Posted by "Michael Dürig (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OAK-202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13421347#comment-13421347 ] 

Michael Dürig commented on OAK-202:
-----------------------------------

I was catching up with what was going on while I was away fixing minor things as I went along. As we manage the code base collaboratively, I think it is preferable to have such changes in explicit commits instead of hiding them alongside other stuff as I often observe. This way it is easy for others to undo things they don't like which is much less annoying than to untangle such changes from "real" changes. 
                
> Simplify the code when possible
> -------------------------------
>
>                 Key: OAK-202
>                 URL: https://issues.apache.org/jira/browse/OAK-202
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>            Reporter: Thomas Mueller
>            Priority: Minor
>
> Sometimes it's possible to simplify the code, for example: 
> - making methods static when possible, so a reader knows the method doesn't change the state of an object 
> - the "else" is unnecessary if the "if" block always returns

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (OAK-202) Simplify the code when possible

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OAK-202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13420702#comment-13420702 ] 

Jukka Zitting commented on OAK-202:
-----------------------------------

As noted by Julian in the similar JCR-3396 issue, such minor changes are not always very clear-cut. What's simpler for one person might well be more complex for another.

For example, revision 1364664 removed the redundant field initialization in cases like the following:

{code}
private String value = null;
{code}

In cases like that I personally _prefer_ to have the explicit initial value in place so I know that it's not a problem if the constructor fails to initialize the field.

More generally many of such "simplifications" depend on personal taste and preference, so in general I'd leave it up to whoever actually works on a particular piece of code to decide which style to use. If people find that confusing, let's document a shared coding style beyond the currently agreed standard Java coding conventions. Until then I'm a bit annoyed by commits that simply make such stylistic changes with no other benefit.
                
> Simplify the code when possible
> -------------------------------
>
>                 Key: OAK-202
>                 URL: https://issues.apache.org/jira/browse/OAK-202
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>            Reporter: Thomas Mueller
>            Priority: Minor
>
> Sometimes it's possible to simplify the code, for example: 
> - making methods static when possible, so a reader knows the method doesn't change the state of an object 
> - the "else" is unnecessary if the "if" block always returns

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OAK-202) Simplify the code when possible

Posted by "Thomas Mueller (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OAK-202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13421246#comment-13421246 ] 

Thomas Mueller commented on OAK-202:
------------------------------------

I agree in many cases it's matter of taste, and where it's a matter of taste I agree it should be left to the person working on that code. I made this issue for code I'm working on or feel responsible for.

As a general rule, I think source code should be as simple as possible, to make it easier to for the reader. That's why I personally like to avoid really pointless Javadocs. For the same reason, I prefer if source code is formatted consistently (position of the "}" for example). I think there should be some minimum rules about such things, for example the "Code Conventions for the Java Programming Language" at http://www.oracle.com/technetwork/java/codeconv-138413.html - plus some of our own rules such as using spaces instead of tabs.

There are cases where formatting can avoid bugs, for example even single line "if" and "while" blocks should have "{}". Immutability helps to avoid bugs, so when possible I make fields final (but for variables and parameters I think it hurts readability more than it helps), and make methods static when possible. Another example is using @Override. Most of that can be checked automatically, for example using CheckStyle or FindBugs. If we have a shared set of CheckStyle rules then we could avoid long discussions about that.

                
> Simplify the code when possible
> -------------------------------
>
>                 Key: OAK-202
>                 URL: https://issues.apache.org/jira/browse/OAK-202
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>            Reporter: Thomas Mueller
>            Priority: Minor
>
> Sometimes it's possible to simplify the code, for example: 
> - making methods static when possible, so a reader knows the method doesn't change the state of an object 
> - the "else" is unnecessary if the "if" block always returns

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira