SlideShare a Scribd company logo
1 of 20
Today
Why Scala?
Not Today 
• Sales pitch 
– “Selling Scala to your boss” 
• Ecosystem 
– Distributed computing 
– Web applications
Scala Features 
≈ Functional 
• First class functions 
• Type inference 
• Case classes 
• Pattern matching 
• Immutable state 
• Nested functions 
• Laziness 
• Implicits 
≈ Object Oriented 
• Singletons 
• Traits
First class functions
Type inference
Case classes
Pattern matching
Immutability I
Immutability II
Singleton
Nested functions
Traits I
Traits II
Laziness I
Laziness II
Implicit Conversions
Implicit Parameters I 
• Ten different implementations
Implicit Parameters II
How Scala is different

More Related Content

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Recently uploaded (20)

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

How Scala is different

Editor's Notes

  1. Combines features from many programming languages. Looking at Scala gives you more insight into other languages. Show you what’s possible with more functional programming. We’ll be doing some direct comparisons with Java and C#.
  2. Won’t be trying to sell you Scala. There’s an excellent presentation on that “Selling Scala to your boss” that I’d recommend to Milan. Also won’t be discussing the ecosystem surrounding Scala. Distributed computing; Web applications. Hadoop is at the moment the standard in distributed computing. More than half of the Fortune 50 use Hadoop. Spark is the successor to Hadoop and is written in Scala.
  3. These are the Scala features I’ll be talking about. They’re mostly functional cause you all know object oriented programming. Start with the basics. You might already be familiar with these. I’ll try to go not to fast. Traits, laziness and implicits are the most interesting features. I’m saving them for last.
  4. Squares concept uitleggen. Java 7. Java 8 daarbij kan je een lambda gebruiken, en Scala vergelijkbaar met Java 8. Don’t want to talk about first class functions. I think you know them already. Every modern language has them: Java 8, C#, Scala, F# There are differences but this is out of our scope. “expression bodied members” is coming to C# 6.0
  5. Type inference is common in modern languages but previously was mostly in functional programming. Here are some samples of sumEevenNumbers in different languages. Silly example. Takes a list of the numbers one to three, and sums only the even numbers. Sommige talen doen meer type inferentie dan anderen. Type inference on - lambda’s - local variables - fields - method return types - constructors.
  6. Left, looks like a lot of code right? Well I didn’t write it. Only wrote about one line of code. Not ideal, when I change something I have to generate all the code. I can’t make any changes to the generated code or I risk losing them. Scala moves this type of code generation from the IDE to the compiler. The Java bytecode of the Java and Scala implementation is the same. In the Scala example, the parameter ‘miles’ of the class Car definition creates the field and the constructor. Adding case generates the hashcode, equals and the get. C# already has automatic getters/setters, allowing you to combine the field and the getter. C# has some features coming that relate to this: - Getter-only auto-properties, 6.0 - Auto-property initializers, 6.0 - Primary constructors, not in 6.0 F# has what Scala has.
  7. Leg uit wat driveCar doet. Anyone recognize this pattern? Disadvantages? Clunky. Not very type safe. There’s a pattern to prevent this. What’s it called? How does this look in C#? You can write it more type-safely by using an ‘as’ cast. Functional languages like Haskell and Scala have pattern matching. It’s like a switch on steriods. The example is simple but there are many more features. C# has a similar feature “type classes” on the wishlist.
  8. Wat is immutability? In het linker voorbeeld zie je dat je vaker aan de variabele x kan assignen, maar niet aan y vanwege final. Who uses immutability? Advantages? We don’t use immutability that much but many functional languages are fully immutable. Final in the left example. Can you do this in C#? Who uses final/readonly on fields? I’m not always sure it’s worth the extra syntax. Scala val syntax is light. I always use val when I can, which is often. In Haskell you can leave away the val.
  9. You can’t write a program without datastructures. Scala has immutable data structures, and also mutable ones. The immutable variants are in the default scope, so they’re sort of recommended.
  10. Who knows the singleton pattern? Do you like it? In Scala, statics have been replaced by making singletons a language concept. In this sense it is more OO than Java / C#. Enums don’t exist but can be mimicked with objects.
  11. In a functional language like Haskell you don’t have classes. Often part of your hierarchy is created by nesting functions. Scala has nested functions. The concept is simple, nested function have access to the scope of the function they are in. The example. It’s not a lot of code but it can be hard to read. What is depth first traversal? Would you like to go over the example to get it?
  12. You all know inheritance. Who of you works with multiple inheritance? Do you feel like you need it? Here’s an example of the PEARL code base where we could have used multiple inheritance. There’s lots of duplication here. We have many more of these report classes. Someone actually used copy paste to put the same kind of time series functionality in all of these time series variants. So what could we have done to improve the situation? Decorator pattern. Java and C# have interfaces. In Scala interfaces are replaced by traits. A trait is somewhere between an interface and an abstract class. They provide a method of doing multiple inheritance since traits can contain behavior and state.
  13. This is the typical diamond problem which is the canonical issue with multiple inheritance. Suppose we inherit from both DoublingQueue and IncrementingQueue. What gets put in the queue when we call push? Java 8 has default methods. Can you use those to create this situation? No, Java 8 has ‘unrelated defaults’ exception. Java 8 mixins can only be used to combine unrelated functionality. Also mixins can’t contain state. Default methods were made only as strong as required by their goal: backwards compatibility. In Scala the order in which you mix in the traits determines who’s victorious. Suppose you want to have DoublingQueue and IncrementingQueue interact. Use abstract override. How is this in C++? The diamond problem gets really confusing when you think about constructors. Scala traits have no constructors so this simplifies it compared to C++. It’s a matter of taste but Scala Traits cover the main criticism of C++ inheritance.
  14. In Java 8 the Optional class was added. The concept of Optional is that tries to help deal with the null value. It wraps around a value that might be null. If you have an Optional you can try to get the value out of it but you have to provide a default. Java 8 has two methods that both implement this concept. In Scala there is only one method. Trick here is that the method argument is lazily, so it’s automatically wrapped in a lambda. Syntactical advantage from two sides.
  15. Some more cool stuff that you can do with laziness: infinite data structures. cons we can use to construct a stream. It starts with a head value, and after that come the other values, the tail. Stream is similar to a list but uses laziness. AllNumbers is a stream of all the numbers from 0 to infinity. Defined using allNumbersFrom
  16. Suppose we want to add functionality to a class from outside the class. In Java we can’t really do this. Best we can do is a extensions class. In C# we can do better with extension methods. In Scala we can define extension methods and add interfaces.
  17. Let’s look at the sum function on sequences of numbers. Skip the Java implementation to save us some tears. Let’s look at C# first.
  18. Calling sum in just as simple as in C#. Ignore the [B >: A] type annotation. Definition of sum is located in the traversable trait. foldLeft is also in traversable. It abstracts over the loop over list pattern. This is called the type class pattern. It is used to add interfaces to classes that did not declare them.
  19. I didn’t cover the really advanced features: - Higher kinded types - Macro’s - TypeTags for dealing with type erasure