Scala at Hello Heart – Adoption and a Bonus Training Plan

At 2016 I gave a lecture about Scala adoption in Hello Heart.

To make a long story short, while I personally really enjoy the language as a developer, we’ve experienced some problems in getting new developers up to speed. The language seems to be extremely frustrating to learn, even to – and I would dare to say especially to – the most experienced developers.

There are several factors that make Scala particularly hard:

The functional ideas in Scala are still new to many developers. While I don’t think Functional ProgrammingTM is necessarily “harder” than imperative programming, it is a new way to think about writing software. Learning ways to think is inherently hard, and the struggle can be a massive ego blow – especially if you are an experienced developer and expect to just “get” new languages easily.

You can end up with wildly different codebases, depending on the language features you use. The Scala language has many features, and it doesn’t constrain you too much in how you can use them. In a typical project, you wouldn’t use them all at once. Ideally, you would choose the subset of the features you prefer, and stick to them in order to achieve consistent style. This means you can see OOP Java-like style in one code base, functional, almost Haskell-y style in another, and any hybrid you can think of in between. Compare to Java code that is quite similar no matter where you look (a loop is a loop everywhere, as my mom would say).

Scala’s syntax is extremely flexible. Brackets? Which do you prefer? Because we do both. At the same time. Or either. Or none. Semicolons? Yeah you can use them. Or not. Hate dots? You can leave them out! Sure thing! Random punctuation marks for identifier name? Amazing! I’ve always wanted a codebase that looks like it was profanityped by a developer with massive anger management problems and an uncontrolled dirty mouth!

All these properties make Scala extremely fun to write DSLs in. And they do, my God, they do. So not only do you need to learn Scala when you learn Scala, you also need to learn the DSLs of all the different libraries used in your project.

All this brings me to my final point, which is that it is extremely hard to just open a source file and dive into the code. Unfortunately, that seems to be a preferred method of learning in our profession. Try that with Scala, and much hair pulling, curse words and cries for help are guaranteed.

So in order to shorten the learning curve, we created a training program that is meant to take a developer with some experience, and teach her everything she needs to know in order to be productive writing server code in about two weeks.

You can find our training plan here, and watch my lecture here:

Advertisements

Tesseract OCR + Open CV 2 on iOS

Disclaimer: This is a quick and messy post that I wrote just so that I will not forget what I did. I am not sure that this is the best way to do things and there may be redundant or missing steps. I will clean this up if I need to do it again. If you happen to go through this procedure and find mistakes, drop me a note and I will fix the post.

The problem

  • I needed to add this build of Tesseract OCR to my iOS project, which uses Open CV 2.
  • Following the installation procedure in the link, caused the following error:

    ‘opencv2/opencv.hpp’ file not found

  • I tried solving it using this stack overflow solution, but it caused a circular dependency issue – every time I removed and added some framework, I got the following error for another framework:

    ld: framework not found <Framework Name>
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

What worked

  • Added the Tesseract OCR iOS project from the link into my workspace
  • Added another build target for the Tesseract project, of type: Cocoa Touch Static Library
  • For my new target:
    • Under build phases, compile sources – added Tesseract.mm (add any file that needs compiling, really)
    • Under build phases, copy files – added Tesseract.h
    • Under link with libraries, added:
      • libstdc++.6.0.9.dylib (Not sure it’s needed here)
      • All the files under the lib folder in the Tesseract OCR project
    • In Build Settings, click “all” so that you can see all settings and look for ‘architecture’ in the search box. Changed “Build Active Architecture Only” to no.
      Made sure I have all the relevant architectures selected.
    • In Build Settings, C++ Standard Library, chose libc++
      (I did the same for the project itself as well, I’m not sure it’s necessary)
  • Selected my new library as a build target and built the thing.
  • For my main project, under the app target, general, linked framework and libraries, added:
    • My new library
    • libstdc++.6.0.9.dylib (Here it’s a must)
  • Added tessdata to the project

Used Tesseract to recognise text in images to my heart’s content.

Reading List on Scala

Work in progress.

  1. http://www.scala-lang.org/
  2. Programming in Scala (by the man himself)
    Easy reading, clear explanations. Seems like the book was written with Java developers in mind, which is fine by me, being one. After working with the language for a while, I wanted do dive more deeply into some of the language features than what the book covers.
    It is still a good starting point, though.
  3. Twitter Scala School
  4. Effective Scala
  5. The Neophyte’s Guide to Scala
    Simple and clear explanations. Good stuff.
  6. The Scala tag in Stackexchange’s code review site (beta)
    So, learning language constructs is easy, but understanding how to think like a Scala developer and write idiomatic Scala is hard. Those of us who are lucky have senior developers who can guide us and from whose code we can learn, but those of us who must teach ourselves need to find alternative solutions.
    This site is a great resource. I skim the Scala section from time to time and read code reviews to get the feel of the language.
  7. A good article on transitioning to Scala

Reading List on Digital Signal Processing

This is an old reading list I started a long time ago when I needed to learn about DSP using online resources for a university project. It’s incomplete but I’m posting it anyway in case it helps someone.

Note that some basic math will help you in your endeavor. Specifically, I recommend that you refresh your memory on linear algebra, calculus and complex numbers.

  1. The Scientist and Engineer’s Guide to Digital Signal Processing By Steven W. Smith
    This is a gentle and practical introduction to the subject. The book is very readable and no prior knowledge in math is required, although it helps.
    I recommend reading chapters 1-3, 5-10, and other chapters if you need them in order to understand more advanced material.
  2. Wavelets and Signal Processing By Olivier Rioul and Martin Vetterli  [pdf]
    I recommend reading chapters 13 and 31 of The Scientist and Engineer’s Guide to Digital Signal Processing before reading this tutorial.

Reading List on CLR Profiling: Stack Sampling and Shadow Stacks

Links preservation for a feature I’m currently working on.
Will update as I go along.

Profiler Stack Walking

Building Shadow Stacks