The strong influence Python has on Scala could already be felt long time ago, before the emergence of Scala 3.0. When using the collections Scala supports, we cannot avoid the deja vu feeling that takes us back to Python. With the emergence of Scala 3.x, many new capabilities and changes were added to Scala and increased its resemblance to Python.
Creating new Objects
class Rectangle(var width:Double,var height:Double)
val rec:Rectangle = Rectangle(3,4)
Define new Classes and Methods
Similar to Python, as of Scala 3.x, you can define new classes, and instead of using curly brackets to create the block, use a uniform space (similar to Python) in each of the lines that make up the block, and add colons to the line before the block. Similarly, uniform spacing can be used in each line as a substitute for using curly brackets, also in the definition of traits and objects. Similarly, you can use uniform spacing in each line as a substitute for using curly brackets, also in the definition of methods.
class Rectangle(var width:Double, var height:Double):
def area():Double =
var result = this.width * this.height
result
def perimeter():Double =
var result = 2 * (this.width + this.height)
result
object RectangleDemo {
def main(args: Array[String]):Unit =
println("testing program")
var rec1:Rectangle = Rectangle(3,4)
print("area of rectangle is ")
print(rec1.area())
}