(a little bit of) Scala in 6 minutes

This can become problematic when functions are dependant on other functions, for example a function that queries a database..It then becomes difficult to test the logic of a single function..If a function is dependant on a function that queries a database, and the unit test for that function fails it becomes difficult to tell if the query to the database failed, or the function logic itself..In scala, we can make use of its function paradigm to isolate dependancies from function logic..Below, the function fake_dependancy simulates a database query that is always successful, and returns a string..The method_that_takes_dependancy function takes in a function (the database query) and returns a new function that contains the logic we need to test..Now, since we know the result of the database query is correct, if we test the function we can be sure we are testing the logic only.Type System FeaturesScala can be classified as a statically typed language with type inference..Scala is compiled using the Java Virtual Machine (JVM) or the .NET Common Language Runtime (CLR), and type correctness is checked at compile time..Scala is also strongly typed..This means that in Scala a type String is only used as a string throughout a program..Only a type String can be held in the variable’s memory location.Type InferenceScala has built in type inference so that programmers often do not have to infer the type of the variables..Before demonstrating type inference, we need to first know the definition of polymorphic methods, and generic classes.Polymorphic MethodsMethods can be parameterized by type, and value.. More details

Leave a Reply