Commit 8f5cc2

2026-01-16 10:12:49 Melisha Dsouza: Scala link update
CMMI/Guidelines/Coding Standard/Scala.md ..
@@ 13,7 13,7 @@
- Break long expressions across multiple lines
- Use appropriate break points (after operators, commas)
**Example**:
- ```
+ ```Scala
// Good
val result = longMethodName(parameter1, parameter2, parameter3) +
anotherMethodCall() +
@@ 32,7 32,7 @@
- Opening brace stays on the same line as the expression
- Closing brace on a separate line
**Examples:**
- ```
+ ```Scala
// Good
if (condition) {
doSomething()
@@ 62,7 62,7 @@
- No space before colon in type ascription
**Example**:
- ```
+ ```Scala
// Good
val sum = a + b
val list = List(1, 2, 3)
@@ 83,7 83,7 @@
- `snake_case` for filenames and configuration keys
**Examples**:
- ```
+ ```Scala
// Classes and traits
class UserRepository
trait DatabaseService
@@ 106,7 106,7 @@
- Getter methods start with `get` only if there is a corresponding setter
- Avoid single-letter names except for conventional ones (`i`, `j`, `k` for indexes)
**Examples**:
- ```
+ ```Scala
// Good
def calculateTotal(): BigDecimal
def save(user: User): Future[User]
@@ 134,7 134,7 @@
4. Companion objects
5. Nested classes
**Example**:
- ```
+ ```Scala
package com.company.service
import scala.concurrent.{Future, ExecutionContext}
@@ 157,7 157,7 @@
- Avoid wildcard imports (`import package._`) except in tests
**Example:**
- ```
+ ```Scala
import scala.concurrent.{Future, ExecutionContext}
import scala.util.{Try, Success, Failure}
@@ 179,7 179,7 @@
- Local variables can use type inference
**Examples:**
- ```
+ ```Scala
// Good
val userName: String = "John"
val count = calculateCount() // type inference acceptable for local variables
@@ 196,7 196,7 @@
- Avoid using `null`. Use `Option` for nullable values.
**Example**:
- ```
+ ```Scala
// Good
def findUser(id: Long): Option[User]
val maybeUser: Option[User] = findUser(123)
@@ 215,7 215,7 @@
- Explicitly specify return types for public methods
**Example**:
- ```
+ ```Scala
// Good
case class SearchCriteria(query: String, limit: Int, offset: Int)
@@ 234,7 234,7 @@
- Avoid side effects in pure functions
**Example**:
- ```
+ ```Scala
// Good
val activeUsers = users.filter(_.isActive).map(_.toDto)
@@ 255,7 255,7 @@
- Use `Future` for asynchronous operations
**Example**:
- ```
+ ```Scala
// With Try
def parseNumber(s: String): Try[Int] = Try(s.toInt)
@@ 278,7 278,7 @@
- Preserve stack trace when wrapping exceptions
**Example**:
- ```
+ ```Scala
class UserNotFoundException(id: Long)
extends RuntimeException(s"User with id $id not found")
@@ 302,7 302,7 @@
- Avoid comments that duplicate code
**Example**:
- ```
+ ```Scala
/**
* Repository for working with users.
*
@@ 342,7 342,7 @@
- Group related tests using `describe`/`it`
**Example**:
- ```
+ ```Scala
class UserServiceSpec extends AnyFlatSpec with Matchers {
"UserService" should "return user by id" in {
@@ 378,7 378,7 @@
### **11. Tools and Automation**
#### **11.1 Formatting**
Use Scalafmt for automatic code formatting. Configuration `.scalafmt.conf`:
- ```
+ ```Scala
version = "3.7.14"
maxColumn = 120
continuationIndent.defnSite = 2
@@ 395,7 395,7 @@
### **Appendix A: Examples**
#### **A.1 Good Practices from the Code**
**Using dependency injection:**
- ```
+ ```Scala
class FuelGaugesRoutes @Inject()(
system: ActorSystem,
userRepository: UserRepository,
@@ 405,7 405,7 @@
)(implicit @Named("global") executionContext: ExecutionContext)
```
**Using type classes:**
- ```
+ ```Scala
// Type class as trait with parameter
trait JsonWriter[A] {
def write(value: A): Json
@@ 458,7 458,7 @@
```
**Structuring configuration:**
- ```
+ ```Scala
lazy val commonSettings = Seq[Def.SettingsDefinition](
scalaVersion := "2.13.16",
version := releaseVersion,
@@ 468,7 468,7 @@
#### **A.2 Areas for Improvement**
**Avoid overly long lines:**
- ```
+ ```Scala
// Instead of:
val all = endpoint(request(Get, root /? (qs[Option[String]]("query") & qs[String]("sort_by") & qs[String]("asc") & qs[Int]("pageNumber") & qs[Int]("rowsNumber") /*& optQs [String]("filterParams")*/)), ok(jsonResponse[ResponseStatus Either GetResponse]))
@@ 487,7 487,7 @@
```
**Use explicit return types for public API:**
- ```
+ ```Scala
// Instead of:
def findAll2(user: User, parameters: GetParameters) = {
// implementation
@@ 514,3 514,5 @@
- Compliance with functional programming principles where appropriate
- No blocking operations in asynchronous context
- Efficient use of collections (without excessive copying)
+
+ **Document** - [Scala](https://docs.google.com/document/d/1gxq5pJsQ4cc5iDnf3h4ynMcpyM4A_sEUeKn9sNRjUec/edit?tab=t.0#heading=h.coq5eefrj3q)
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9