Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Mridul Muralidharan
You are right.
A degenerate case would be :

def createFoo = new FooImpl()

vs

def createFoo: Foo = new FooImpl()

Former will cause api instability. Reynold, maybe this is already
avoided - and I understood it wrong ?

Thanks,
Mridul



On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen c...@adatao.com wrote:
 Mridul, IIUUC, what you've mentioned did come to mind, but I deemed it
 orthogonal to the stylistic issue Reynold is talking about.

 I believe you're referring to the case where there is a specific desired
 return type by API design, but the implementation does not, in which case,
 of course, one must define the return type. That's an API requirement and
 not just a matter of readability.

 We could add this as an NB in the proposed guideline.

 --
 Christopher T. Nguyen
 Co-founder  CEO, Adatao http://adatao.com
 linkedin.com/in/ctnguyen



 On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin r...@databricks.com wrote:

 +1 Christopher's suggestion.

 Mridul,

 How would that happen? Case 3 requires the method to be invoking the
 constructor directly. It was implicit in my email, but the return type
 should be the same as the class itself.




 On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan mri...@gmail.com
 wrote:

  Case 3 can be a potential issue.
  Current implementation might be returning a concrete class which we
  might want to change later - making it a type change.
  The intention might be to return an RDD (for example), but the
  inferred type might be a subclass of RDD - and future changes will
  cause signature change.
 
 
  Regards,
  Mridul
 
 
  On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin r...@databricks.com
 wrote:
   Hi guys,
  
   Want to bring to the table this issue to see what other members of the
   community think and then we can codify it in the Spark coding style
  guide.
   The topic is about declaring return types explicitly in public APIs.
  
   In general I think we should favor explicit type declaration in public
   APIs. However, I do think there are 3 cases we can avoid the public API
   definition because in these 3 cases the types are self-evident 
  repetitive.
  
   Case 1. toString
  
   Case 2. A method returning a string or a val defining a string
  
   def name = abcd // this is so obvious that it is a string
   val name = edfg // this too
  
   Case 3. The method or variable is invoking the constructor of a class
 and
   return that immediately. For example:
  
   val a = new SparkContext(...)
   implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) = new
   AsyncRDDActions(rdd)
  
  
   Thoughts?
 



Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Patrick Wendell
+1 overall.

Christopher - I agree that once the number of rules becomes large it's
more efficient to pursue a use your judgement approach. However,
since this is only 3 cases I'd prefer to wait to see if it grows.

The concern with this approach is that for newer people, contributors,
etc it's hard for them to understand what good judgement is. Many are
new to scala, so explicit rules are generally better.

- Patrick

On Wed, Feb 19, 2014 at 12:19 AM, Reynold Xin r...@databricks.com wrote:
 Yes, the case you brought up is not a matter of readability or style. If it
 returns a different type, it should be declared (otherwise it is just
 wrong).


 On Wed, Feb 19, 2014 at 12:17 AM, Mridul Muralidharan mri...@gmail.comwrote:

 You are right.
 A degenerate case would be :

 def createFoo = new FooImpl()

 vs

 def createFoo: Foo = new FooImpl()

 Former will cause api instability. Reynold, maybe this is already
 avoided - and I understood it wrong ?

 Thanks,
 Mridul



 On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen c...@adatao.com
 wrote:
  Mridul, IIUUC, what you've mentioned did come to mind, but I deemed it
  orthogonal to the stylistic issue Reynold is talking about.
 
  I believe you're referring to the case where there is a specific desired
  return type by API design, but the implementation does not, in which
 case,
  of course, one must define the return type. That's an API requirement and
  not just a matter of readability.
 
  We could add this as an NB in the proposed guideline.
 
  --
  Christopher T. Nguyen
  Co-founder  CEO, Adatao http://adatao.com
  linkedin.com/in/ctnguyen
 
 
 
  On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin r...@databricks.com
 wrote:
 
  +1 Christopher's suggestion.
 
  Mridul,
 
  How would that happen? Case 3 requires the method to be invoking the
  constructor directly. It was implicit in my email, but the return type
  should be the same as the class itself.
 
 
 
 
  On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan mri...@gmail.com
  wrote:
 
   Case 3 can be a potential issue.
   Current implementation might be returning a concrete class which we
   might want to change later - making it a type change.
   The intention might be to return an RDD (for example), but the
   inferred type might be a subclass of RDD - and future changes will
   cause signature change.
  
  
   Regards,
   Mridul
  
  
   On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin r...@databricks.com
  wrote:
Hi guys,
   
Want to bring to the table this issue to see what other members of
 the
community think and then we can codify it in the Spark coding style
   guide.
The topic is about declaring return types explicitly in public APIs.
   
In general I think we should favor explicit type declaration in
 public
APIs. However, I do think there are 3 cases we can avoid the public
 API
definition because in these 3 cases the types are self-evident 
   repetitive.
   
Case 1. toString
   
Case 2. A method returning a string or a val defining a string
   
def name = abcd // this is so obvious that it is a string
val name = edfg // this too
   
Case 3. The method or variable is invoking the constructor of a
 class
  and
return that immediately. For example:
   
val a = new SparkContext(...)
implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) = new
AsyncRDDActions(rdd)
   
   
Thoughts?
  
 



Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Christopher Nguyen
Patrick, I sympathize with your sensibility here, and at face value,
there's very little daylight between (a) a rule comprising small set of
enumerated items and (b) a guideline followed by the same set as examples.

My suggestion had a non-obvious tl;dr thesis behind it, so allow me to show
my cards :)

First, rules can be costly for the rule makers to create and maintain to
ensure necessity and sufficiency, and can unintentionally encourage
mischievous, often tedious arguments to work around those rules. In the
area of coding style, even at Google (at least when I was there), we had
guides rather than rules. It turns out that guidelines are also easier to
socialize and enforce than enumerated rules. strawman_humorA Google
search for coding style guide returns 15.7 million results, while that
for coding style rule has 6.6M, and most of *those* are articles about
coding style guide./strawman_humor

More importantly, I've found Spark's to be one of the best
socially-engineered communities I've participated in. It is quite helpful
and welcoming to newcomers while (not paradoxically) comprising one of the
highest median quality of participants, per my calibration of, e.g., the
various meetups I've gone to in the SF Bay Area. This community
friendliness and mutual regard are not accidental and have contributed in
part to Spark's success to date. It seems quite tolerant of newbies and
implicitly recognizes that there may be a lot of valuable expertise and
interesting use cases we can learn from the person behind that
idiotic-sounding question, who might go on to contribute valuable PRs. I've
yet to see the acronym RTFM used in anger here. Now, rules don't
automatically negate that, but they can be discouraging to navigate (Have
I broken some rule?) and misused as devices to shoot others (You've just
broken our rule #178.S4.P2). I'd rather see those things kept to a minimum,
in locked cabinets.

For the above reasons, I would suggest, for Spark, guidelines over rules
whenever feasible  tolerable, certainly in the area of coding style.

Cheers,
--
Christopher T. Nguyen
Co-founder  CEO, Adatao http://adatao.com
linkedin.com/in/ctnguyen



On Wed, Feb 19, 2014 at 8:37 AM, Patrick Wendell pwend...@gmail.com wrote:

 +1 overall.

 Christopher - I agree that once the number of rules becomes large it's
 more efficient to pursue a use your judgement approach. However,
 since this is only 3 cases I'd prefer to wait to see if it grows.

 The concern with this approach is that for newer people, contributors,
 etc it's hard for them to understand what good judgement is. Many are
 new to scala, so explicit rules are generally better.

 - Patrick

 On Wed, Feb 19, 2014 at 12:19 AM, Reynold Xin r...@databricks.com wrote:
  Yes, the case you brought up is not a matter of readability or style. If
 it
  returns a different type, it should be declared (otherwise it is just
  wrong).
 
 
  On Wed, Feb 19, 2014 at 12:17 AM, Mridul Muralidharan mri...@gmail.com
 wrote:
 
  You are right.
  A degenerate case would be :
 
  def createFoo = new FooImpl()
 
  vs
 
  def createFoo: Foo = new FooImpl()
 
  Former will cause api instability. Reynold, maybe this is already
  avoided - and I understood it wrong ?
 
  Thanks,
  Mridul
 
 
 
  On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen c...@adatao.com
  wrote:
   Mridul, IIUUC, what you've mentioned did come to mind, but I deemed it
   orthogonal to the stylistic issue Reynold is talking about.
  
   I believe you're referring to the case where there is a specific
 desired
   return type by API design, but the implementation does not, in which
  case,
   of course, one must define the return type. That's an API requirement
 and
   not just a matter of readability.
  
   We could add this as an NB in the proposed guideline.
  
   --
   Christopher T. Nguyen
   Co-founder  CEO, Adatao http://adatao.com
   linkedin.com/in/ctnguyen
  
  
  
   On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin r...@databricks.com
  wrote:
  
   +1 Christopher's suggestion.
  
   Mridul,
  
   How would that happen? Case 3 requires the method to be invoking the
   constructor directly. It was implicit in my email, but the return
 type
   should be the same as the class itself.
  
  
  
  
   On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan 
 mri...@gmail.com
   wrote:
  
Case 3 can be a potential issue.
Current implementation might be returning a concrete class which we
might want to change later - making it a type change.
The intention might be to return an RDD (for example), but the
inferred type might be a subclass of RDD - and future changes will
cause signature change.
   
   
Regards,
Mridul
   
   
On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin r...@databricks.com
 
   wrote:
 Hi guys,

 Want to bring to the table this issue to see what other members
 of
  the
 community think and then we can codify it in the Spark coding
 style
guide.
 The 

Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Mridul Muralidharan
Without bikeshedding this too much ... It is likely incorrect (not wrong) -
and rules like this potentially cause things to slip through.

Explicit return type strictly specifies what is being exposed (think in
face of impl change - createFoo changes in future from Foo to Foo1 or Foo2)
.. being conservative about how to specify exposed interfaces, imo,
outweighs potential gains in breveity of code.
Btw this is a degenerate contrieved example already stretching its use ...

Regards
Mridul

Regards
Mridul
On Feb 19, 2014 1:49 PM, Reynold Xin r...@databricks.com wrote:

 Yes, the case you brought up is not a matter of readability or style. If it
 returns a different type, it should be declared (otherwise it is just
 wrong).


 On Wed, Feb 19, 2014 at 12:17 AM, Mridul Muralidharan mri...@gmail.com
 wrote:

  You are right.
  A degenerate case would be :
 
  def createFoo = new FooImpl()
 
  vs
 
  def createFoo: Foo = new FooImpl()
 
  Former will cause api instability. Reynold, maybe this is already
  avoided - and I understood it wrong ?
 
  Thanks,
  Mridul
 
 
 
  On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen c...@adatao.com
  wrote:
   Mridul, IIUUC, what you've mentioned did come to mind, but I deemed it
   orthogonal to the stylistic issue Reynold is talking about.
  
   I believe you're referring to the case where there is a specific
 desired
   return type by API design, but the implementation does not, in which
  case,
   of course, one must define the return type. That's an API requirement
 and
   not just a matter of readability.
  
   We could add this as an NB in the proposed guideline.
  
   --
   Christopher T. Nguyen
   Co-founder  CEO, Adatao http://adatao.com
   linkedin.com/in/ctnguyen
  
  
  
   On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin r...@databricks.com
  wrote:
  
   +1 Christopher's suggestion.
  
   Mridul,
  
   How would that happen? Case 3 requires the method to be invoking the
   constructor directly. It was implicit in my email, but the return type
   should be the same as the class itself.
  
  
  
  
   On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan 
 mri...@gmail.com
   wrote:
  
Case 3 can be a potential issue.
Current implementation might be returning a concrete class which we
might want to change later - making it a type change.
The intention might be to return an RDD (for example), but the
inferred type might be a subclass of RDD - and future changes will
cause signature change.
   
   
Regards,
Mridul
   
   
On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin r...@databricks.com
   wrote:
 Hi guys,

 Want to bring to the table this issue to see what other members of
  the
 community think and then we can codify it in the Spark coding
 style
guide.
 The topic is about declaring return types explicitly in public
 APIs.

 In general I think we should favor explicit type declaration in
  public
 APIs. However, I do think there are 3 cases we can avoid the
 public
  API
 definition because in these 3 cases the types are self-evident 
repetitive.

 Case 1. toString

 Case 2. A method returning a string or a val defining a string

 def name = abcd // this is so obvious that it is a string
 val name = edfg // this too

 Case 3. The method or variable is invoking the constructor of a
  class
   and
 return that immediately. For example:

 val a = new SparkContext(...)
 implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) = new
 AsyncRDDActions(rdd)


 Thoughts?
   
  
 



Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Aaron Davidson
One slight concern regarding primitive types -- in particular, Ints and
Longs can have semantic differences when it comes to overflow, so it's
often good to know what type of variable you're returning. Perhaps it is
sufficient to say that Int is the default numeric type, and that other
types should be specified explicitly.


On Wed, Feb 19, 2014 at 8:37 AM, Patrick Wendell pwend...@gmail.com wrote:

 +1 overall.

 Christopher - I agree that once the number of rules becomes large it's
 more efficient to pursue a use your judgement approach. However,
 since this is only 3 cases I'd prefer to wait to see if it grows.

 The concern with this approach is that for newer people, contributors,
 etc it's hard for them to understand what good judgement is. Many are
 new to scala, so explicit rules are generally better.

 - Patrick

 On Wed, Feb 19, 2014 at 12:19 AM, Reynold Xin r...@databricks.com wrote:
  Yes, the case you brought up is not a matter of readability or style. If
 it
  returns a different type, it should be declared (otherwise it is just
  wrong).
 
 
  On Wed, Feb 19, 2014 at 12:17 AM, Mridul Muralidharan mri...@gmail.com
 wrote:
 
  You are right.
  A degenerate case would be :
 
  def createFoo = new FooImpl()
 
  vs
 
  def createFoo: Foo = new FooImpl()
 
  Former will cause api instability. Reynold, maybe this is already
  avoided - and I understood it wrong ?
 
  Thanks,
  Mridul
 
 
 
  On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen c...@adatao.com
  wrote:
   Mridul, IIUUC, what you've mentioned did come to mind, but I deemed it
   orthogonal to the stylistic issue Reynold is talking about.
  
   I believe you're referring to the case where there is a specific
 desired
   return type by API design, but the implementation does not, in which
  case,
   of course, one must define the return type. That's an API requirement
 and
   not just a matter of readability.
  
   We could add this as an NB in the proposed guideline.
  
   --
   Christopher T. Nguyen
   Co-founder  CEO, Adatao http://adatao.com
   linkedin.com/in/ctnguyen
  
  
  
   On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin r...@databricks.com
  wrote:
  
   +1 Christopher's suggestion.
  
   Mridul,
  
   How would that happen? Case 3 requires the method to be invoking the
   constructor directly. It was implicit in my email, but the return
 type
   should be the same as the class itself.
  
  
  
  
   On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan 
 mri...@gmail.com
   wrote:
  
Case 3 can be a potential issue.
Current implementation might be returning a concrete class which we
might want to change later - making it a type change.
The intention might be to return an RDD (for example), but the
inferred type might be a subclass of RDD - and future changes will
cause signature change.
   
   
Regards,
Mridul
   
   
On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin r...@databricks.com
 
   wrote:
 Hi guys,

 Want to bring to the table this issue to see what other members
 of
  the
 community think and then we can codify it in the Spark coding
 style
guide.
 The topic is about declaring return types explicitly in public
 APIs.

 In general I think we should favor explicit type declaration in
  public
 APIs. However, I do think there are 3 cases we can avoid the
 public
  API
 definition because in these 3 cases the types are self-evident 
repetitive.

 Case 1. toString

 Case 2. A method returning a string or a val defining a string

 def name = abcd // this is so obvious that it is a string
 val name = edfg // this too

 Case 3. The method or variable is invoking the constructor of a
  class
   and
 return that immediately. For example:

 val a = new SparkContext(...)
 implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) = new
 AsyncRDDActions(rdd)


 Thoughts?
   
  
 



Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Reynold Xin
Mridul,

Can you be more specific in the createFoo example?

def myFunc = createFoo

is disallowed in my guideline. It is invoking a function createFoo, not the
constructor of Foo.




On Wed, Feb 19, 2014 at 10:39 AM, Mridul Muralidharan mri...@gmail.comwrote:

 Without bikeshedding this too much ... It is likely incorrect (not wrong) -
 and rules like this potentially cause things to slip through.

 Explicit return type strictly specifies what is being exposed (think in
 face of impl change - createFoo changes in future from Foo to Foo1 or Foo2)
 .. being conservative about how to specify exposed interfaces, imo,
 outweighs potential gains in breveity of code.
 Btw this is a degenerate contrieved example already stretching its use ...

 Regards
 Mridul

 Regards
 Mridul
 On Feb 19, 2014 1:49 PM, Reynold Xin r...@databricks.com wrote:

  Yes, the case you brought up is not a matter of readability or style. If
 it
  returns a different type, it should be declared (otherwise it is just
  wrong).
 
 
  On Wed, Feb 19, 2014 at 12:17 AM, Mridul Muralidharan mri...@gmail.com
  wrote:
 
   You are right.
   A degenerate case would be :
  
   def createFoo = new FooImpl()
  
   vs
  
   def createFoo: Foo = new FooImpl()
  
   Former will cause api instability. Reynold, maybe this is already
   avoided - and I understood it wrong ?
  
   Thanks,
   Mridul
  
  
  
   On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen c...@adatao.com
   wrote:
Mridul, IIUUC, what you've mentioned did come to mind, but I deemed
 it
orthogonal to the stylistic issue Reynold is talking about.
   
I believe you're referring to the case where there is a specific
  desired
return type by API design, but the implementation does not, in which
   case,
of course, one must define the return type. That's an API requirement
  and
not just a matter of readability.
   
We could add this as an NB in the proposed guideline.
   
--
Christopher T. Nguyen
Co-founder  CEO, Adatao http://adatao.com
linkedin.com/in/ctnguyen
   
   
   
On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin r...@databricks.com
   wrote:
   
+1 Christopher's suggestion.
   
Mridul,
   
How would that happen? Case 3 requires the method to be invoking the
constructor directly. It was implicit in my email, but the return
 type
should be the same as the class itself.
   
   
   
   
On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan 
  mri...@gmail.com
wrote:
   
 Case 3 can be a potential issue.
 Current implementation might be returning a concrete class which
 we
 might want to change later - making it a type change.
 The intention might be to return an RDD (for example), but the
 inferred type might be a subclass of RDD - and future changes will
 cause signature change.


 Regards,
 Mridul


 On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin 
 r...@databricks.com
wrote:
  Hi guys,
 
  Want to bring to the table this issue to see what other members
 of
   the
  community think and then we can codify it in the Spark coding
  style
 guide.
  The topic is about declaring return types explicitly in public
  APIs.
 
  In general I think we should favor explicit type declaration in
   public
  APIs. However, I do think there are 3 cases we can avoid the
  public
   API
  definition because in these 3 cases the types are self-evident 
 repetitive.
 
  Case 1. toString
 
  Case 2. A method returning a string or a val defining a string
 
  def name = abcd // this is so obvious that it is a string
  val name = edfg // this too
 
  Case 3. The method or variable is invoking the constructor of a
   class
and
  return that immediately. For example:
 
  val a = new SparkContext(...)
  implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) =
 new
  AsyncRDDActions(rdd)
 
 
  Thoughts?

   
  
 



Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Andrew Ash
I found Haskell's convention of including type signatures as documentation
to be worthwhile.

http://www.haskell.org/haskellwiki/Type_signatures_as_good_style

I'd support a guideline to include type signatures where they're unclear
but would prefer to leave it quite vague.  In my experience, the lightest
process is the best process for contributions.  Strict rules here _will_
drive away contributors.


On Wed, Feb 19, 2014 at 10:42 AM, Reynold Xin r...@databricks.com wrote:

 Mridul,

 Can you be more specific in the createFoo example?

 def myFunc = createFoo

 is disallowed in my guideline. It is invoking a function createFoo, not the
 constructor of Foo.




 On Wed, Feb 19, 2014 at 10:39 AM, Mridul Muralidharan mri...@gmail.com
 wrote:

  Without bikeshedding this too much ... It is likely incorrect (not
 wrong) -
  and rules like this potentially cause things to slip through.
 
  Explicit return type strictly specifies what is being exposed (think in
  face of impl change - createFoo changes in future from Foo to Foo1 or
 Foo2)
  .. being conservative about how to specify exposed interfaces, imo,
  outweighs potential gains in breveity of code.
  Btw this is a degenerate contrieved example already stretching its use
 ...
 
  Regards
  Mridul
 
  Regards
  Mridul
  On Feb 19, 2014 1:49 PM, Reynold Xin r...@databricks.com wrote:
 
   Yes, the case you brought up is not a matter of readability or style.
 If
  it
   returns a different type, it should be declared (otherwise it is just
   wrong).
  
  
   On Wed, Feb 19, 2014 at 12:17 AM, Mridul Muralidharan 
 mri...@gmail.com
   wrote:
  
You are right.
A degenerate case would be :
   
def createFoo = new FooImpl()
   
vs
   
def createFoo: Foo = new FooImpl()
   
Former will cause api instability. Reynold, maybe this is already
avoided - and I understood it wrong ?
   
Thanks,
Mridul
   
   
   
On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen c...@adatao.com
 
wrote:
 Mridul, IIUUC, what you've mentioned did come to mind, but I deemed
  it
 orthogonal to the stylistic issue Reynold is talking about.

 I believe you're referring to the case where there is a specific
   desired
 return type by API design, but the implementation does not, in
 which
case,
 of course, one must define the return type. That's an API
 requirement
   and
 not just a matter of readability.

 We could add this as an NB in the proposed guideline.

 --
 Christopher T. Nguyen
 Co-founder  CEO, Adatao http://adatao.com
 linkedin.com/in/ctnguyen



 On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin r...@databricks.com
 
wrote:

 +1 Christopher's suggestion.

 Mridul,

 How would that happen? Case 3 requires the method to be invoking
 the
 constructor directly. It was implicit in my email, but the return
  type
 should be the same as the class itself.




 On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan 
   mri...@gmail.com
 wrote:

  Case 3 can be a potential issue.
  Current implementation might be returning a concrete class which
  we
  might want to change later - making it a type change.
  The intention might be to return an RDD (for example), but the
  inferred type might be a subclass of RDD - and future changes
 will
  cause signature change.
 
 
  Regards,
  Mridul
 
 
  On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin 
  r...@databricks.com
 wrote:
   Hi guys,
  
   Want to bring to the table this issue to see what other
 members
  of
the
   community think and then we can codify it in the Spark coding
   style
  guide.
   The topic is about declaring return types explicitly in public
   APIs.
  
   In general I think we should favor explicit type declaration
 in
public
   APIs. However, I do think there are 3 cases we can avoid the
   public
API
   definition because in these 3 cases the types are
 self-evident 
  repetitive.
  
   Case 1. toString
  
   Case 2. A method returning a string or a val defining a string
  
   def name = abcd // this is so obvious that it is a string
   val name = edfg // this too
  
   Case 3. The method or variable is invoking the constructor of
 a
class
 and
   return that immediately. For example:
  
   val a = new SparkContext(...)
   implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) =
  new
   AsyncRDDActions(rdd)
  
  
   Thoughts?
 

   
  
 



Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Mridul Muralidharan
My initial mail had it listed, adding more details here since I assume I am
missing something or not being clear - please note, this is just
illustrative and my scala knowledge is bad :-) (I am trying to draw
parallels from mistakes in java world)

def createFoo = new Foo()

To

def createFoo = new Foo1()

To

def createFoo = new Foo2()

(appropriate inheritance applied - parent Foo).

I am thinking from api evolution and binary compatibility point of view

Regards,
Mridul
On Feb 20, 2014 12:12 AM, Reynold Xin r...@databricks.com wrote:

 Mridul,

 Can you be more specific in the createFoo example?

 def myFunc = createFoo

 is disallowed in my guideline. It is invoking a function createFoo, not the
 constructor of Foo.




 On Wed, Feb 19, 2014 at 10:39 AM, Mridul Muralidharan mri...@gmail.com
 wrote:

  Without bikeshedding this too much ... It is likely incorrect (not
 wrong) -
  and rules like this potentially cause things to slip through.
 
  Explicit return type strictly specifies what is being exposed (think in
  face of impl change - createFoo changes in future from Foo to Foo1 or
 Foo2)
  .. being conservative about how to specify exposed interfaces, imo,
  outweighs potential gains in breveity of code.
  Btw this is a degenerate contrieved example already stretching its use
 ...
 
  Regards
  Mridul
 
  Regards
  Mridul
  On Feb 19, 2014 1:49 PM, Reynold Xin r...@databricks.com wrote:
 
   Yes, the case you brought up is not a matter of readability or style.
 If
  it
   returns a different type, it should be declared (otherwise it is just
   wrong).
  
  
   On Wed, Feb 19, 2014 at 12:17 AM, Mridul Muralidharan 
 mri...@gmail.com
   wrote:
  
You are right.
A degenerate case would be :
   
def createFoo = new FooImpl()
   
vs
   
def createFoo: Foo = new FooImpl()
   
Former will cause api instability. Reynold, maybe this is already
avoided - and I understood it wrong ?
   
Thanks,
Mridul
   
   
   
On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen c...@adatao.com
 
wrote:
 Mridul, IIUUC, what you've mentioned did come to mind, but I deemed
  it
 orthogonal to the stylistic issue Reynold is talking about.

 I believe you're referring to the case where there is a specific
   desired
 return type by API design, but the implementation does not, in
 which
case,
 of course, one must define the return type. That's an API
 requirement
   and
 not just a matter of readability.

 We could add this as an NB in the proposed guideline.

 --
 Christopher T. Nguyen
 Co-founder  CEO, Adatao http://adatao.com
 linkedin.com/in/ctnguyen



 On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin r...@databricks.com
 
wrote:

 +1 Christopher's suggestion.

 Mridul,

 How would that happen? Case 3 requires the method to be invoking
 the
 constructor directly. It was implicit in my email, but the return
  type
 should be the same as the class itself.




 On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan 
   mri...@gmail.com
 wrote:

  Case 3 can be a potential issue.
  Current implementation might be returning a concrete class which
  we
  might want to change later - making it a type change.
  The intention might be to return an RDD (for example), but the
  inferred type might be a subclass of RDD - and future changes
 will
  cause signature change.
 
 
  Regards,
  Mridul
 
 
  On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin 
  r...@databricks.com
 wrote:
   Hi guys,
  
   Want to bring to the table this issue to see what other
 members
  of
the
   community think and then we can codify it in the Spark coding
   style
  guide.
   The topic is about declaring return types explicitly in public
   APIs.
  
   In general I think we should favor explicit type declaration
 in
public
   APIs. However, I do think there are 3 cases we can avoid the
   public
API
   definition because in these 3 cases the types are
 self-evident 
  repetitive.
  
   Case 1. toString
  
   Case 2. A method returning a string or a val defining a string
  
   def name = abcd // this is so obvious that it is a string
   val name = edfg // this too
  
   Case 3. The method or variable is invoking the constructor of
 a
class
 and
   return that immediately. For example:
  
   val a = new SparkContext(...)
   implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) =
  new
   AsyncRDDActions(rdd)
  
  
   Thoughts?
 

   
  
 



Re: coding style discussion: explicit return type in public APIs

2014-02-19 Thread Mridul Muralidharan
I agree, makes sense.
Please note I was referring only to exposed user api in my comments - not
other code !

Regards,
Mridul
On Feb 20, 2014 12:15 AM, Andrew Ash and...@andrewash.com wrote:

 I found Haskell's convention of including type signatures as documentation
 to be worthwhile.

 http://www.haskell.org/haskellwiki/Type_signatures_as_good_style

 I'd support a guideline to include type signatures where they're unclear
 but would prefer to leave it quite vague.  In my experience, the lightest
 process is the best process for contributions.  Strict rules here _will_
 drive away contributors.


 On Wed, Feb 19, 2014 at 10:42 AM, Reynold Xin r...@databricks.com wrote:

  Mridul,
 
  Can you be more specific in the createFoo example?
 
  def myFunc = createFoo
 
  is disallowed in my guideline. It is invoking a function createFoo, not
 the
  constructor of Foo.
 
 
 
 
  On Wed, Feb 19, 2014 at 10:39 AM, Mridul Muralidharan mri...@gmail.com
  wrote:
 
   Without bikeshedding this too much ... It is likely incorrect (not
  wrong) -
   and rules like this potentially cause things to slip through.
  
   Explicit return type strictly specifies what is being exposed (think in
   face of impl change - createFoo changes in future from Foo to Foo1 or
  Foo2)
   .. being conservative about how to specify exposed interfaces, imo,
   outweighs potential gains in breveity of code.
   Btw this is a degenerate contrieved example already stretching its use
  ...
  
   Regards
   Mridul
  
   Regards
   Mridul
   On Feb 19, 2014 1:49 PM, Reynold Xin r...@databricks.com wrote:
  
Yes, the case you brought up is not a matter of readability or style.
  If
   it
returns a different type, it should be declared (otherwise it is just
wrong).
   
   
On Wed, Feb 19, 2014 at 12:17 AM, Mridul Muralidharan 
  mri...@gmail.com
wrote:
   
 You are right.
 A degenerate case would be :

 def createFoo = new FooImpl()

 vs

 def createFoo: Foo = new FooImpl()

 Former will cause api instability. Reynold, maybe this is already
 avoided - and I understood it wrong ?

 Thanks,
 Mridul



 On Wed, Feb 19, 2014 at 12:44 PM, Christopher Nguyen 
 c...@adatao.com
  
 wrote:
  Mridul, IIUUC, what you've mentioned did come to mind, but I
 deemed
   it
  orthogonal to the stylistic issue Reynold is talking about.
 
  I believe you're referring to the case where there is a specific
desired
  return type by API design, but the implementation does not, in
  which
 case,
  of course, one must define the return type. That's an API
  requirement
and
  not just a matter of readability.
 
  We could add this as an NB in the proposed guideline.
 
  --
  Christopher T. Nguyen
  Co-founder  CEO, Adatao http://adatao.com
  linkedin.com/in/ctnguyen
 
 
 
  On Tue, Feb 18, 2014 at 10:40 PM, Reynold Xin 
 r...@databricks.com
  
 wrote:
 
  +1 Christopher's suggestion.
 
  Mridul,
 
  How would that happen? Case 3 requires the method to be invoking
  the
  constructor directly. It was implicit in my email, but the
 return
   type
  should be the same as the class itself.
 
 
 
 
  On Tue, Feb 18, 2014 at 10:37 PM, Mridul Muralidharan 
mri...@gmail.com
  wrote:
 
   Case 3 can be a potential issue.
   Current implementation might be returning a concrete class
 which
   we
   might want to change later - making it a type change.
   The intention might be to return an RDD (for example), but the
   inferred type might be a subclass of RDD - and future changes
  will
   cause signature change.
  
  
   Regards,
   Mridul
  
  
   On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin 
   r...@databricks.com
  wrote:
Hi guys,
   
Want to bring to the table this issue to see what other
  members
   of
 the
community think and then we can codify it in the Spark
 coding
style
   guide.
The topic is about declaring return types explicitly in
 public
APIs.
   
In general I think we should favor explicit type declaration
  in
 public
APIs. However, I do think there are 3 cases we can avoid the
public
 API
definition because in these 3 cases the types are
  self-evident 
   repetitive.
   
Case 1. toString
   
Case 2. A method returning a string or a val defining a
 string
   
def name = abcd // this is so obvious that it is a string
val name = edfg // this too
   
Case 3. The method or variable is invoking the constructor
 of
  a
 class
  and
return that immediately. For example:
   
val a = new SparkContext(...)
implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T])
 =
   new

Re: coding style discussion: explicit return type in public APIs

2014-02-18 Thread Reynold Xin
Case 2  should probably be expanded to cover most primitive types.


On Tue, Feb 18, 2014 at 10:22 PM, Reynold Xin r...@databricks.com wrote:

 Hi guys,

 Want to bring to the table this issue to see what other members of the
 community think and then we can codify it in the Spark coding style guide.
 The topic is about declaring return types explicitly in public APIs.

 In general I think we should favor explicit type declaration in public
 APIs. However, I do think there are 3 cases we can avoid the public API
 definition because in these 3 cases the types are self-evident  repetitive.

 Case 1. toString

 Case 2. A method returning a string or a val defining a string

 def name = abcd // this is so obvious that it is a string
 val name = edfg // this too

 Case 3. The method or variable is invoking the constructor of a class and
 return that immediately. For example:

 val a = new SparkContext(...)
 implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) = new
 AsyncRDDActions(rdd)


 Thoughts?




Re: coding style discussion: explicit return type in public APIs

2014-02-18 Thread Christopher Nguyen
Reynold, perhaps better than enumerating all the rules, it should be
generalized to a guideline that allows this relaxation when the return type
is immediately obvious from the next few tokens in the code. In exceptional
cases of doubt, provide the return type.

The cases you've listed should serve as examples of the guideline.
--
Christopher T. Nguyen
Co-founder  CEO, Adatao http://adatao.com
linkedin.com/in/ctnguyen



On Tue, Feb 18, 2014 at 10:23 PM, Reynold Xin r...@databricks.com wrote:

 Case 2  should probably be expanded to cover most primitive types.


 On Tue, Feb 18, 2014 at 10:22 PM, Reynold Xin r...@databricks.com wrote:

  Hi guys,
 
  Want to bring to the table this issue to see what other members of the
  community think and then we can codify it in the Spark coding style
 guide.
  The topic is about declaring return types explicitly in public APIs.
 
  In general I think we should favor explicit type declaration in public
  APIs. However, I do think there are 3 cases we can avoid the public API
  definition because in these 3 cases the types are self-evident 
 repetitive.
 
  Case 1. toString
 
  Case 2. A method returning a string or a val defining a string
 
  def name = abcd // this is so obvious that it is a string
  val name = edfg // this too
 
  Case 3. The method or variable is invoking the constructor of a class and
  return that immediately. For example:
 
  val a = new SparkContext(...)
  implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) = new
  AsyncRDDActions(rdd)
 
 
  Thoughts?
 
 



Re: coding style discussion: explicit return type in public APIs

2014-02-18 Thread Mridul Muralidharan
Case 3 can be a potential issue.
Current implementation might be returning a concrete class which we
might want to change later - making it a type change.
The intention might be to return an RDD (for example), but the
inferred type might be a subclass of RDD - and future changes will
cause signature change.


Regards,
Mridul


On Wed, Feb 19, 2014 at 11:52 AM, Reynold Xin r...@databricks.com wrote:
 Hi guys,

 Want to bring to the table this issue to see what other members of the
 community think and then we can codify it in the Spark coding style guide.
 The topic is about declaring return types explicitly in public APIs.

 In general I think we should favor explicit type declaration in public
 APIs. However, I do think there are 3 cases we can avoid the public API
 definition because in these 3 cases the types are self-evident  repetitive.

 Case 1. toString

 Case 2. A method returning a string or a val defining a string

 def name = abcd // this is so obvious that it is a string
 val name = edfg // this too

 Case 3. The method or variable is invoking the constructor of a class and
 return that immediately. For example:

 val a = new SparkContext(...)
 implicit def rddToAsyncRDDActions[T: ClassTag](rdd: RDD[T]) = new
 AsyncRDDActions(rdd)


 Thoughts?