Re: [project lombok] Feature Request

35 views
Skip to first unread message

Fabrizio Giudici

unread,
May 10, 2013, 7:12:18 AM5/10/13
to project...@googlegroups.com, Kshitiz Sharma
On Fri, 10 May 2013 12:44:18 +0200, Kshitiz Sharma
<ksharma...@gmail.com> wrote:

> I am wondering if you folks have plans to include annotations for
> changing
> default accessibility of all members of a class. Something like -
>
> @DefaultScope(methods=private, variables=private)
> class {
> int a;
> String s;
> public Date d;
> }
>
> This would have two advantages -
>
> 1. Makes code concise as you don't have to append private in front of
> every member. For classes with 50-70 members that makes a lot of
> difference.

Classes with 50-70 members are not a good practice per se. I know that
unfortunately they are around, but some verbosity on accessibility is
their least problem.

> 2. Good practice. You don't expose your variables by mistake. This is
> the OSGi approach. Everything is private unless explicitly specified.

This is a bit more meaningful, but you could still write "public"
erroneously, and forget about it. If I had a problem of this kind, I'd
rather use a custom rule of Checkstyle.


--
Fabrizio Giudici - Java Architect @ Tidalwave s.a.s.
"We make Java work. Everywhere."
http://tidalwave.it/fabrizio/blog - fabrizio...@tidalwave.it

Robbert Jan Grootjans

unread,
May 10, 2013, 7:16:02 AM5/10/13
to project...@googlegroups.com
In general, lombok doesn't do a lot of re-writing of existing code, just the generation of boilerplate, based on the context of existing code. I'm not sure how feasible this is.

That said, I'm not enthousiastic (yet) about the idea
1. My classes, in practice, contain 3-7 members, and not 50-70. Unless these are POJO classes for rather large database tables, I don't see this happening this often. Perhaps there are use cases I'm missing.
2. I agree it would be really nice if people would think about the information they expose in their code. Either you do this already, and I'm not sure this tool would help me in this process, or you don't and you won't be adding this annotation anyway.


On Fri, May 10, 2013 at 12:44 PM, Kshitiz Sharma <ksharma...@gmail.com> wrote:
I am wondering if you folks have plans to include annotations for changing default accessibility of all members of a class. Something like - 

@DefaultScope(methods=private, variables=private)
class {
int a;
String s;
public Date d;
}

This would have two advantages - 
  1. Makes code concise as you don't have to append private in front of every member. For classes with 50-70 members that makes a lot of difference.
  1. Good practice. You don't expose your variables by mistake. This is the OSGi approach. Everything is private unless explicitly specified.
    What are your thoughts on this?

    --
    You received this message because you are subscribed to the Google Groups "Project Lombok" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
     
     

    Reinier Zwitserloot

    unread,
    May 10, 2013, 12:28:32 PM5/10/13
    to project-lombok

    Already exists: @lombok.experimental.FieldDefaults

    Reply all
    Reply to author
    Forward
    0 new messages