Scala naming scheme

In Haskell, when I need a fast working function or helper value, I usually use simple ( ' ), which is widely used in mathematics. For example, if I were to write a reverse function and needed to work with a tail-recursive, I would call it reverse' .

In Scala, function names cannot contain ' . Is there a common naming scheme for helper functions and values ​​in Scala?

+7
source share
2 answers

Why don't you declare a method inside the method that uses it? Then you can simply call him β€œhelper” or whatever you like, without worrying about name conflicts.

 scala> def reverse[A](l:List[A]) = { | def helper(acc:List[A],rest:List[A]):List[A] = rest match { | case Nil => acc | case x::xs => helper(x::acc, xs) | } | helper(Nil, l) | } reverse: [A](l: List[A])List[A] scala> reverse(1::2::3::Nil) res0: List[Int] = List(3, 2, 1) 
+13
source

If I remember well the Martin Odersky programming course I took in 2004, I think that he used the suffix 0 for auxiliary functions defined in the body of the main function.

 def reverse(...) = { def reverse0(...) = { // ... } reverse0(...) } 
+6
source

All Articles