flink-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jinkui Shi <shijinkui...@163.com>
Subject Re: [Discuss] Declare class field's type in scala class field
Date Fri, 27 Jan 2017 08:21:47 GMT
Hi, Till, Bruno

Thank for your reply.

Twitter’s scala programming suggestion is useful. I prefer the alexandru/scala-best-practices.


Like this rule `2.16. Public functions SHOULD have an explicit return type`, the class field
type explicitly declaring is better for developer to read.

[1] https://github.com/alexandru/scala-best-practices/blob/master/sections/2-language-rules.md#216-public-functions-should-have-an-explicit-return-type
<https://github.com/alexandru/scala-best-practices/blob/master/sections/2-language-rules.md#216-public-functions-should-have-an-explicit-return-type>

Thanks
Jinkui Shi

> On Jan 27, 2017, at 02:33, Bruno Aranda <brunoaranda@gmail.com> wrote:
> 
> Hi,
> 
> Twitter's Effective Scala contains very well-known and accepted conventions
> for Scala:
> 
> http://twitter.github.io/effectivescala/
> 
> Cheers,
> 
> Bruno
> 
> On Thu, 26 Jan 2017 at 14:16 Till Rohrmann <trohrmann@apache.org> wrote:
> 
>> Agreed. I think it's a good idea to annotate the code with as much
>> information as possible to help other people to understand it. I think it's
>> a good idea to include this information in the coding guidelines. But I'm
>> not sure whether we have a dedicated Scala coding guideline.
>> 
>> Cheers,
>> Till
>> 
>> On Thu, Jan 26, 2017 at 10:27 AM, Jinkui Shi <shijinkui666@163.com> wrote:
>> 
>>> hi, all
>>> 
>>> Scala can infer the actual type if we didn’t declare its type. There also
>>> nothing different in the byte code of java class format.
>>> It’s convenient for write the code, but hard to read. Maybe it’s time to
>>> face such bad smell code.
>>> Scala check style plugin also have such rule. We can add this to the code
>>> guidelines.
>>> 
>>> So I have a proposal: Declare all the class field with its type as far as
>>> possible in Scala code. The variate in the function can be ignore if
>>> necessary.
>>> 
>>> What do you think about this?
>>> 
>>> The test below to show that declare type and type inference are the same
>>> after compiling.
>>> 
>>> Thanks
>>> Jinkui Shi
>>> 
>>> ------------------------------------------------------------
>>> --------------------------------------
>>> 
>>> object DeclareTypeTest {
>>> 
>>>  def main(args: Array[String]): Unit = {
>>>    //  1
>>>    declareTypeFunction
>>>    //  2
>>>    undeclareTypeFunction
>>>  }
>>> 
>>>  def declareTypeFunction: Int = {
>>>    1
>>>  }
>>> 
>>>  def undeclareTypeFunction: Int = {
>>>    1
>>>  }
>>> }
>>> 
>>> 
>>> java -c DeclareTypeTest$.class :
>>> 
>>>  public void main(java.lang.String[]);
>>>    Code:
>>>       0: aload_0
>>>       1: invokevirtual #18                 // Method
>>> declareTypeFunction:()I
>>>       4: pop
>>>       5: aload_0
>>>       6: invokevirtual #21                 // Method
>>> undeclareTypeFunction:()I
>>>       9: pop
>>>      10: return
>>> 
>>>  public int declareTypeFunction();
>>>    Code:
>>>       0: iconst_1
>>>       1: ireturn
>>> 
>>>  public int undeclareTypeFunction();
>>>    Code:
>>>       0: iconst_1
>>>       1: ireturn
>>> 
>>> 
>>> 
>> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message