Scala Anti-Patterns Overview
Scala Anti-Patterns Overview
Using Option.get Without Checking
Using Option.get Without Checking
.get on an Option without first checking if it contains a value, as it will throw a NoSuchElementException if the option is None.Excessive Use of Nulls
Excessive Use of Nulls
null in Scala. Instead, use Option[T] to represent the presence or absence of a value.Ignoring Return Values
Ignoring Return Values
val _ = ....Overusing Var
Overusing Var
var in favor of val and functional transformations to make code more predictable and easier to reason about.Returning Any
Returning Any
Any as it bypasses the type system. Use algebraic data types (ADTs) or sealed traits instead.Using Exceptions for Control Flow
Using Exceptions for Control Flow
Option, Either, or Try to represent operations that might fail.Not Using Case Classes for Data
Not Using Case Classes for Data
equals, hashCode, toString, and copy.Not Using Pattern Matching
Not Using Pattern Matching
Overusing Implicits
Overusing Implicits
Excessive Nesting
Excessive Nesting
flatMap/map chains or for-comprehensions for more readable code.Not Using Proper Resource Management
Not Using Proper Resource Management
Using (Scala 2.13+).Overusing Object-Oriented Features
Overusing Object-Oriented Features
Not Using Proper Immutability
Not Using Proper Immutability
Not Using Proper Error Handling
Not Using Proper Error Handling
Either, Option, or Try for error handling instead of throwing exceptions.Not Using Lazy Evaluation When Appropriate
Not Using Lazy Evaluation When Appropriate
lazy val for expensive computations that might not be needed, and consider using streams or views for lazy collection processing.Misusing Futures
Misusing Futures
map, flatMap, or for-comprehensions.Not Using Proper Functional Error Handling
Not Using Proper Functional Error Handling
Try, Either, or Option.Not Using Proper Type Parameters
Not Using Proper Type Parameters
Any to leverage the type system.Not Using Proper Collection Methods
Not Using Proper Collection Methods
Not Using Proper String Interpolation
Not Using Proper String Interpolation
s"", f"", raw"") instead of concatenation for better readability.Not Using Proper Case Class Patterns
Not Using Proper Case Class Patterns
copy for creating modified instances.