You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Aleksandar Nikolov (JIRA)" <ji...@apache.org> on 2009/10/27 16:55:59 UTC

[jira] Created: (TAP5-909) Against PRIVATE modifier on fields

Against PRIVATE modifier on fields
----------------------------------

                 Key: TAP5-909
                 URL: https://issues.apache.org/jira/browse/TAP5-909
             Project: Tapestry 5
          Issue Type: Wish
          Components: tapestry-core
    Affects Versions: 5.0.18
            Reporter: Aleksandar Nikolov


In Tapestry classes every instance variable MUST be declared private!?!

Why this requirements exists?

I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...

I will give you an example: Imagine you want to access a variable declared in superclass like this:

@Property
private User user;

Must create getter and setter which @Property already does in background!

I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Aleksandar Nikolov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770691#action_12770691 ] 

Aleksandar Nikolov commented on TAP5-909:
-----------------------------------------

Hm...

Adding getters/setters is just workaround.

I am not familiar with Tapestry "bytecode-level enhancement", (sorry for my question which might be too amateur) but : 

1. Can't these "bytecode enhancements" be applied at compile time, not at application startup time, as for example, obfuscators do?

2. Looking at your example I do not understand why for every single class "A" we must search for possible subclasses and apply them bytecode enhancement. Isn't it much easy and much faster just do the opposite - find the superclass "A" for each class "B" and apply for its subclass (class "B") bytecode enhancement?

I really do not understand why changing field modifiers cause such problems. Would you give me any start point?

> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>            Assignee: Robert Zeigler
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Robert Zeigler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Zeigler reassigned TAP5-909:
-----------------------------------

    Assignee: Robert Zeigler

> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>            Assignee: Robert Zeigler
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Robert Zeigler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Zeigler reassigned TAP5-909:
-----------------------------------

    Assignee: Robert Zeigler

> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>            Assignee: Robert Zeigler
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Robert Zeigler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Zeigler closed TAP5-909.
-------------------------------

    Resolution: Won't Fix

> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>            Assignee: Robert Zeigler
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Robert Zeigler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12788890#action_12788890 ] 

Robert Zeigler commented on TAP5-909:
-------------------------------------

0) Applying getters/setters is NOT a workaround.  It is the java-standard way of providing public access to properties.  The fact that @Property generates getters and setters for you is a convenience provided by tapestry.  

1) Generally, no.  That would eliminate T5's ability to "hot swap" the code when you make changes to page/component/mixin classes.

2) Superclass/subclass was perhaps a bad example.  Generally speaking, Tapestry manages variables by replacing access to them in user-written code with synthetic methods in generated code.  That means tapestry has to find all usages of variable "foo" of class "Bar" and replace it with appropriate synthetic methods... something like _foo() for read access and _foo(value) for write access. Although there may be some very simple cases where the synthetic method replacement isn't necessary, generally it is (consider, for example: @Parameter @Property foo; There's a whole host of code going on to make @Parameter work).   If you allow non-private variables, the scope of classes to search for synthetic method replacement becomes that much larger.  Package protected? Now you have to search every class in the package.  Protected? Search every class in the package.  Subclass compilation will also have to walk the chain of superclasses, as you mentioned.  Public? Watch out!   Basically, by allowing a non-private variable to be controlled by tapestry, you're opening a whole can of worms.  It's just not worth it.  Although if you really feel strongly otherwise, you could try your hand at contributing a patch for this issue.... :)



> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>            Assignee: Robert Zeigler
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Robert Zeigler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12788890#action_12788890 ] 

Robert Zeigler commented on TAP5-909:
-------------------------------------

0) Applying getters/setters is NOT a workaround.  It is the java-standard way of providing public access to properties.  The fact that @Property generates getters and setters for you is a convenience provided by tapestry.  

1) Generally, no.  That would eliminate T5's ability to "hot swap" the code when you make changes to page/component/mixin classes.

2) Superclass/subclass was perhaps a bad example.  Generally speaking, Tapestry manages variables by replacing access to them in user-written code with synthetic methods in generated code.  That means tapestry has to find all usages of variable "foo" of class "Bar" and replace it with appropriate synthetic methods... something like _foo() for read access and _foo(value) for write access. Although there may be some very simple cases where the synthetic method replacement isn't necessary, generally it is (consider, for example: @Parameter @Property foo; There's a whole host of code going on to make @Parameter work).   If you allow non-private variables, the scope of classes to search for synthetic method replacement becomes that much larger.  Package protected? Now you have to search every class in the package.  Protected? Search every class in the package.  Subclass compilation will also have to walk the chain of superclasses, as you mentioned.  Public? Watch out!   Basically, by allowing a non-private variable to be controlled by tapestry, you're opening a whole can of worms.  It's just not worth it.  Although if you really feel strongly otherwise, you could try your hand at contributing a patch for this issue.... :)



> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>            Assignee: Robert Zeigler
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Aleksandar Nikolov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770691#action_12770691 ] 

Aleksandar Nikolov commented on TAP5-909:
-----------------------------------------

Hm...

Adding getters/setters is just workaround.

I am not familiar with Tapestry "bytecode-level enhancement", (sorry for my question which might be too amateur) but : 

1. Can't these "bytecode enhancements" be applied at compile time, not at application startup time, as for example, obfuscators do?

2. Looking at your example I do not understand why for every single class "A" we must search for possible subclasses and apply them bytecode enhancement. Isn't it much easy and much faster just do the opposite - find the superclass "A" for each class "B" and apply for its subclass (class "B") bytecode enhancement?

I really do not understand why changing field modifiers cause such problems. Would you give me any start point?

> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>            Assignee: Robert Zeigler
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Robert Zeigler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770572#action_12770572 ] 

Robert Zeigler commented on TAP5-909:
-------------------------------------

Tapestry does a whole ton of bytecode-level enhancements on page & component classes. The benefit of the requirement is that it makes this process much more efficient.  Consider scenarios like:

Class A {
@Property
protected User user;
}

Class B extends A {
  super.user....
}

where class B can now be /anywhere/.  It could be in your components directory, or it could be in a 3rd party drop-in module.  Do you /really/ want Tapestry to have to perform byte-code enhancement on every single page and every single component in every single library included in your app, right at startup?  To support non-private fields would effectively require that.  I'll take the heavy "burden" of implementing my own getters/setters any day over decreasing T5's startup time.  One of the major complaints about T4 was it's slow startup time... I'd rather we not head back down that road.



> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Robert Zeigler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770572#action_12770572 ] 

Robert Zeigler commented on TAP5-909:
-------------------------------------

Tapestry does a whole ton of bytecode-level enhancements on page & component classes. The benefit of the requirement is that it makes this process much more efficient.  Consider scenarios like:

Class A {
@Property
protected User user;
}

Class B extends A {
  super.user....
}

where class B can now be /anywhere/.  It could be in your components directory, or it could be in a 3rd party drop-in module.  Do you /really/ want Tapestry to have to perform byte-code enhancement on every single page and every single component in every single library included in your app, right at startup?  To support non-private fields would effectively require that.  I'll take the heavy "burden" of implementing my own getters/setters any day over decreasing T5's startup time.  One of the major complaints about T4 was it's slow startup time... I'd rather we not head back down that road.



> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (TAP5-909) Against PRIVATE modifier on fields

Posted by "Robert Zeigler (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Zeigler closed TAP5-909.
-------------------------------

    Resolution: Won't Fix

> Against PRIVATE modifier on fields
> ----------------------------------
>
>                 Key: TAP5-909
>                 URL: https://issues.apache.org/jira/browse/TAP5-909
>             Project: Tapestry 5
>          Issue Type: Wish
>          Components: tapestry-core
>    Affects Versions: 5.0.18
>            Reporter: Aleksandar Nikolov
>            Assignee: Robert Zeigler
>
> In Tapestry classes every instance variable MUST be declared private!?!
> Why this requirements exists?
> I agree that it is a good practice to hide and encapsulate the data, but in some cases, especially in extending classes (including your own), this becomes a problem. In subclasses these variables can be accessed ONLY  through getter/setters. This is like giving pocket-money to your son using bank account...
> I will give you an example: Imagine you want to access a variable declared in superclass like this:
> @Property
> private User user;
> Must create getter and setter which @Property already does in background!
> I think that this requirement makes difficult using OO techniques like inheritance and should be removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.