We have a wiki memo: 
https://cwiki.apache.org/confluence/display/DAFFODIL/Coding+for+Performance 
which is about coding style for things like daffodil runtimes, which have to go 
fast.

I added a section "Avoid Destructuring by Pattern in Assignments" which is a 
guidance that goes along with the guidance for avoiding match-case pattern 
matching in performance code.

Interestingly, there's also a code coverage thing going on here. If you write

val Some(x) = y

Where y is Option[T], the CodeCov tool will always red line this statement as 
non-covered. This is because there is a type-conversion here. The scala 
compiler is checking the type here, and as that code path cannot happen (or you 
wouldn't have written this) there is uncovered code here. The code path that 
checks the type is ascribed to this statement in the code, and so you get a 
red-mark because that type check never fails in testing.

I updated the memo to suggest writing `val x = y.get` instead, which first we 
know is going to generate best-possible byte-code, and second which will fix 
the codecov red line.

Other guidelines suggest sticking with Maybe[T] instead of Option[T] in the 
runtime, but in some cases libraries are being called which utilize Option 
types so you may have no choice.

Reply via email to