What is a good use case for scala? [closed]

In a current project we have setup the build so that we could mix Java and Scala. I would like to use more Scala in our code base to make the code more readable and concise. In the process also learn the language by handing over real features.

So I plan to use Scala for some classes to showcase its benefits and convince other devs to look into using Scala too.

For a rest based web server or a program in general what kind of code structures lend themselves to Scala’s functional programming style.

8

A typical example if you want to illustrate conciseness of functional code could use collections and their operations. E.g. consider a class Customer and a method creating a sorted list of customer names from a list of customers.

Here is the Java implementation:

class Customer
{
    String name;

    ... // Other attributes.
}

List<String> sortedCustomerNames(List<Customer> customers)
{
    List<String> names = new ArrayList<String>();

    for (Customer customer : customers)
        names.add(customer.name);

    Collections.sort(names);

    return names;
}

Scala version:

class Customer(val name: String, /* ... other attributes */)

def sortedCustomerNames(customers: List[Customer]): List[String] =
  customers.map(c => c.name).sorted

NOTE

Conciseness in terms of keystrokes is not always a good measure of code quality and maintainability.

Also, in general I would not advise to switch from Java to Scala just because Scala is newer. If most of the team members are more familiar with Java, the team will be much more productive with Java than with Scala (or any other programming language they don’t know well).

I have been learning Scala in my free time for about two years now, and only recently (after attending an online course) I got the feeling I can be more productive in Scala than I am in Java. Before reaching this point, I would not have considered using Scala for production.

3

For all, everywhere where it is possible or for nothing, just use Java. This way this will work sane. I were making such experiments long time ago but in later times you rewrite everything to one or two (to you keep some things if that could not be done in another language) languages just for clarity.

If you can declare class shorter in 2 lines of code, that is not advantage you must not use language for this “feature”. For example also you can write beautiful functional code in xxx lines and spend yyy time and maybe in the same time you can write it in OOP style in xxx+150 lines in yyy-2hours time with perfomance benefit (who knows). What I want to say is that is not possible to say “this part will be better on Scala” and “this part on Java”. In development you must not discover features, in my opinion, you must just develop without mixing and think about general logic instead of implementation in language X or Y that’s why, in my opinion, for clarity and productivity you must pick language for project instead of for feature.

7

I suspect this is a matter of how good the programmers on the team are and how much they are willing to learn new things.

Scala is much more concise and expressive, but equally more complex. Any programmer who can make a good use of the high level abstractions it offers will like it and be more productive in it and will never want to go back to the oversimplified level of Java. But a programmer who is not good at high level abstractions or simply does not want to learn will never get it.

Also I don’t think you should use any cases tailored specifically to Scala. Just start writing the prototype in it and you’ll see whether it’s more productive or not. It should be more productive for everything to be worth switching.

And I definitely wouldn’t mix the languages except for using libraries written in the other. Start prototyping in Scala, see how well it goes and choose one or the other.

In my (admittedly limited) experience, the use case I’ve seen most is to use it to get a sense of superiority and smugness over your colleagues who actually ship things, and/or hide your limitations by blaming the “antiquated and inelegant” language you’re “forced” to use instead of the new hotness 😉

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật