TNS
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
NEW! Try Stackie AI
Programming Languages / Software Development

Scala Creator Proposes ‘Lean Scala’ for Simpler Code

Martin Odersky promotes the concept of lean Scala, a coding style to simplify Scala development. Meanwhile JetBrains delivered a new release of its IntelliJ Scala plugin.
Apr 17th, 2024 10:14am by
Featued image for: Scala Creator Proposes ‘Lean Scala’ for Simpler Code
Feature image via Unsplash.

Martin Odersky, creator of the Scala programming language has posted a masterful proposal for developers to pursue the concept of “Lean Scala”.

Lean Scala is a coding style that aims to make Scala code simple, understandable, concise, and expressive, Odersky wrote.

“Scala is a strong statically typed high-level general-purpose programming language that supports both object-oriented programming and functional programming,” Wikipedia says. “Designed to be concise, many of Scala’s design decisions are intended to address criticisms of Java.” And Scala source code can be compiled into Java bytecode and run on a Java virtual machine (JVM).

Scala has a reputation as a complex language that has a steep learning curve compared to other languages. “There’s quite a lot of complexity there. And that complexity is made kind of worse because it’s built on top of Java and its ecosystem,” Matthew de Detrich, an open source developer at Aiven and a maintainer of the Apache Pekko project (which is written in Scala), told The New Stack in a discussion about Pekko. “It’s quite a lot to learn, but Scala 3 has done quite a good job in simplifying” things, he said.

Meanwhile, “Lean Scala is a useful default, for instance for teams that don’t have special requirements, people new to the language, or for educators that want to teach simple and modern Scala,” Odersky noted in the post.

For instance, in Odersky’s courses in EPFL’s Scala specialization on Coursera, he presents many examples of lean Scala code.

“Scala, and in particular Scala 3, is a very good notation for writing lean code,” Odersky wrote. “It has a smallish, quiet syntax. It has a concise and expressive type system with good type inference that gives type safety and documentation without a lot of boilerplate.”

Another factor in Scala 3 being well-suited for writing lean code is its immutable-first orientation, which promotes software that is reliable and correct by design and provides an expressive toolkit for clean modularization, he said.

However, Scala’s flexibility and expressiveness can also lead to challenges, such as varying coding styles and over-abstraction.

To address these challenges, Odersky proposes identifying a recommended style for writing lean Scala code. The properties of this style include:

  • Following the Principle of Least Power
  • Being immutable-first without being dogmatic
  • Focusing on Scala 3 constructs and syntax
  • Promoting the core language over embedded Domain-specific Languages (DSLs)
  • Focusing on direct style

“The innovation of Scala allowed me to implement Akka as my vision for the actor model on the Java Virtual Machine,” Jonas Boner, CTO, co-founder and chairman of Lightbend, told The New Stack. “User code expressing its intent has always been central to us in the Akka team, even at the price of more intricate library code in Akka. We nowadays fully support Scala 3 alongside Scala 2 and Java. I’ll follow Martin’s Lean Code initiative and we will revisit our examples to show them in Scala 3 with Lean Scala in mind.”

Lean Scala is but one way to write code in the language, Odersky said. Moreover, lean code can be written in any programming language, but some languages make it easier than others, he said.

“There are situations and whole application areas where you want to deviate from the style and develop your own set of principles and techniques,” he wrote.

Writing lean code can be like writing lean technical prose, Odersky said.

“Lean code is simple and understandable. It is as concise as possible without losing clarity,” he explained. “It avoids lingo, over-abstraction, and obscure features. It does not mislead, that is, it expresses the meaning of a program clearly and without fault. All these properties are desirable for code just as they are desirable for technical prose.”

Odersky achieved that goal with this excellent, “lean” post.

IntelliJ Scala Plugin

Meanwhile, in other Scala-related news, JetBrains earlier this month introduced a new release of its IntelliJ Scala plugin.

The IntelliJ Scala Plugin 2024.1 release includes numerous improvements and fixes, such as enhanced Scala 3 support, including better handling of specific syntax cases, improved debugger support, and accurate autocompletion, wrote Maciej Gorywoda, Product Marketing Manager in the IntelliJ Scala team at JetBrains in a blog post.

“Sometimes, a lot of work results in only a small number of visible changes, while at the same time, it lays out the foundations for many more improvements in the next release,” Gorywoda said. “But even in light of this, the 2024.1 release of IntelliJ Scala Plugin seems bigger than usual. We worked on many fronts and came up with a long list of fixes and improvements.”

That list of fixes and improvements includes:

  • Scaladoc enhancements, with improved highlighting for class, trait, and method declarations, as well as code inside Scaladoc blocks.
  • Improved compiler-based highlighting, providing a more stable experience and support for Scala 3 and Scala 2.13 compiler diagnostics.
  • Build tool improvements for SBT and BSP, including adding a .gitignore file for new SBT projects and fixing various issues.
  • The ability to pin the X-Ray mode, introduced in the previous release, for easier access.
  • The project wizard now defaults to Scala 3.3.x LTS for new projects, as Scala 3 support has improved significantly.

Other improvements include new icons, enhanced inlay hint presentation, and the addition of Scala documentation to the settings help page.

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.