Should i use scala




















Let's write a function to safely update a String to Int. And if we need an error message we can use the Either class that will return a Right containing the value or a Left with an error type. Try is also a great type to manage error, especially to encapsulate every call to Java functions that can throw errors. Option, Either or Try allow us to return a result or an error and not throw it to whatever will catch it.

We can combine them and return an error for the first error we encounter. We can even combine Future with other error types like Either by using functional libraries like cats. Another useful tool we use is sbt-docker. It allows you to simply build a docker container embedding your application. Such powerful language attracts skilled engineers who are curious and keen to test new tools, who have the willingness to discover new paradigms, new perspectives to see the world of programming And this is the perfect mindset to join a startup as Engineer 1 to 10!

Code review is part of your engineering culture. Programming in Scala, on the other hand, has a slightly more complex structure. The truth is that Java is often just way too verbose. In Scala, the compiler is incredibly smart, so this avoids the developer needing to specify explicitly those things that the compiler can infer.

Now consider a case where we have a list of strings that are numbers, but we want to convert that list to a list of integers:. However, if you think back to the reasoning behind getters and setters in Java, it is specifically for future-proofing. That is, if you later need to add some logic to either the getting or setting of variables you would have to re-write those public variables to use methods instead which is why the use of getters and setters to begin with is encouraged in Java.

Because of the language design, the abstraction remains intact without needing getters and setters. Consider, for example, this modified User class in Scala that throws a NullPointerException if you try to set the name to null:. Moreover, since Scala prefers immutability, I can write this in Scala even more concisely with case classes:. Now consider a scenario with the above classes where I want to add a nifty little method in the User class that returns a list of all Products that the User has ordered:.

Fortunately, java. List has an addAll method, or getProducts would have been an even longer in Java. You can see just how much smaller the Scala language implementation is. Yes, it may seem more complex to the Scala newbie, but once you actually fully understand the concepts behind it, the Scala code will look far more simplistic than the Java code.

What if we want to only get the Products within a specific Category? List , so things get uglier in Java :. In Scala , however, the code remains fairly straightforward. We simply use flatMap to combine the products lists from each Order flattened in a single list, then we filter to only include the ones that match the category:.

There has certainly been no shortage of new languages over the past few years, but whereas nearly all the others that have recently emerged are dynamic, Scala is statically-typed. As a professional developer — though I know and use many dynamic languages — it is my opinion that compile-time checks are incredibly important to write solid code. In a dynamic language, you can never be sure that your code is sufficiently bug-free and robust until you actually run it in a wide range of scenarios.

The company arrived in the Pacific Northwest with its acquisition of Kirkland-based Dev9 last year, and maintains that office to focus on building custom cloud and software products. Because Nortal works with a variety of customers, Solutions Architect Nathan Skone said his company must consider the practicality of adopting Scala-based tools within a client organization.

Scala is often a perfect fit for our big data projects. The entry barrier into functional programming as a whole is still surprisingly high. Most developers have had very limited exposure to proper functional programming and are hesitant to explore its benefits.

We have been lucky to have a group of developers and stakeholders that were excited about the journey, and convinced of the eventual benefits. The Scala community has created a rich set of tooling to ensure adherence to proper conventions and quality guidelines.

Our team loves how concise and compact code written in Scala can be. Concepts that would otherwise need to be pulled into a separate method can often be articulated by a single line of functional code. The conciseness of the language comes to mind as one of the major benefits.

Being able to express large algorithmic meaning and not having to write repetitive boilerplate code makes teams productive. Managing dependency versions is a common challenge across different programming languages. The issue is prominent with Scala, where you have to account for different Scala versions as well — especially during Scala version upgrades.

For example, sealed traits are great for safely describing situations where a limit exists on some kind of value versus the value being unlimited. In other languages, the options might have been to use magic values or null. Immutability is a useful tool as well.

Immutable locals help reason about the code locally, while case classes and immutable collections help ensure that no surprises happen to the data as it travels down and up the call chain. I think everyone who had ever had to debug a rogue setter appreciates how much this can simplify things! Data processing with maps, filters and reducers helps remove lots of the cruft that exists in the imperative counterparts of these idioms, and clarify the intent of the developer.

Less cruft means less opportunities to make a mistake, and focusing on the core of the data transforms generally makes understanding the code easier. Types and a good type system are just the best. Library support is also generally quite good: circe, Finch, PureConfig, kantan. The benefits of Scala accumulate over time, as it slowly changes the patterns we use to solve problems. Our first early steps were mostly just trying to avoid clumsy Java syntax, but gradually we started to appreciate other things.

Our Scala code is asynchronous, uses immutable data structures with a declarative style instead of imperative, and with functional error handling instead of throwing exceptions. We organically learned these things over a few years, but a new hire has to dive into the deep end all at once.

It can take a few weeks or even months until they feel totally comfortable. Functional languages like Scala fit big data workflows very well. Functional concepts such as immutability, pure functions and separating program data from behavior help us reason about data transformations and ensure data correctness. One of the main challenges we have faced is training developers that have been taught and raised in an object-oriented programming world. All of our projects make use of an internal SBT plugin, which propagates code conventions, test coverage goals, linting rules and much more.

The biggest benefit, however, is the mental model that functional programming brings.



0コメント

  • 1000 / 1000