For my listening pleasure

Listening to podcasts has really grown on me over the last few years.  Now that I'm working from home full time due to the Covid-19 pand...

January 20, 2020

More Scala, More Questions

I've started on the Scala Exercises and have learned some tiny tidbits, which lead to more questions.

One thing that was stated in a section titled "Functional Loops", is that you may use '@tailrec' to enforce using a tail call.  I had never seen this, or quite honestly, thought of such a thing myself.  I find this pretty interesting.  The page says "In Scala, only directly recursive calls to the current function are optimized."  So, it is mostly (only) about optimizations, which is more to say memory requirements will stay constant since the stack won't grow out of control.  I suspect I mostly won't notice any issues surrounding this, but ya never know.

Here's an example of the above:

I'm ready to start muddling through a project so I can learn more about how things are tested, and how to start working with Scala in something slightly bigger than tiny little trivial functions. In a section titled "Lexical Scoping" I learned that you can add a 'package' declaration to control which definitions are seen where. So, you might add a 'package foo' to a file forcing all definitions in that file under the 'foo' package and thereby limiting the scope so other packages cannot accidentally see definitions they shouldn't. The example indicated that you might have a function "Bar" in a file "foo/Bar.scala", with a 'package foo' declaration. Ok, but is that file structure enforced? My suspicion is that it is enforced, because this ends up on the JVM.

This brings up another question. Is there a utility to generate a "correct" project structure? Elixir has the 'mix' tool for this (and many other) uses. I'm only aware of the 'sbt' (Scala Build Tool) at the moment. Judging from this old SO question it isn't the solved problem I was hoping for, but I don't know much so it might be once I learn what G8 is, I guess.

Time for some more Scala.

No comments:

Post a Comment