How to pattern match into an uppercase variable?

The short answer is don’t.

Syntax conventions make your code readable and understandable for others. Scala’s convention is that variables start with lower-case and constants and classes start with upper-case. By violating this, not only you get problems like pattern-matching issues, your code becomes less readable. (Believe me, if you ever have to read code written by someone else who didn’t care for such conventions, you’ll be cursing that person.)

If you want to emphasize that the variables are matrices, I suggest you to use xMatrix and yMatrix or something like that. This will make clear that they’re variables and that they represent matrices.

Or create a convention specific to your project that all matrix variables will end with let’s say “M”, like xM and yM.

It’s worth typing a few more characters if it makes your code readable.

Leave a Comment