Learning Methodology
When I learn new programming languages I first choose a non-trivial programming problem and then develop pieces of that system in the new language then go back and re-factor as I learn more. Solving a real problem with the language is the fastest way I have found to gain demonstrated competence in a new language.
I first discover examples of the key things you need to accomplish in any distributed system such as fetching a remote web page, parsing a delimited file, Sorting an array. This document contains links to information I discovered along the way. Let me know of links you think should be added.
Helpful Scala Links
Items that should be considered must Read are prefixed with **.
Items prefixed **# specify recommended study order
We provide consulting services with a specialty in solving complex distributed problems. Please contact us if you need help.
Overcome Class not found when compiling from command line.
If you compile a class or package from command line Scala will not find it unless you add -classpash . to your command line. This tells scala to search your current directory.
Example: scala -classpath . readHGTElevationGenJPG.scala
exSampleLibrary.scala
package mylibs.sample {
object util {
def printAString( aStr : String) = {
println("printAString() " + aStr )
}
}
}
exSampleLibraryTest.scala
import mylibs.sample
sample.util.printAString("I am a string")
exSampleLibraryTest.bat
call scalac exSampleLibrary.scala
echo Using implied class path from enviornment variable
echo Seems to fail with error can not find import under
echo some conditions but have not been able to reliably
echo predict when it will fail.
call scala exSampleLibraryTest.scala
echo Now try it with our class path explicit By adding
echo the class path it manually it never seems to fail
scala -classpath . exSampleLibraryTest.scala
NOTE: I use the mylibs. or something similar to keep all the class files junk generated by the compliler out of my main source directories. It also makes it easy to avoid saving those binaries with the git ignore file.
I tend to distrust IDE. Or more specifically i like to be able to build everything explicitly and know what the underlying tools are doing before depending and build packages. I blew a a couple hours on this because I expected the scala command line to search the java CLASSPATH for resolving module names. I always have my java CLASSPATH set with .;./lib;..;../lib;../..;../../lib so I can have sub projects that depend on more general library modules. I would have expected scala to find my locally compiled modules this way but it didn’t.
Random Notes
There is no char in Scala they are treated as strings
JSON LIKE Hash Map
10 11 12 13 14 | bluex = { 'name': 'Johny Blue', 'weight' : 170, 'height' : 62 } |
Define class constructor values with var to allow mutable elements as class attributes.
Play Routing
play – Accessing files saved in the public directory
Using the Standard play 2.4 seed you can add a new file under the /public directory such as sample.txt This can be retrieved using the URI: http://127.0.0.1:9000/assets/sample.txt without having to change the routes file.
play – Creating a Alias to Directory inside of the project
Creating an alias for the public directory under conf/routes add the line GET /s/*file controllers.Assets.versioned(path=”/public”, file: Asset) which allows the sample.txt file stored in public/sample.txt to be accessed as http://127.0.0.1:9000/s/sample.txt
play – Creating an alias to file external to the Play application
I used this because I need to reference stock and forex data files that can be hundreds of gigabytes and do not have sufficient storage to duplicate them in different directories for different projects an when running on windows the symbolic link doesn’t work. Add the following to the file conf\router
GET /forex/*file controllers.ExternalAssets.at(
Retrieved the file existing file actions.txt with view-source:http://127.0.0.1:9000/forex/actions.txt
2 Replies to “Scala Resource Links Getting started”