You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@abdera.apache.org by Harris Boyce III <ha...@gmail.com> on 2006/09/28 16:25:58 UTC

Coding/Language Standards

I am looking to have a brief discussion about coding standards in Java
and .NET and how they are/should be applied on this project.

While studying the code for this project, and other Java porgrams as
well, I'm not sure that I understand the premises behind getters and
setters and list operation methods (AddEntry, RemoveEntry, etc.).  In
.NET, the concept of properties allows the compilers to automatically
generate getter and setter methods in-place of what appears to be
regular public fields.  What I don't necessarily understand is why
list operations are added to objects when the getters and setters
expose the list/collection types?  I don't know if this is just a
nuance of Java and that .NET developers just don't follow these
practices, but I am hoping to receive some insight as to why this
practice is followed and whether or not I should do the same in the
.NET implemenation of Abdera.

Thanks,

Harris

Re: Coding/Language Standards

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
> Right and I think this is where the rub lies.  I've been "brought-up"
> that, unless the data is read-only, you just generally implement
> read/write properties so I can easily implement it as:
>
> List<Entry> Entries {
>   get;
> }
>
> But even with that, nothing prevents the user accessing the feed from
> calling theFeed.Entries.Add(someEntry);  Now, the implementation could
> return a read-only List and then any modifying operations would
> generate exceptions.  But...why would I do that?
>
> Does that make any sense?  I'm hoping that this doesn't seem like an
> immature conversation, but it's one that I struggle with when I study
> Java.  Why wouldn't I just use those conveience methods to modify the
> list if and when I need to do so?
>
> Thanks again for the discussion!  I'm learning lots!

I wouldn't object to returning read-only lists in that sort of
situation.  Heck, I wouldn't object to doing so in Java either ;-)

-garrett

Re: Coding/Language Standards

Posted by Harris Boyce III <ha...@gmail.com>.
Garrett, James, thanks for your replies. See, I think that makes more
sense especially from the perspective of single responsiblity.  The
AddEntry method localizes all the validation for adding entries to a
feed.

As for the Axiom bit, I guess that is going to take some more research
and studying to figure out how that needs to implemented in .NET.

Thanks guys,

H

On 9/28/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
> > OK, so why would I do that?  Why would I make the list returned from
> > List<?> getEntries() immutable and provide mutator methods when the
> > List<?> type supports them implicitly?
> >
> > Again, sorry if this seems like a college-level discussion, but I do
> > struggle with this bit of encapsulation.
>
> Aside from what James said about our current implementation, I could
> also see you wanting to have sanity checking on the entries, for
> example if there's no feed level author then authors are required on
> entries.  If you can just insert an arbitrary entry into the list you
> wouldn't have a chance to sanity check it.
>
> Not saying we do that now (I have no idea), but it's one reason to
> keep mutations to the underlying data structure under the control of
> Abdera's code, not the list implementation.
>
> -garrett
>

Re: Coding/Language Standards

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
> OK, so why would I do that?  Why would I make the list returned from
> List<?> getEntries() immutable and provide mutator methods when the
> List<?> type supports them implicitly?
>
> Again, sorry if this seems like a college-level discussion, but I do
> struggle with this bit of encapsulation.

Aside from what James said about our current implementation, I could
also see you wanting to have sanity checking on the entries, for
example if there's no feed level author then authors are required on
entries.  If you can just insert an arbitrary entry into the list you
wouldn't have a chance to sanity check it.

Not saying we do that now (I have no idea), but it's one reason to
keep mutations to the underlying data structure under the control of
Abdera's code, not the list implementation.

-garrett

Re: Coding/Language Standards

Posted by James M Snell <ja...@gmail.com>.
The wierdness stems from the way Axiom works under the covers and the
incremental parsing model.  Essentially, the List returned by the
methods is backed by an Iterator that may not be in an appropriate state
to modify the underlying infoset.

- James

Harris Boyce III wrote:
> OK, so why would I do that?  Why would I make the list returned from
> List<?> getEntries() immutable and provide mutator methods when the
> List<?> type supports them implicitly?
> 
> Again, sorry if this seems like a college-level discussion, but I do
> struggle with this bit of encapsulation.
> 
> Thanks again,
> 
> H
> 
> On 9/28/06, James M Snell <ja...@gmail.com> wrote:
>> The List<?> methods exist mainly to support easy iteration and getting
>> of the entries.  They are unmodifiable lists, meaning that calling any
>> of the add/remove operations will result in an unsupported operation
>> exception.
>>
>> - James
>>
>> Harris Boyce III wrote:
>> > Right and I think this is where the rub lies.  I've been "brought-up"
>> > that, unless the data is read-only, you just generally implement
>> > read/write properties so I can easily implement it as:
>> >
>> > List<Entry> Entries {
>> >  get;
>> > }
>> >
>> > But even with that, nothing prevents the user accessing the feed from
>> > calling theFeed.Entries.Add(someEntry);  Now, the implementation could
>> > return a read-only List and then any modifying operations would
>> > generate exceptions.  But...why would I do that?
>> >
>> > Does that make any sense?  I'm hoping that this doesn't seem like an
>> > immature conversation, but it's one that I struggle with when I study
>> > Java.  Why wouldn't I just use those conveience methods to modify the
>> > list if and when I need to do so?
>> >
>> > Thanks again for the discussion!  I'm learning lots!
>> >
>> > H
>> >
>> > On 9/28/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
>> >> On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
>> >> > Garrett -
>> >> >
>> >> > Yeah, shoulda done that to begin with, sorry...OK, from package
>> >> > org.apache.abdera.model, interface Feed defines these methods:
>> >> >
>> >> > List<Entry> getEntries();
>> >> > void addEntry(Entry entry);
>> >> > ...
>> >> > Entry getEntry(String id);
>> >> >
>> >> > In .NET, I could define these as properties like this:
>> >> >
>> >> > List<Entry> Entries {
>> >> >   get;
>> >> >   set;
>> >> > }
>> >> >
>> >> > And then, normally, I would use the methods exposed by
>> List<Entry> to
>> >> > perform operations on the Entries (add, remove, etc.).  Now,
>> granted,
>> >> > I would have to implement a method to retrieve the entry by ID
>> just as
>> >> > done above.  But I guess my question may be centered around the
>> >> > encapsulation standards across the languages?  Maybe?
>> >> >
>> >> > Does that clarify any?  If not, let me know.
>> >>
>> >> Well, you'd definately want the getter for the entries, but setting an
>> >> entire list of entries is kind of weird IMO...  Perhaps other people
>> >> have optinions.
>> >>
>> >> -garrett
>> >>
>> >
>>
> 

Re: Coding/Language Standards

Posted by Harris Boyce III <ha...@gmail.com>.
OK, so why would I do that?  Why would I make the list returned from
List<?> getEntries() immutable and provide mutator methods when the
List<?> type supports them implicitly?

Again, sorry if this seems like a college-level discussion, but I do
struggle with this bit of encapsulation.

Thanks again,

H

On 9/28/06, James M Snell <ja...@gmail.com> wrote:
> The List<?> methods exist mainly to support easy iteration and getting
> of the entries.  They are unmodifiable lists, meaning that calling any
> of the add/remove operations will result in an unsupported operation
> exception.
>
> - James
>
> Harris Boyce III wrote:
> > Right and I think this is where the rub lies.  I've been "brought-up"
> > that, unless the data is read-only, you just generally implement
> > read/write properties so I can easily implement it as:
> >
> > List<Entry> Entries {
> >  get;
> > }
> >
> > But even with that, nothing prevents the user accessing the feed from
> > calling theFeed.Entries.Add(someEntry);  Now, the implementation could
> > return a read-only List and then any modifying operations would
> > generate exceptions.  But...why would I do that?
> >
> > Does that make any sense?  I'm hoping that this doesn't seem like an
> > immature conversation, but it's one that I struggle with when I study
> > Java.  Why wouldn't I just use those conveience methods to modify the
> > list if and when I need to do so?
> >
> > Thanks again for the discussion!  I'm learning lots!
> >
> > H
> >
> > On 9/28/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> >> On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
> >> > Garrett -
> >> >
> >> > Yeah, shoulda done that to begin with, sorry...OK, from package
> >> > org.apache.abdera.model, interface Feed defines these methods:
> >> >
> >> > List<Entry> getEntries();
> >> > void addEntry(Entry entry);
> >> > ...
> >> > Entry getEntry(String id);
> >> >
> >> > In .NET, I could define these as properties like this:
> >> >
> >> > List<Entry> Entries {
> >> >   get;
> >> >   set;
> >> > }
> >> >
> >> > And then, normally, I would use the methods exposed by List<Entry> to
> >> > perform operations on the Entries (add, remove, etc.).  Now, granted,
> >> > I would have to implement a method to retrieve the entry by ID just as
> >> > done above.  But I guess my question may be centered around the
> >> > encapsulation standards across the languages?  Maybe?
> >> >
> >> > Does that clarify any?  If not, let me know.
> >>
> >> Well, you'd definately want the getter for the entries, but setting an
> >> entire list of entries is kind of weird IMO...  Perhaps other people
> >> have optinions.
> >>
> >> -garrett
> >>
> >
>

Re: Coding/Language Standards

Posted by James M Snell <ja...@gmail.com>.
The List<?> methods exist mainly to support easy iteration and getting
of the entries.  They are unmodifiable lists, meaning that calling any
of the add/remove operations will result in an unsupported operation
exception.

- James

Harris Boyce III wrote:
> Right and I think this is where the rub lies.  I've been "brought-up"
> that, unless the data is read-only, you just generally implement
> read/write properties so I can easily implement it as:
> 
> List<Entry> Entries {
>  get;
> }
> 
> But even with that, nothing prevents the user accessing the feed from
> calling theFeed.Entries.Add(someEntry);  Now, the implementation could
> return a read-only List and then any modifying operations would
> generate exceptions.  But...why would I do that?
> 
> Does that make any sense?  I'm hoping that this doesn't seem like an
> immature conversation, but it's one that I struggle with when I study
> Java.  Why wouldn't I just use those conveience methods to modify the
> list if and when I need to do so?
> 
> Thanks again for the discussion!  I'm learning lots!
> 
> H
> 
> On 9/28/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
>> On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
>> > Garrett -
>> >
>> > Yeah, shoulda done that to begin with, sorry...OK, from package
>> > org.apache.abdera.model, interface Feed defines these methods:
>> >
>> > List<Entry> getEntries();
>> > void addEntry(Entry entry);
>> > ...
>> > Entry getEntry(String id);
>> >
>> > In .NET, I could define these as properties like this:
>> >
>> > List<Entry> Entries {
>> >   get;
>> >   set;
>> > }
>> >
>> > And then, normally, I would use the methods exposed by List<Entry> to
>> > perform operations on the Entries (add, remove, etc.).  Now, granted,
>> > I would have to implement a method to retrieve the entry by ID just as
>> > done above.  But I guess my question may be centered around the
>> > encapsulation standards across the languages?  Maybe?
>> >
>> > Does that clarify any?  If not, let me know.
>>
>> Well, you'd definately want the getter for the entries, but setting an
>> entire list of entries is kind of weird IMO...  Perhaps other people
>> have optinions.
>>
>> -garrett
>>
> 

Re: Coding/Language Standards

Posted by Harris Boyce III <ha...@gmail.com>.
Right and I think this is where the rub lies.  I've been "brought-up"
that, unless the data is read-only, you just generally implement
read/write properties so I can easily implement it as:

List<Entry> Entries {
  get;
}

But even with that, nothing prevents the user accessing the feed from
calling theFeed.Entries.Add(someEntry);  Now, the implementation could
return a read-only List and then any modifying operations would
generate exceptions.  But...why would I do that?

Does that make any sense?  I'm hoping that this doesn't seem like an
immature conversation, but it's one that I struggle with when I study
Java.  Why wouldn't I just use those conveience methods to modify the
list if and when I need to do so?

Thanks again for the discussion!  I'm learning lots!

H

On 9/28/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
> > Garrett -
> >
> > Yeah, shoulda done that to begin with, sorry...OK, from package
> > org.apache.abdera.model, interface Feed defines these methods:
> >
> > List<Entry> getEntries();
> > void addEntry(Entry entry);
> > ...
> > Entry getEntry(String id);
> >
> > In .NET, I could define these as properties like this:
> >
> > List<Entry> Entries {
> >   get;
> >   set;
> > }
> >
> > And then, normally, I would use the methods exposed by List<Entry> to
> > perform operations on the Entries (add, remove, etc.).  Now, granted,
> > I would have to implement a method to retrieve the entry by ID just as
> > done above.  But I guess my question may be centered around the
> > encapsulation standards across the languages?  Maybe?
> >
> > Does that clarify any?  If not, let me know.
>
> Well, you'd definately want the getter for the entries, but setting an
> entire list of entries is kind of weird IMO...  Perhaps other people
> have optinions.
>
> -garrett
>

Re: Coding/Language Standards

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
> Garrett -
>
> Yeah, shoulda done that to begin with, sorry...OK, from package
> org.apache.abdera.model, interface Feed defines these methods:
>
> List<Entry> getEntries();
> void addEntry(Entry entry);
> ...
> Entry getEntry(String id);
>
> In .NET, I could define these as properties like this:
>
> List<Entry> Entries {
>   get;
>   set;
> }
>
> And then, normally, I would use the methods exposed by List<Entry> to
> perform operations on the Entries (add, remove, etc.).  Now, granted,
> I would have to implement a method to retrieve the entry by ID just as
> done above.  But I guess my question may be centered around the
> encapsulation standards across the languages?  Maybe?
>
> Does that clarify any?  If not, let me know.

Well, you'd definately want the getter for the entries, but setting an
entire list of entries is kind of weird IMO...  Perhaps other people
have optinions.

-garrett

Re: Coding/Language Standards

Posted by Harris Boyce III <ha...@gmail.com>.
Garrett -

Yeah, shoulda done that to begin with, sorry...OK, from package
org.apache.abdera.model, interface Feed defines these methods:

List<Entry> getEntries();
void addEntry(Entry entry);
...
Entry getEntry(String id);

In .NET, I could define these as properties like this:

List<Entry> Entries {
  get;
  set;
}

And then, normally, I would use the methods exposed by List<Entry> to
perform operations on the Entries (add, remove, etc.).  Now, granted,
I would have to implement a method to retrieve the entry by ID just as
done above.  But I guess my question may be centered around the
encapsulation standards across the languages?  Maybe?

Does that clarify any?  If not, let me know.

Thanks,

H

On 9/28/06, Garrett Rooney <ro...@electricjellyfish.net> wrote:
> On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
> > I am looking to have a brief discussion about coding standards in Java
> > and .NET and how they are/should be applied on this project.
> >
> > While studying the code for this project, and other Java porgrams as
> > well, I'm not sure that I understand the premises behind getters and
> > setters and list operation methods (AddEntry, RemoveEntry, etc.).  In
> > .NET, the concept of properties allows the compilers to automatically
> > generate getter and setter methods in-place of what appears to be
> > regular public fields.  What I don't necessarily understand is why
> > list operations are added to objects when the getters and setters
> > expose the list/collection types?  I don't know if this is just a
> > nuance of Java and that .NET developers just don't follow these
> > practices, but I am hoping to receive some insight as to why this
> > practice is followed and whether or not I should do the same in the
> > .NET implemenation of Abdera.
>
> Perhaps your question would be easier to understand if you pointed us
> to a specific example in the code...
>
> -garrett
>

Re: Coding/Language Standards

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 9/28/06, Harris Boyce III <ha...@gmail.com> wrote:
> I am looking to have a brief discussion about coding standards in Java
> and .NET and how they are/should be applied on this project.
>
> While studying the code for this project, and other Java porgrams as
> well, I'm not sure that I understand the premises behind getters and
> setters and list operation methods (AddEntry, RemoveEntry, etc.).  In
> .NET, the concept of properties allows the compilers to automatically
> generate getter and setter methods in-place of what appears to be
> regular public fields.  What I don't necessarily understand is why
> list operations are added to objects when the getters and setters
> expose the list/collection types?  I don't know if this is just a
> nuance of Java and that .NET developers just don't follow these
> practices, but I am hoping to receive some insight as to why this
> practice is followed and whether or not I should do the same in the
> .NET implemenation of Abdera.

Perhaps your question would be easier to understand if you pointed us
to a specific example in the code...

-garrett