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 <shijinkui...@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 > > >