4 ms·
> Nor is structuring every module even if it's completely stateless as a class, just to benefit from IDE driven development a reasonable price to pay. That's a
by still_grokking 4y ago
> Nor is structuring every module even if it's completely stateless as a class, just to benefit from IDE driven development a reasonable price to pay.
That's a question of language.
object SomeModule:
def someMethod(someRandomNumber: 42) =
s"The answer is: $someRandomNumber."
def someOtherMethod = someMethod(42)
@main def entryPoint =
val someTheory = SomeModule.someMethod(23)
import SomeModule.someOtherMethod
import StringExtension.*
(someOtherMethod :: "No!" :: someTheory :: Nil)
.fold("")(_ + _ + "\n")
.printLine()
object StringExtension:
extension (s: String) def printLine() = println(s)
// Because methods compose better in a fluent style…
// You don't need to read your code backwards!
https://scastie.scala-lang.org/Zt6xTucJRyK1IEQQgFNRLQ https://scastie.scala-lang.org/Zt6xTucJRyK1IEQQgFNRLQ
That's Scala.
Two cute stateless modules. Nicely wrapped in singletons.
Not quite sure why I had to add the handy `printLine()` method to the String class myself, after the fact…
But as extending arbitrary classes with new methods without touching them is trivial, who cares.
(Frankly it does not compile. It says something like `Found: (23 : Int); Required: (42 : Int)`. No clue)