Scala Basics for a Python Dev

Best Practices
  • Camel case instead of snake e.g. addOne
  • Short temporary variables
Variables
Scala

Python

Function Parameters & Return Values
Scala

Python

Functions
Scala

Python

Anonymous Functions
Scala

Python

NOTE: Just like in python you can can assign an anon function or any function for that matter to a variable and pass the reference via that variable assignment.

Multi-Line Functions
Instead of having a tabular syntax just like in JavaScript “which is pretty hot right now”, you can wrap any of the functions contents discussed above anon or otherwise in {}.

def times_two …

Drop your email below to get updated on my next post!

Swapping Values In Python

When swapping values in python there really is not reason to use a temporary variable. We can take advantage of tuples to initiate the swap, which allows us to do the swap without a temporary variable.

 

Below is an example of non-idiomatic swapping.

a = ‘A’
b = ‘B’
temp = a
a = b
b = temp

 

Below is an example of utilizing the power of a Python tuple.

a = ‘A’
b = ‘B’
(a, b) = (b, a)

What Is 2-Step Verification

Two-step verification (also known as Two-factor authentication, abbreviated to TFA) is a process involving two stages to verify the identity of an entity trying to access services in a computer or in a network. This is a special case of a multi-factor authentication which might involve only one of the three authentication factors (a knowledge factor, a possession factor, and an inherence factor) for both steps.[1][2][3] If each step involves a different authentication factor then the two-step authentication is additionally two-factor authentication.