Watch the video of me presenting this at Scala Exchange 2014 : https://skillsmatter.com/skillscasts/5835-bootstrapping-a-scala-mindset
The aim of this session was to map out the key stages involved in moving productively from a Java to a Scala mindset.
As Scala gains increasing traction in OO developer communities, more and more Java developers are in the progress of making the move from being Imperative-comfortable to FP-fluent. Many are lured by the terser syntax, others by the promise of powerful high-level constructs, and more still by the thrill of challenging themselves and learning something almost entirely new to them. The problem however, is that for many their initial enthusiasm soon wears off and the realization of how much a mind-shift this really is sinks in.
In this session I discussed in some detail the key steps along a path which via much trial-and-error, has proved for me to be effective in undertaking this transition. We began at the base-camp of understanding (Java-concepts to let go of, the initially-unfamiliar syntax, the equally-unfamiliar maths idiom) and from there up into the lower foothills (the basics of the type system, infix notation, ""everything is an expression"" and referential transparency) before progressing on to the lower peaks of the language (Pattern-matching with case classes and partial functions) and ending at one significant Monadic taster (Option, map/flatMap and the for-comprehension).
For maximum benefit I also pointed out the pain points I encountered, techniques and resources I used to overcome these, and we ended by mentioning next steps and further inroads into the language.
The Strange World of Javascript and all its little Asynchronous BeastsFederico Galassi
Javascript is a wonderland populated by all kinds of exotic beasts. Callbacks, events, promises, functional programming, reactive programming, streams, generators are all part of this incredible asynchronous bestiary. We’re talking of insidious or even ferocious things, a great danger to the unwary programmer. Let’s look at them, learn from them, tame them and finally put them to our own advantage. Let’s stop Javascript from being an unfamiliar place and make it feel much more like home.
Talk I held on 14/05/2014 at JsDay, Verona, Italy. Corrected slides.
http://2014.jsday.it/talk/the-strange-world-of-javascript-and-all-its-little-asynchronous-beasts/
Feedback!
https://joind.in/talk/view/11280
Follow me on Twitter!
https://twitter.com/federicogalassi
JavaScript APIs you’ve never heard of (and some you have)Nicholas Zakas
The document discusses several JavaScript APIs related to manipulating the DOM and CSS, including some newer APIs that the reader may be unfamiliar with. It describes APIs such as insertAdjacentHTML() and outerHTML for inserting and retrieving HTML, children and firstElementChild/lastElementChild for traversing element nodes, and matches() and getBoundingClientRect() for working with CSS selectors and elements' positions. The document provides examples and explanations of many DOM and CSS-related JavaScript APIs beyond the traditional ones.
Need for Async: Hot pursuit for scalable applicationsKonrad Malawski
This document discusses asynchronous processing and how it relates to scalability and performance. It begins with an introduction on why asynchronous processing is important for highly parallel systems. It then covers topics like asynchronous I/O, scheduling, latency measurement, concurrent data structures, and techniques for distributed systems like backup requests and combined requests. The overall message is that asynchronous programming allows more efficient use of resources through approaches like non-blocking I/O, and that understanding these principles is key to building scalable applications.
The next version of JavaScript, ES6, is starting to arrive. Many of its features are simple enhancements to the language we already have: things like arrow functions, class syntax, and destructuring. But other features will change the way we program JavaScript, fundamentally expanding the capabilities of the language and reshaping our future codebases. In this talk we'll focus on two of these, discovering the the myriad possibilities of generators and the many tricks you can pull of with template strings.
The document summarizes Roman Elizarov's presentation on Kotlin coroutines at the JVM Language Summit in 2017. The presentation recapped the initial Kotlin coroutines prototype, discussed issues with its design, and outlined the solutions adopted in Kotlin 1.1. This included using suspending functions instead of async/await keywords, tail suspension to avoid stack overflows, and abstraction to provide a natural coroutine declaration syntax.
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tKonrad Malawski
A talk about the implications and context around API design. How APIs come to be and how to understand them. This talk was delivered as opening keynote, setting the tone, for the ScalaSwarm conference in Porto, Portugal in 2017.
Covers Arrays in JavaScript,
Various types of declaration and initializations,
Associative Arrays,
Nesting Arrays,
Array Functions etc.
Video tutorials available at http://youtube.com/techcbt-online
The Strange World of Javascript and all its little Asynchronous BeastsFederico Galassi
Javascript is a wonderland populated by all kinds of exotic beasts. Callbacks, events, promises, functional programming, reactive programming, streams, generators are all part of this incredible asynchronous bestiary. We’re talking of insidious or even ferocious things, a great danger to the unwary programmer. Let’s look at them, learn from them, tame them and finally put them to our own advantage. Let’s stop Javascript from being an unfamiliar place and make it feel much more like home.
Talk I held on 14/05/2014 at JsDay, Verona, Italy. Corrected slides.
http://2014.jsday.it/talk/the-strange-world-of-javascript-and-all-its-little-asynchronous-beasts/
Feedback!
https://joind.in/talk/view/11280
Follow me on Twitter!
https://twitter.com/federicogalassi
JavaScript APIs you’ve never heard of (and some you have)Nicholas Zakas
The document discusses several JavaScript APIs related to manipulating the DOM and CSS, including some newer APIs that the reader may be unfamiliar with. It describes APIs such as insertAdjacentHTML() and outerHTML for inserting and retrieving HTML, children and firstElementChild/lastElementChild for traversing element nodes, and matches() and getBoundingClientRect() for working with CSS selectors and elements' positions. The document provides examples and explanations of many DOM and CSS-related JavaScript APIs beyond the traditional ones.
Need for Async: Hot pursuit for scalable applicationsKonrad Malawski
This document discusses asynchronous processing and how it relates to scalability and performance. It begins with an introduction on why asynchronous processing is important for highly parallel systems. It then covers topics like asynchronous I/O, scheduling, latency measurement, concurrent data structures, and techniques for distributed systems like backup requests and combined requests. The overall message is that asynchronous programming allows more efficient use of resources through approaches like non-blocking I/O, and that understanding these principles is key to building scalable applications.
The next version of JavaScript, ES6, is starting to arrive. Many of its features are simple enhancements to the language we already have: things like arrow functions, class syntax, and destructuring. But other features will change the way we program JavaScript, fundamentally expanding the capabilities of the language and reshaping our future codebases. In this talk we'll focus on two of these, discovering the the myriad possibilities of generators and the many tricks you can pull of with template strings.
The document summarizes Roman Elizarov's presentation on Kotlin coroutines at the JVM Language Summit in 2017. The presentation recapped the initial Kotlin coroutines prototype, discussed issues with its design, and outlined the solutions adopted in Kotlin 1.1. This included using suspending functions instead of async/await keywords, tail suspension to avoid stack overflows, and abstraction to provide a natural coroutine declaration syntax.
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tKonrad Malawski
A talk about the implications and context around API design. How APIs come to be and how to understand them. This talk was delivered as opening keynote, setting the tone, for the ScalaSwarm conference in Porto, Portugal in 2017.
Covers Arrays in JavaScript,
Various types of declaration and initializations,
Associative Arrays,
Nesting Arrays,
Array Functions etc.
Video tutorials available at http://youtube.com/techcbt-online
How Google AppEngine deals with digital art? how about music? a few case studies developed by Stinkdigital with Google Creative Lab and how App Engine dealt with a considerable amount of visits
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
The document discusses some of the unseen aspects of software, programming languages, and distributed systems. It covers topics like tradeoffs that must be made in software but are not visible, the impact of blocking code in Akka applications, and how traits are represented differently in Scala depending on the version. Messages are emphasized as a core abstraction in Akka rather than method calls. Some hidden features of ScalaDoc are also shown.
This document discusses Akka futures and remote actors. It covers how to use futures to retrieve results asynchronously from actors or directly. It also describes how to enable remote capabilities in an Akka project, how to create remote actors, and how to look up remote actors. Functional composition of futures using map, filter, and for comprehensions is also covered.
This document summarizes Konrad Malawski's talk on reactive programming and related topics. Konrad discusses reactive streams, Akka toolkit for building concurrent applications, actors model for concurrency, and how circuit breakers can be used as a substitute for flow control. He also talks about the origins and development of reactive streams specification to provide a common set of semantics for backpressure.
This presentation will give you a brief background to JavaScript, what it is and where it comes from. Then it will walk you through general pitfalls, best practices and more advanced topics such as object-orientation, scope and closures.
The document discusses asynchronous programming with Kotlin coroutines. It begins by describing problems with callbacks and futures for asynchronous code, such as callback hell and complex combinators. Kotlin coroutines provide a natural way to write asynchronous code using suspending functions that read like regular synchronous code but can suspend and resume. This is achieved by compiling coroutines to state machines under the hood. The document demonstrates how coroutines integrate well with libraries like Retrofit for making asynchronous HTTP requests. It also discusses different ways to launch coroutines, such as using coroutine builders.
Java Universal super class java.lang.Object is discussed comprehensively with code snippets.
Also covers:
a) Why we need inheritance and dynamic method dispatch
b) Need of a universal parent
c) Delegation and proxies
d) toString(), clone(), equals(), notify()
Presentation to the Hampton Roads Association of Environmental Educators September 15, 2011 by Debra Burrell, CVA, Volunteer Services Manager, Norfolk Botanical Garden, Norfolk VA.
This document discusses turning a crisis into unnecessary drama and offers sarcastic advice on how to make the situation worse. It recommends crowding around anyone typing, keeping information to yourself by relying on rumors and gossip instead of facts, working incredibly long hours while simultaneously changing many things and introducing new problems, and placing religious-level belief in selective statistics rather than considering all available data. The overall tone is critical of exaggerating crises and problems through panic, lack of communication, unreasonable actions, and ignoring evidence.
The document provides an overview of using Scala and Akka for building distributed sensor networks. Some key points:
- The speaker uses Scala and Akka at their company for building distributed systems to manage traffic and sensor networks.
- Akka actors are used to build distributed and fault-tolerant systems. Camel is used for integration between actors. Remote actors allow building systems that span multiple machines.
- Examples of systems built include a border control sensor network and distributed traffic management systems. Scala and Akka provide benefits like less code, fault tolerance, and ability to interoperate with existing Java systems.
- Topics covered include using Akka actors, remote actors, Camel integration,
This document provides operating instructions for a digital video camera. It contains safety information, descriptions of camera parts and their functions, instructions for using modes like recording, playback and editing, and specifications. Functions covered include recording, playback controls, menu settings, self-timer, zoom, autofocus, white balance and more. Users are advised to read the manual fully before use and handle the camera carefully.
SoundCloud allows users to upload, share and record songs for free or with a paid account, and can be accessed from an iPhone. Users can sign up, upload songs, record tracks, make groups and friends, and share their music with others around the world. Many famous artists use SoundCloud as it is easy, free and fast to share their music.
El documento lista precios y especificaciones de varios componentes de computadora como procesadores, memorias, discos duros, tarjetas de video, unidades ópticas, cajas, fuentes de poder, teclados, mouse y sistemas operativos.
Functional programming in Scala. Looking at various examples of defining a program first and executing it at some later stage, separating pure functions from side effects.
How Google AppEngine deals with digital art? how about music? a few case studies developed by Stinkdigital with Google Creative Lab and how App Engine dealt with a considerable amount of visits
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
The document discusses some of the unseen aspects of software, programming languages, and distributed systems. It covers topics like tradeoffs that must be made in software but are not visible, the impact of blocking code in Akka applications, and how traits are represented differently in Scala depending on the version. Messages are emphasized as a core abstraction in Akka rather than method calls. Some hidden features of ScalaDoc are also shown.
This document discusses Akka futures and remote actors. It covers how to use futures to retrieve results asynchronously from actors or directly. It also describes how to enable remote capabilities in an Akka project, how to create remote actors, and how to look up remote actors. Functional composition of futures using map, filter, and for comprehensions is also covered.
This document summarizes Konrad Malawski's talk on reactive programming and related topics. Konrad discusses reactive streams, Akka toolkit for building concurrent applications, actors model for concurrency, and how circuit breakers can be used as a substitute for flow control. He also talks about the origins and development of reactive streams specification to provide a common set of semantics for backpressure.
This presentation will give you a brief background to JavaScript, what it is and where it comes from. Then it will walk you through general pitfalls, best practices and more advanced topics such as object-orientation, scope and closures.
The document discusses asynchronous programming with Kotlin coroutines. It begins by describing problems with callbacks and futures for asynchronous code, such as callback hell and complex combinators. Kotlin coroutines provide a natural way to write asynchronous code using suspending functions that read like regular synchronous code but can suspend and resume. This is achieved by compiling coroutines to state machines under the hood. The document demonstrates how coroutines integrate well with libraries like Retrofit for making asynchronous HTTP requests. It also discusses different ways to launch coroutines, such as using coroutine builders.
Java Universal super class java.lang.Object is discussed comprehensively with code snippets.
Also covers:
a) Why we need inheritance and dynamic method dispatch
b) Need of a universal parent
c) Delegation and proxies
d) toString(), clone(), equals(), notify()
Presentation to the Hampton Roads Association of Environmental Educators September 15, 2011 by Debra Burrell, CVA, Volunteer Services Manager, Norfolk Botanical Garden, Norfolk VA.
This document discusses turning a crisis into unnecessary drama and offers sarcastic advice on how to make the situation worse. It recommends crowding around anyone typing, keeping information to yourself by relying on rumors and gossip instead of facts, working incredibly long hours while simultaneously changing many things and introducing new problems, and placing religious-level belief in selective statistics rather than considering all available data. The overall tone is critical of exaggerating crises and problems through panic, lack of communication, unreasonable actions, and ignoring evidence.
The document provides an overview of using Scala and Akka for building distributed sensor networks. Some key points:
- The speaker uses Scala and Akka at their company for building distributed systems to manage traffic and sensor networks.
- Akka actors are used to build distributed and fault-tolerant systems. Camel is used for integration between actors. Remote actors allow building systems that span multiple machines.
- Examples of systems built include a border control sensor network and distributed traffic management systems. Scala and Akka provide benefits like less code, fault tolerance, and ability to interoperate with existing Java systems.
- Topics covered include using Akka actors, remote actors, Camel integration,
This document provides operating instructions for a digital video camera. It contains safety information, descriptions of camera parts and their functions, instructions for using modes like recording, playback and editing, and specifications. Functions covered include recording, playback controls, menu settings, self-timer, zoom, autofocus, white balance and more. Users are advised to read the manual fully before use and handle the camera carefully.
SoundCloud allows users to upload, share and record songs for free or with a paid account, and can be accessed from an iPhone. Users can sign up, upload songs, record tracks, make groups and friends, and share their music with others around the world. Many famous artists use SoundCloud as it is easy, free and fast to share their music.
El documento lista precios y especificaciones de varios componentes de computadora como procesadores, memorias, discos duros, tarjetas de video, unidades ópticas, cajas, fuentes de poder, teclados, mouse y sistemas operativos.
Functional programming in Scala. Looking at various examples of defining a program first and executing it at some later stage, separating pure functions from side effects.
Dr. Patrick Berbon gave a presentation about clean technologies in China. He discussed China Materialia, a venture capital firm based in Shanghai that invests in cleantech startups. The presentation covered successful implementations like reducing acid rain and hybrid vehicles. It also discussed opportunities and limitations in clean energy, as well as China's fuel mix and the potential for green jobs. Dr. Berbon encouraged the audience to position themselves to take advantage of opportunities in clean technologies.
Android & Kotlin - The code awakens #03Omar Miatello
A series of 3 events for building apps with Kotlin on Android.
Introduction to Kotlin, a modern language, developed by JetBrains (those who developed the IDE on which is based Android Studio) that compared to Java is more concise, versatile and with better error handling. The code is 100% interoperable with Java, and can be used to write native Android apps or small component.
Best practices for crafting high quality PHP apps (Bulgaria 2019)James Titcumb
This prototype works, but it’s not pretty, and now it’s in production. That legacy application really needs some TLC. Where do we start? When creating long lived applications, it’s imperative to focus on good practices. The solution is to improve the whole development life cycle; from planning, better coding and testing, to automation, peer review and more. In this tutorial, we’ll take a deep dive into each of these areas, looking at how we can make positive, actionable change in our workflow.
This workshop intends to improve your skills in planning, documenting, some aspects of development, testing and delivery of software for both legacy and greenfield projects. The workshop is made up of multiple exercises, allowing dynamic exploration into the various aspects of the software development life cycle. In each practical exercise, we’ll brainstorm and investigate solutions, ensuring they are future-proofed, well tested and lead to the ultimate goal of confidence in delivering stable software.
UK Symfony Meetup, November 2012
Original presentation: https://docs.google.com/presentation/pub?id=1PLcqTby6yqSbfWlMIDHknH852DU6DO6OAgQJOtSEdsg&start=false&loop=false&delayms=3000
The document discusses code generation and abstract syntax tree (AST) transformations. It provides an overview of Project Lombok, a Java library that generates boilerplate code through annotation processing and AST transformations. It also discusses how to analyze and transform code by visiting and rewriting AST nodes, giving examples of checking for null checks and instanceof expressions.
Best practices for crafting high quality PHP apps (php[world] 2019)James Titcumb
The Best Practices for Crafting Quality PHP Applications workshop is an interactive exploration into some conventions, processes, and habits that help make better quality software. Whilst there is no single silver bullet, we will spend time discussing, supported by some practical exercises, what improvements we can make. We’ll focus on three core areas; planning, development, and testing; using a variety of practical explorations, group discussion and showing you discoveries from my own experience.
This document summarizes Nicholas C. Zakas's presentation on maintainable JavaScript. The presentation discusses why maintainability is important, as most time is spent maintaining code. It defines maintainable code as code that works for five years without major changes and is intuitive, understandable, adaptable, extendable, debuggable and testable. The presentation covers code style guidelines, programming practices, code organization techniques and automation tools to help write maintainable JavaScript.
An introduction to jQuery. How to access elements, what you can then do with them, how to create elements, a bit of AJAX and some JSON. Given as a lecture in the fh ooe in Hagenberg, Austria in December 2011.
The document discusses code generation on the JVM using various tools and frameworks. It provides an overview of Lombok for generating Java boilerplate code, Groovy AST transformations, CodeNarc for static analysis, and Spock, GContracts, and Groovy++ for framework-oriented code generation. It also discusses generating code at compile time using abstract syntax trees.
The document discusses classes, inheritance, and references in Swift. It provides examples of defining base classes, creating subclasses that inherit properties and methods from base classes, overriding methods and properties in subclasses, and how references to class instances work. The document also covers differences between classes and structures.
AmpersandJS is the front-end "non-frameworky framework". Some might consider it as Backbone 2.0. Everything is a small CommonJS module published to npm, which follows strict semver. Perfect for nodeJS devs!
Considering all the discontent with AngularJS 2.0, Ampersand is a more than viable alternative for your MEAN stack.
Have you played this Symfony? Why Symfony is great choice for Web developmentMike Taylor
Symfony a top php framework to develop high performance, scalable websites. Here Brainvire a leading symfony development company shows you why one should use symfony for their web development needs. To Get a quick quote on Symfony expertise visit: http://www.brainvire.com/symfony-framework-expertise/
The document discusses using OpenStruct and HashMap to create structured data objects in code. It shows how to define a Fund class that extends HashMap to add custom logic, and includes examples of initializing an OpenStruct instance and accessing its properties. It also introduces the morph gem for transforming between XML/HTML and Ruby objects.
Swift: Apple's New Programming Language for iOS and OS XSasha Goldshtein
The document discusses Apple's new programming language Swift. It provides an overview of Swift's key features such as variables, constants, strings, arrays, dictionaries, optional types, functions, classes, enums, extensions and generics. It also discusses how Swift aims to be a modern, type-safe language that is cleaner than Objective-C and seamlessly interoperates with existing iOS apps. The presentation concludes that Swift fixes many issues with Objective-C and most iOS developers are excited about its potential.
This document is a pitch deck containing various photos and images with captions. It discusses the high failure rate of CRMs due to lack of user adoption, citing a statistic that 70% of CRMs fail for this reason. One image shows a 1929 Cadillac tow truck. The deck is credited to an online source and is intended to be an example pitch deck for a startup.
Virtual events in C#: something went wrongPVS-Studio
Not so long ago I was working on a new C# diagnostic - V3119 - for the PVS-Studio static code analyzer. The function of this diagnostic is to detect potentially unsafe constructions in the source code of C#, related to the usage of virtual and overridden events. Let's try to sort out, what's wrong with virtual events in C# - the principle of this diagnostic, and why Microsoft doesn't recommend using virtual and overridden events.
Kotlin is a statically typed language that runs on the JVM, Android and browsers. It was developed by JetBrains and had its first stable release in February 2016. Some key features of Kotlin include null safety, lambdas, extension functions, and delegation which allow avoiding null checks and reducing boilerplate code compared to Java. It also integrates well with Android by reducing the need for findViewById and providing libraries like Anko that simplify common tasks. Performance tests have shown Kotlin to be as fast as Java.
Scala is a multi-paradigm programming language that runs on the Java Virtual Machine. It is both object-oriented and functional, with support for immutable data and concise syntax. Scala has gained popularity due to its advantages like type safety, concurrency support, and interoperability with Java. However, some of Scala's advanced features can be difficult to read and use for beginners, and tooling support is not as robust as Java. Overall, Scala represents a promising approach that prioritizes simplicity over ease of use.
Writing JavaScript as a hobby and writing JavaScript as a job are two very different things. Learn some common practices for making your JavaScript friendly to a team environment.
Similar to Bootstrapping a Scala Mindset (Scala eXchange 2014) (20)
Utilocate offers a comprehensive solution for locate ticket management by automating and streamlining the entire process. By integrating with Geospatial Information Systems (GIS), it provides accurate mapping and visualization of utility locations, enhancing decision-making and reducing the risk of errors. The system's advanced data analytics tools help identify trends, predict potential issues, and optimize resource allocation, making the locate ticket management process smarter and more efficient. Additionally, automated ticket management ensures consistency and reduces human error, while real-time notifications keep all relevant personnel informed and ready to respond promptly.
The system's ability to streamline workflows and automate ticket routing significantly reduces the time taken to process each ticket, making the process faster and more efficient. Mobile access allows field technicians to update ticket information on the go, ensuring that the latest information is always available and accelerating the locate process. Overall, Utilocate not only enhances the efficiency and accuracy of locate ticket management but also improves safety by minimizing the risk of utility damage through precise and timely locates.
Do you want Software for your Business? Visit Deuglo
Deuglo has top Software Developers in India. They are experts in software development and help design and create custom Software solutions.
Deuglo follows seven steps methods for delivering their services to their customers. They called it the Software development life cycle process (SDLC).
Requirement — Collecting the Requirements is the first Phase in the SSLC process.
Feasibility Study — after completing the requirement process they move to the design phase.
Design — in this phase, they start designing the software.
Coding — when designing is completed, the developers start coding for the software.
Testing — in this phase when the coding of the software is done the testing team will start testing.
Installation — after completion of testing, the application opens to the live server and launches!
Maintenance — after completing the software development, customers start using the software.
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
Mobile app Development Services | Drona InfotechDrona Infotech
Drona Infotech is one of the Best Mobile App Development Company In Noida Maintenance and ongoing support. mobile app development Services can help you maintain and support your app after it has been launched. This includes fixing bugs, adding new features, and keeping your app up-to-date with the latest
Visit Us For :
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...kalichargn70th171
A dynamic process unfolds in the intricate realm of software development, dedicated to crafting and sustaining products that effortlessly address user needs. Amidst vital stages like market analysis and requirement assessments, the heart of software development lies in the meticulous creation and upkeep of source code. Code alterations are inherent, challenging code quality, particularly under stringent deadlines.
Launch Your Streaming Platforms in MinutesRoshan Dwivedi
The claim of launching a streaming platform in minutes might be a bit of an exaggeration, but there are services that can significantly streamline the process. Here's a breakdown:
Pros of Speedy Streaming Platform Launch Services:
No coding required: These services often use drag-and-drop interfaces or pre-built templates, eliminating the need for programming knowledge.
Faster setup: Compared to building from scratch, these platforms can get you up and running much quicker.
All-in-one solutions: Many services offer features like content management systems (CMS), video players, and monetization tools, reducing the need for multiple integrations.
Things to Consider:
Limited customization: These platforms may offer less flexibility in design and functionality compared to custom-built solutions.
Scalability: As your audience grows, you might need to upgrade to a more robust platform or encounter limitations with the "quick launch" option.
Features: Carefully evaluate which features are included and if they meet your specific needs (e.g., live streaming, subscription options).
Examples of Services for Launching Streaming Platforms:
Muvi [muvi com]
Uscreen [usencreen tv]
Alternatives to Consider:
Existing Streaming platforms: Platforms like YouTube or Twitch might be suitable for basic streaming needs, though monetization options might be limited.
Custom Development: While more time-consuming, custom development offers the most control and flexibility for your platform.
Overall, launching a streaming platform in minutes might not be entirely realistic, but these services can significantly speed up the process compared to building from scratch. Carefully consider your needs and budget when choosing the best option for you.
Mobile App Development Company In Noida | Drona InfotechDrona Infotech
Looking for a reliable mobile app development company in Noida? Look no further than Drona Infotech. We specialize in creating customized apps for your business needs.
Visit Us For : https://www.dronainfotech.com/mobile-application-development/
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j
Dr. Jesús Barrasa, Head of Solutions Architecture for EMEA, Neo4j
Découvrez les dernières innovations de Neo4j, et notamment les dernières intégrations cloud et les améliorations produits qui font de Neo4j un choix essentiel pour les développeurs qui créent des applications avec des données interconnectées et de l’IA générative.
Atelier - Innover avec l’IA Générative et les graphes de connaissancesNeo4j
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Allez au-delà du battage médiatique autour de l’IA et découvrez des techniques pratiques pour utiliser l’IA de manière responsable à travers les données de votre organisation. Explorez comment utiliser les graphes de connaissances pour augmenter la précision, la transparence et la capacité d’explication dans les systèmes d’IA générative. Vous partirez avec une expérience pratique combinant les relations entre les données et les LLM pour apporter du contexte spécifique à votre domaine et améliorer votre raisonnement.
Amenez votre ordinateur portable et nous vous guiderons sur la mise en place de votre propre pile d’IA générative, en vous fournissant des exemples pratiques et codés pour démarrer en quelques minutes.
E-commerce Application Development Company.pdfHornet Dynamics
Your business can reach new heights with our assistance as we design solutions that are specifically appropriate for your goals and vision. Our eCommerce application solutions can digitally coordinate all retail operations processes to meet the demands of the marketplace while maintaining business continuity.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Crescat
Crescat is industry-trusted event management software, built by event professionals for event professionals. Founded in 2017, we have three key products tailored for the live event industry.
Crescat Event for concert promoters and event agencies. Crescat Venue for music venues, conference centers, wedding venues, concert halls and more. And Crescat Festival for festivals, conferences and complex events.
With a wide range of popular features such as event scheduling, shift management, volunteer and crew coordination, artist booking and much more, Crescat is designed for customisation and ease-of-use.
Over 125,000 events have been planned in Crescat and with hundreds of customers of all shapes and sizes, from boutique event agencies through to international concert promoters, Crescat is rigged for success. What's more, we highly value feedback from our users and we are constantly improving our software with updates, new features and improvements.
If you plan events, run a venue or produce festivals and you're looking for ways to make your life easier, then we have a solution for you. Try our software for free or schedule a no-obligation demo with one of our product specialists today at crescat.io
Transform Your Communication with Cloud-Based IVR SolutionsTheSMSPoint
Discover the power of Cloud-Based IVR Solutions to streamline communication processes. Embrace scalability and cost-efficiency while enhancing customer experiences with features like automated call routing and voice recognition. Accessible from anywhere, these solutions integrate seamlessly with existing systems, providing real-time analytics for continuous improvement. Revolutionize your communication strategy today with Cloud-Based IVR Solutions. Learn more at: https://thesmspoint.com/channel/cloud-telephony
Transform Your Communication with Cloud-Based IVR Solutions
Bootstrapping a Scala Mindset (Scala eXchange 2014)
1. Photo by ColorblindRain - Creative Commons Attribution-NonCommercial License https://www.flickr.com/photos/11594851@N00 Created with Haiku Deck
2. Photo by Zach Dischner - Creative Commons Attribution License https://www.flickr.com/photos/35557234@N07 Created with Haiku Deck
3. Photo by André Hofmeister - Creative Commons Attribution-NonCommercial License https://www.flickr.com/photos/54786327@N00 Created with Haiku Deck
4.
5. Photo by Leo Reynolds - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/49968232@N00 Created with Haiku Deck
6. Photo by Gueоrgui - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/49722723@N00 Created with Haiku Deck
7. Photo by Infidelic - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/87472505@N00 Created with Haiku Deck
8. Photo by gruntzooki - Creative Commons Attribution-ShareAlike License https://www.flickr.com/photos/37996580417@N01 Created with Haiku Deck
9. Photo by Peter Rivera - Creative Commons Attribution License https://www.flickr.com/photos/13057030@N00 Created with Haiku Deck
10.
11.
12.
13. Photo by thepartycow - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/44124327211@N01 Created with Haiku Deck
14. Photo by @Doug88888 - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/29468339@N02 Created with Haiku Deck
15. Photo by Masa Sakano - Creative Commons Attribution-ShareAlike License https://www.flickr.com/photos/42548354@N04 Created with Haiku Deck
16. Photo by Brianellwood1 - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/92848318@N05 Created with Haiku Deck
17. val v = Vector(1, 2, 3, 4)
v.foreach( print("> " + n) )
// from: Atomic Scala v1.1
18. def show(n: Int): Unit = {
print("> " + n)
}
val v = Vector(1, 2, 3, 4)
v.foreach(show)
// from: Atomic Scala v1.1
19. Photo by These * Are * My * Photons - Creative Commons Attribution-NonCommercial License https://www.flickr.com/photos/61762350@N06 Created with Haiku Deck
20. // Everything is an expression
// including "statements"
if(1 > 0) {
"It's true!“
} else {
"It’s false!"
}
// adapted from: Atomic Scala v1.1
21. // Everything is an expression
// including "statements"
val result =
if(1 > 0) {
"It's true!"
} else {
"It's false!"
}
println(result) // “It’s true!”
// adapted from: Atomic Scala v1.1
22. // Everything is an expression,
// including “blocks“
val calc =
{
val i1 = 2
val j1 = 4/i1
i1 * j1
}
println(calc)
// from: Atomic Scala v1.1
23. Photo by plaits - Creative Commons Attribution License https://www.flickr.com/photos/90198349@N04 Created with Haiku Deck
24. // Infix Notation means that
// this...
a.method(b)
// ... can be written like this...
a method b
// from: Atomic Scala v1.1
25. // And Infix Notation also means
// that this...
a.method()
// ... can be written like this...
a method
// from: Atomic Scala v1.1
26. Photo by keoshi - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/46567414@N00 Created with Haiku Deck
27. class Simple(val s:String) {
def getA() = s
val getB = s + "ya"
}
val simple = new Simple("Hi")
// from: Atomic Scala v1.1
28. class Simple(val s:String) {
def getA() = s
val getB = s + "ya"
}
val simple = new Simple("Hi")
simple.getA() // res0: String = Hi
// from: Atomic Scala v1.1
29. class Simple(val s:String) {
def getA() = s
val getB = s + "ya"
}
val simple = new Simple("Hi")
simple getA // res4: String = Hi
// from: Atomic Scala v1.1
30. class Simple(val s:String) {
def getA() = s
val getB = s + "ya"
}
val simple = new Simple("Hi")
simple getB // res5: String = Hiya
// from: Atomic Scala v1.1
31. Photo by MTSOfan - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/8628862@N05 Created with Haiku Deck
32. Photo by Jonohey - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/23465120@N00 Created with Haiku Deck
33. Photo by Dru! - Creative Commons Attribution-NonCommercial License https://www.flickr.com/photos/36543076@N00 Created with Haiku Deck
34. def inc: (i:Int) = i + 1
// this is a TOTAL function
// from: "Programming in Scala
// (2nd Ed.)", pp 332-333
35. def inc (i:Int) = i + 1
// this is a TOTAL function
def fraction (d:Int) = 42 / d
// this is a PARTIAL function
// It is not defined for d == 0
// E.g. It’ll throw an exception
// if called with 0
// from: "Programming in Scala
// (2nd Ed.)", pp 332-333
37. import scala.collection.immutable._
val second:
PartialFunction[List[Int],Int] = {
case x :: y :: _ => y
}
// from: "Programming in Scala
// (2nd Ed.)", pp 332-333
38. import scala.collection.immutable._
val second:
PartialFunction[List[Int],Int] = {
case x :: y :: _ => y
}
second.isDefinedAt(List(5,6,7))
res30: Boolean = true
// from: "Programming in Scala
// (2nd Ed.)", pp 332-333
39. import scala.collection.immutable._
val second:
PartialFunction[List[Int],Int] = {
case x :: y :: _ => y
}
second.isDefinedAt(List())
res30: Boolean = false
// from: "Programming in Scala
// (2nd Ed.)", pp 332-333
41. class Problem(val msg:String)
extends Exception
def test(n:Int) =
try {
f(n)
} catch {
case err:Problem => s“whoops“
case err:Disaster => s“BOOM!“
}
// from: Atomic Scala v1.1
42. Photo by jhull - Creative Commons Attribution License https://www.flickr.com/photos/18937122@N00 Created with Haiku Deck
43. case class Cat (name:String,
age:Int)
// from: Atomic Scala v1.1
44. Photo by littlechay - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/59012878@N00 Created with Haiku Deck
45. def acceptAnything(x:Any):String = {
x match {
case "Exactly" => "An exact match!"
case s:String => "A String: " + s
case i:Int if (i < 20)
=> s"Int < 20: $i"
case p:Person => s"A person ${p.name}"
case _ => "I don't know what!"
}
}
// from: Atomic Scala v1.1
46. def findCatsCalledBob(x:Cat):String = {
x match {
case Cat("Bob", age)
=> s"Got $age y/o cat called Bob"
case _ => "I don't know what"
}
}
// from: My own Brain
47. Photo by dharma communications - Creative Commons Attribution-NonCommercial License https://www.flickr.com/photos/38475709@N00 Created with Haiku Deck
48. Photo by magnezja - Creative Commons Attribution License https://www.flickr.com/photos/81923938@N02 Created with Haiku Deck
49. Photo by afagen - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/51035749109@N01 Created with Haiku Deck
50. Photo by brewbooks - Creative Commons Attribution-ShareAlike License https://www.flickr.com/photos/93452909@N00 Created with Haiku Deck
51. Photo by DoNotLick - Creative Commons Attribution License https://www.flickr.com/photos/45972156@N04 Created with Haiku Deck
52. Photo by Anita363 - Creative Commons Attribution-NonCommercial License https://www.flickr.com/photos/61897811@N00 Created with Haiku Deck
53. Photo by kellerabteil - Creative Commons Attribution-NonCommercial License https://www.flickr.com/photos/7815396@N07 Created with Haiku Deck
54. val maybeFirstName : Option[String] =
Some("Mark")
val maybeSurname : Option[String] = None
// from: http://www.markhneedham.com/blog/2011/09/15/scala-for-
// comprehensions-with-options/
55. case class Person(firstName:String,
surname:String)
val maybeFirstName : Option[String] =
Some("Mark")
val maybeSurname : Option[String] = None
for { firstName <- maybeFirstName;
surname <- maybeSurname }
yield Person(firstName, surname)
// res01: Option[Person] = None
// from: http://www.markhneedham.com/blog/2011/09/15/scala-for-
// comprehensions-with-options/
56. case class Person(firstName:String,
surname:String)
val maybeFirstName : Option[String] =
Some("Mark")
val maybeSurname : Option[String] =
Some("Needham")
for { firstName <- maybeFirstName;
surname <- maybeSurname }
yield Person(firstName, surname)
// res01: Option[Person] =
Some(Person(Mark,Needham)
// from: http://www.markhneedham.com/blog/2011/09/15/scala-for-
// comprehensions-with-options/
57. Photo by tiswango - Creative Commons Attribution-ShareAlike License https://www.flickr.com/photos/26395196@N00 Created with Haiku Deck
58. Photo by Podknox - Creative Commons Attribution License https://www.flickr.com/photos/91198056@N00 Created with Haiku Deck
59. val maybeFirstName : Option[String] =
Some("me")
val maybeSurname : Option[String] = None
val result = maybeFirstName.map(_.toUpperCase)
// result : Option[String] = Some(ME)
val result = maybeSurame.map(_.toUpperCase)
// result: Option[String] = None
// from: http://alvinalexander.com/
// scala/collection-scala-flatmap-examples-
// map-flatten
60. Photo by chriscom - Creative Commons Attribution-ShareAlike License https://www.flickr.com/photos/31192329@N00 Created with Haiku Deck
62. Photo by taquiman - Creative Commons Attribution-ShareAlike License https://www.flickr.com/photos/10705232@N06 Created with Haiku Deck
63. case class Person(name: String,
isMale : Boolean, children: Person*)
val lara = Person("Lara", false)
val bob = Person("Bob", true)
val julie = Person("Julie", false, lara, bob)
val persons = List(lara, bob, julie)
persons filter (p => !p.isMale)
res0: List[worksheet2.Person] =
List(Person(Lara,false,WrappedArray()),
Person(Julie,false,WrappedArray(...)))
// from: Programming in Scala (2nd Ed.)
64. Photo by Peter Hellberg - Creative Commons Attribution-ShareAlike License https://www.flickr.com/photos/75489014@N00 Created with Haiku Deck
65. val result = for {
n <- v // GENERATOR
if n < 10
valueToYield = n
} yield valueToYield
// from: Atomic Scala v.1.1
66. val result = for {
n <- v
if n < 10 // FILTER
valueToYield = n
} yield valueToYield
// from: Atomic Scala v.1.1
67. val result = for {
n <- v
if n < 10
valueToYield = n // DEFINITION
} yield valueToYield
// from: Atomic Scala v.1.1
68. Photo by pico2009 - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/24823485@N06 Created with Haiku Deck
69. // Single Generator plus filter?
val v = Vector(1,2,3,5,6,7,8,10,13,14,17)
val result = for {
n <- v
if n % 2 == 0
} yield n * 2
// Desugars to:
val resultMap =
v.withFilter(n => n % 2 == 0)
.map(n => n * 2)
// res1: Vector(4,12,16,20,28)
// from: My Own Brain
70. Photo by td stevenson - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/79471249@N00 Created with Haiku Deck
71. // Multiple Generators
val v = Vector(1,2,3,5,6,7,8,10,13,14,17)
val w = Vector(1)
val result = for {
x <- v
y <- w
} yield x == y
// Desugars to:
val resultMap2 =
v.flatMap{ x => w.map{ y => x == y } }
// res2: Vector(true, false, false, false,…)
// from: My Own Brain
72. // Multiple Generators
val v = Vector(1,2,3,5,6,7,8,10,13,14,17)
val w = Vector(1)
val result = for {
x <- v
y <- w
} yield x == y
// Desugars to:
val resultMap2 =
v.map{ x => w.map{ y => x == y } }
// res2: Vector(Vector(true), Vector(false),…)
// from: My Own Brain
73. Photo by Deetrak - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/9254684@N05 Created with Haiku Deck
74. Photo by ilkerender - Creative Commons Attribution License https://www.flickr.com/photos/76805197@N00 Created with Haiku Deck
75. Tips:
• Read closely. (Slowly)
• Beware your Java-sense
• But don’t ignore it
• Unlearning is HARD,
and it HURTS
Photo by twiga269 ॐ FEMEN - Creative Commons Attribution-NonCommercial License https://www.flickr.com/photos/24257706@N07 Created with Haiku Deck
76. • Atomic Scala (Eckel & Marsh)
• The Scala Koans
• Scala for the Impatient (Horstmann)
• Twitter’s Scala School
• Introduction to Functional Programming
(Coursera)
• Programming in Scala (2nd Ed.) (Odersky,
Venners, Spoon)
• The Scala Language Specification
(Seriously)
Photo by ecstaticist - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/41864721@N00 Created with Haiku Deck
77. • Implicits
• Type Classes
• Learn you a Haskell
• Revisit
Photo by Jack Lazar - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/38638219@N04 Created with Haiku Deck
78.
79. Photo by a9r - Creative Commons Attribution-NonCommercial-ShareAlike License https://www.flickr.com/photos/34788578@N08 Created with Haiku Deck
Editor's Notes
“Scala is a Cliff” – that’s my quote – no-one other than me said it, but Chad Fowler got pretty close:
"Scala is difficult to learn“ he wrote in his forward to Scala in Action, from 2013
“Scala is a lot to chew on. It’s got what seems way too many features.”
He continued:
“You’re going to hurt yourself along the way”
“[However] it’s these jagged edges that improve us. If you approach this climb properly, you’ll reach the top sharper, more open-minded, and, best of all, less afraid.“
I wish I’d paid more attention to this when I started learning Scala.
This presentation pretty much deals with how I learned this the hard way.
* Senior Java Dev / Dev Lead
* 5 or so years ago I “Learned” Ruby (ruby-eye-for-the-java-guy.blogspot.com) to get some DynaLang in my life (and done some Groovy-fiddling)
* For the past few years I’ve been Learning Scala to get some Functional in my life
As well as this I:
* Stopped studying Maths at High School (Age 16 yrs)
* And at university too the easy option and studied Psychology at University (fluffy!)
So given that, and assuming you’re not totally put off, whats my aim here?
By telling you things I learned, I can reduce your pain (N.b. It’ll still hurt)
How?
* By mapping out the key stages involved in my moving from a Java to the beginnings of a Scala mindset
* And by telling you some things few folks remember to tell you
And what do you get if you follow this path?
Rather facetiously I’m gonna claim that “soon you’ll be using Monadic constructs without even feeling special.”
But what this really means is you’ll have a better foundation mental model of the Scala language
Which will allow you launch into the next challenges the language presents
as you encounter more and more of its richness.
So are we ready? Lets go.
Part 1: Everything you know is wrong – in which we learn just how far Andrew had to go when he started
First up, confession time. I was so clueless about Scala when I started I even had a misconception around the name:
IS:
* Scales nicely - Play and Reactive Programming
* Parallelises well - Immutability & Actors
* More productive - High Level so much less boiler plate
* More team members - Statically Typed -> Refactorable
BUT that's not where the name comes from…
In reality, it turns out that Scala is so named because it “grows with the demands of its users” (Programming in Scala 2nd Ed.)
It’s layered – “Scala is much more like a bazaar than a cathedral” (Programming in Scala 2nd Ed.)
It’s designed to be extended and adapted,
in that it’s Scala all the way down,
via libraries that nevertheless feel native.
Consequently, you can apply it to a wide range of tasks.
But you can also (must) bootstrap your way in.
What do I mean by all this? Patience patience, we’ll soon see.
But first, more misconceptions.
The next thing to bear in mind is that, whether you Like it or not: There Will Be Math(s)™
That's fine. But what you need to consider is that this maths is EVERYWHERE:
* It inspired the much terser, and mathematical-idiom driven syntax
* It means things are in the “wrong place”, such as something as fundamental as the parameter types and return type on method signatures - because they're in the "right place" for mathematical notation
* and they expect operator overloading (i.e. more “weird looking” code)
* And maths folks use a lot of chaining – so you’ll see a lot of that
In short, you're stumbling into an entirely different world
And that’s the first reason why I claim “everything you know is wrong” – everything I knew certainly was.
Or it felt like that at one point.
There’s a reason for all this maths – Scala is Functional and not Imperative.
And functional == maths
I need to hammer this home (I wish someone had for me), and also unpick it a little: Scala is Functional not Imperative.
(N.b. the fact its also Object Oriented matters not a jot here.)
So before we complete this section, let’s have an overview of the specific aspects Functional compared to Imperative programming:
Here’s what underpins a functional mindset:
1. Consider what information and transformations are required on data (rather than the steps and resulting state changes)
2. That's because these state changes are non-existent (or mega-frowned upon)
3. Which means that the order of execution is of low importance
4. and the focus is primarily on functions and data as the primary manipulation units.
That’s almost diametrically opposed to how I, and I guess you think when you code in Java
(From: http://msdn.microsoft.com/en-GB/library/bb669144.aspx)
To move to this new mindset, which is essential in order to wrap your head round something like Scala, you must jettison a lot of what you currently hold dear:
* the idiom (the “names of things”)
* the familiar syntax (even the "places of things")
* Pretty much your entire way of thinking about code:
* No more State / Mutability (hands off!)
* Worrying about how things work inside (you don't need to care)
* And remembering the order in which they work (ditto)
* There’s no more Looping for you ("iterate" / "traverse" instead)
* Or functions only hanging off objects (a fundamental OO concept - now they can just float around...)
But its not all bad. If you bear this list in mind as you go you might remember to think “I’m feeling uncomfortable / experiencing pain; this probably means I’m still holding onto an imperative mindset.
Let go.... Learn to let go...
OK, so all we do is stop thinking in an imperative way and start learning to think functionally. Simple right?
“Sure, I have my list right here…”
Well no, because the Java-imperative baggage we have with us runs deep.
This means that some stuff about Scala is seemingly so simple when you first come across it you’re like, “uhuh, got it. Next!”
but then you need to build on this and it turns out this dismissive approach didn’t prepare you.
Scala’s subtleties around things like its support for the Uniform Access Principle and related concepts is one of these key areas.
To examine it we’ll revise the following:
* First up: functions as first-class citizens
* Next: “everything is an expression"
* And finally: infix notation
When you look at them in close proximity you have your first taster of functional programming:
– look back at ourfour-point lists.:
You don’t care how something is done,
or in which order it’s done,
you just care about the result
This lets you /let /go of a lot of mental baggage. That's the subtle (but potentially spectacularly large) benefit.
image "rock"
Lets start quite slowly. First up, it's reassuring to remember that in Scala, objects are still objects:
In fact I discovered that far from being hard to grasp,
the core class hierarchy in Scala was like a welcome friend
– it gets so much more right than Java did:
everything is an object
But did you spot the first subtlety slipping past you there?
"Everything is an object".
Naturally you'd expect this to mean that functions are objects too.
And they are. Lets revise what this means with some code…
image "pebbles"
Here’s some not very surprising code: apart from perhaps that foreach is a higher order function which means it takes a function as a parameter.
The print(“> “ + n) is the (anonymous) function being passed to it.
And then just pass the new “show” function-object to foreach.
Beautiful.
Next: “Everything is an expression”
Now we've got our toe-hold in functions being first class,
lets revise the next "tiny" change:
Everything is an Expression.
What?
Well, in Java, we have "statements" - "a statement in a programming language does not produce a result. In order for the statement to do something interesting, it must change the state of its surroundings. Another way of putting this is “a statement is called for its side effects” (that is, what it does other than producing a result)." (from Atomic Scala v.1.1, Eckel and Marsh)
As a memory aid Bruce and Dianne suggest we think: "A STATEMENT CHANGES STATE"
And so what about expressions?:
Again, as a memory aid Bruce and Dianne suggest we think "One definition of 'express' is 'to force or squeeze out,' as in 'to express the juice from an orange.' So:
AN EXPRESSION EXPRESSES
That is, it produces a result." (from Atomic Scala v.1.1, Eckel and Marsh)
Again, lets look at it in action:
In Scala, “if” is an expression
As we can see here…
“for” is an expression too, but we’ll get to them later on.
This means that “Try-catch” blocks are expressions
Ok. We’re still good – a hand-hold
– Finally we’ll revise infix notation.
image "stone"
Again, when glanced at cursorily, all you see here is "nice, no dots or parens - good for DSLs” (look at me, I've read a book on DSLs!).
Wait! Come back! You missed something...
Lets refresh our memories…
Clearly you can drop the dots, and the parens, and you now only have to put the method name between the objects
(or after the first if there's only one object).
Note, it also only works if there is zero or one argument - more than that and the compiler wouldn't know how to cope sadly.
This is almost too simple, why am I telling you all this, and wasting your time?
OK, we’ve got our 3 anchor points.
Lets now move on and consider the Uniform Access Principle
We've now got everything in mind to be able to make real deep sense of the "Uniform Access Principle":
Put forth by Bertrand Meyer. It boils down to:
there should be no difference between working with an attribute, precomputed property, or method/query.
(From: https://en.wikipedia.org/wiki/Uniform_access_principle)
Lets have that again: "there should be NO DIFFRERENCE between working with an attribute, precomputed property, or method/query"
To us this means that the code should look the same, whether you’re accessing a function or a value (val or var) – whatever the case, your client code should not be any different
Let’s see how this works in Scala.
image "rock"
Here we’ve got a class called simple. It has one constructor argument, which lets us set a single field: a String s.
We’ve also got two functions, getA and getB and a property “getC” (so named for clarity – bear with me).
We then instantiate simple with the constructor parameter “Hi”
Finally we’re going to test it by calling it’s various functions:
First up, lets examine the parens: dot-getA-parens – gives us “Hi” as expected
GetA-no-parens – “Hi”
Next dot-getC-no-parens – also “Hiya” hmmm.
That’s a val we’re accessing there, and the value is calculated at call time, but it looks like the method calls…
Now lets drop the dots…
And so ladies and gentlemen, we now have your first bit of Scala power right here
What? Infix notation? So what?
Well, lets consider for a minute what we’re getting here:
With infix we’re relieved from worrying about the implementation of something – is it a value or a function? Don’t care
We get a similar thing with functions as objects – the difference between functions and other objects is diminished – you care less what something is too
And again with everything is an expression? – again, everything returns something, and side effects are frowned on – again we let go of what “it” is a little more
As a result of all of these things we’re helped to move towards functional thinking:
* Functions and attributes become virtually the same – from client code anyway
* Side-effects are down-graded
Sound tenuous? Perhaps, but this for me was the first fundamental realisation around Scala and one which has since served most to kick me out of my Java-imperative torpor
But I feel impelled to point out that this can be painful too.
It takes trust to know that you can forego all this extra mental-loading.
The letting go can lead to a feeling of mental vertigo as you lose so many of your Imperative-crutches.
It is at this point that you realise that for some (myself included) the verbosity, and explicit-ness of Java served as a safety blanket.
Don't underestimate the significance of this mental unloading.
Also don't underestimate the power of the pull of the "old way" - when reading some Scala code hurts; stop, think - it might be your brain not letting go.
image "boulder"
Ok, that’s the “watch out for the hidden subtleties in things that seem - on the surface - patently obvious” trip-up, and associated goodness once we realise and work through it.
Next we get to consider a slightly more involved area:
Imagine if you will that there is a feature of the Scala language which has been designed to do something, and do it well.
Imagine also that the keywords chosen make this link supremely clear,
and all the syntactic sugar built up around it makes sense too,
but you hear about it far earlier in the learning process,
as it turns out to be a selling point to moving to the language (it’s a sizzle all on its own).
As a result, we (i.e. I) frequently fail to appreciate the full possibilities of pattern matching
Case classes are one of these such circumstances.
Not only that, but also when you grok them - and a supporting concept, PartialFunctions in this case - you get an early taste of the mental model and internal consistency of Scala – of the “Scala all the way down” I mentioned at the start.
That’s where we want to get in this section.
It’s a view that empowers and re-vitalises you, and is one that is worth savouring.
We’ll use as our engine to drive this section the much discussed concept of Pattern Matching
image "cliff"
Lets take this slowly. Lets not start with Case Classes. Lets instead introduce / refresh Partial Functions.
Firstly, where does the name come from? From maths of course.
image "climber"
def inc(i: Int) = i + 1 // this is a TOTAL function
def fraction(d: Int) = 42 / d // this is a PARTIAL FUNCTION as it is not defined for d== 0 – it will throw an exception if called like this
REMEBER: A complete function can be treated as a partial function
Here, the complier will complain the match is not exhaustiveIt'll blow up if you pass it an empty list
Now here’s the clever bit – at this stage of Scala-development learning, we likely don’t need to create explicit PartialFunctions which are a Trait offered by Scala,
but we have been using them – because every time we put “{ case …” we have one.
Lets look at this in more detail.
Here’s a new function called second the body of which is a “{ case”
It’s clearly a partial function as we’ve not covered the cases when the list is empty of only has one element.
And indeed it is – “{ case … “ is a literal for a partial function.
In fact, that previous function is equivalent to this,
And in fact, courtesy of Scala’s translation work,
our second instance gives us access to the isDefinedAt and apply methods
which come from the PartialFunction trait
without our having had to implement them
Before we move on from Partial Functions, lets make the final leap of this sub-section
to a circumstance where we’ve likely seen the “case” keyword already
and their existence as literals for PartialFunctions in this circumstance will seem quite sensible now:
We’ve seen them in catch blocks for example, as individual case expressions …
or, more likely, as “case sequences”.
In these cases, our concept of these sequences as literal PartialFunctions, with an entry point per case to the function, makes perfect, logical sense.
Knowing this little equivalence trick helped me greatly in grasping a lot of code as moved through the world of Scala.
We’re almost ready to look at one of those instances now – Pattern Matching with the match keyword – but lets not leap into that without first reminding ourselves about case classes
Now there came a point when I was surprised to learn that Case Classes aren’t just a way to save a lot of typing,
despite frequently being introduced in that way.
In fact they’re designed “to allow pattern matching on objects without requiring a large amount of boilerplate” (Odersky, Venners, Spoon)
Hence the name, which by now ought to have a little more resonance for you
- adding the keyword “case” to definitions of classes means they can be used in pattern-matches
image "climber"
As a refresher - here’s what one looks like.
But behind the scenes you’re getting a lot of bang for your buck.
Just like the case-based PartialFunction shorthand, the “case” keyword again gives us a lot for free.
By adding it we get:
* “Natural” implementations of toString, hashcode and equals. N.b. in Scala ‘==‘ always delegates to equals
* All args in the parameter list implicitly get a “val” prefix so they are maintained as immutable fields
* Which means that all fields in Case Classes are immutable by default
* Factory methods with the same name as the class: No more “new”. NOTE: looks very nice when nested
* A copy method, using named and default parameters
This all means that when you write pattern matching code, you can fit a lot, in a small space - a small space like a pattern matching block.
Ludicrously, deceptively, simple.
And so finally we get to Pattern Matching.
My first encounter with this concept was when it was being touted as a major reason to dump everything and move to Scala. Perhaps that’s overstating the case, but folks get pretty excited about it.
But it does bring great benefits - “Pattern matching is a generalization of switch from C/Java to class hierarchies”. (Coursera session 4-7)
In short, it brings polymorphism to the concept of “switch”, which when understood clearly and used well can be incredibly powerful.
image "ice climbing"
Lets do a little deck clearing yet again :-
There are lots of flavours of patterns in pattern matching, but we only want to look at one here – case class matchers – so here are all the other major options to get them out of the way:
matching on a constant,
matching on a type,
matching on a type with a guard,
matching on a type with a guard and some nice value extraction,
wildcard matching – we’ll not go into that.
Now we know what we’re not thinking about, lets look very quickly at a Case Class matcher
Here’s the type of cleverness we can do when we’re matching with Case classes. This excerpt is the equivalent of saying:
“match all cats with the name “Bob” and print their age”.
Note we’re matching on the construction parameters that make up the Cat.
Clearly, even from this little snippet its clear that this can get really powerful, but you’ll have to take my word for it – we’ve got to keep moving – on to the pros, cons, gotchas and most importantly our mindset lessons to learn.
(But if you want to know more, take a look at the Pattern Matching chapter in “Programming in Scala”)
Any gotchas worth highlighting?
Two here:
Patterns are tried in the order they are coded (because they de-sugar into a load of nested "If"s)
Partial Functions are NOT "partially applied functions" which seems to have confused more folks than just me, and its not helped by the fact that some folks Scala tutorials on the topic get it wrong.
(Could someone tidy up the internet please?)
image "climbing rope"
Finally we get to our mindset slide.
The mindset that this deeper understanding of Scala’s Pattern Matching brings is for me at least the biggest benefit of all,
far greater than the “polymorphic switch” I trailed at the top of this section.
Because case lists are partial functions, and because we can group them together and use with “match”;
and because Scala is internally consistent in the fact it maps these concepts to real objects,
it takes the Pattern Matching and firmly embeds it into the bigger Object Oriented picture,
lifting it far above simply being a syntactic construct.
As someone coming from Java, I really appreciated that. It meant it stuck as a concept.
Bear this “Scala’s made of Scala” benefit in mind because we’re now going to tackle our first peak – for-comprehensions – and this will help us a lot.
We’ve bootstrapped ourselves a long way in a short period of time.
Now we’ve got enough under our belt to make a push at a peak – the for-comprehension.
* We're seen so far that Scala is constructed, at least in part, from a lot of cross-cutting concepts, but we’ve not yet looked explicitly at de-sugaring?
* I didn’t go into this aspect in the last section because, despite being “made up” of Partial Functions, when you desugar a pattern match (perhaps unexpectedly) we get a super-nested set of if-expressions
With for-comprehensions we’re dealing with a concept that is not only made up of other, smaller chunks of Scala, but we’re also dealing with something which explicitly de-sugars a little more nicely
But that alone isn’t reason enough to go through the palaver of desugaring – we’ll also find that unlike Pattern Matching, for-comprehensions work in a way completely different from that which you’d expect. And so by de-sugaring we’ll learn not only gain an understanding of the contributing constituent parts, but also the wider the construct in question.
Not only this, but by understanding how for-comprehensions are constructed we’ll be able to start to get a glimpse of our future Scala selves
In this final section we’ve a slightly convoluted path we’re going to follow, but its worth it
we’ll be clear first about what we’re about to consider
Then orient ourselves in our mental starting place – picking Option[T] as a nice way to do this
We’ll then look at Option[T] in a for comprehension
Before stepping back to refresh the functions under the covers
Before finally facing the elements of the for head on,
and mapping out under the covers elements to each of them
Before we move on, after the previous "partial" / "partially applied" stramash, and because it’s important to the next slides, here's the scoop:
You will find the construct that we’re about to look at called variously:
- a "for comprehension"
- or simply a "comprehension"
- or a "for-expression"
- or even a "for-yield"
(you can get for-loops too, but that's a special case and we'll get back to them at the end)
And what are they for?
Just as with pattern Matching, falling into the “it’s the equivalent of Java’s ‘for’ ” trap will not serve you well. For me particularly, this caused immense pain which you can see written up on my Java-to-Scala blog.
Despite this, I persisted, because For-Comprehensions are very powerful, and are commonly used to:
- Iterate through things
- filter something
- produce a new collection
We can’t move on yet.
I need to stress this point – you need to stop thinking of Java’s “for” and everything that comes with it right now – having “looping” in your mind (which this will summon up) will send you down the wrong path.
Remember, to “Iterate” is not to “loop”
It’s far better to think of them in terms of Option[T]
- But again, make sure you don't think of this as "a list of something or nothing“ which you’ll encounter some resources telling you to do.
- Remember, Option[T] is more strongly typed than that
- It can contain None or Some[T]
- And there are methods provided to work on its contents
- And these methods can be applied without “opening the box”
- Think of it instead as a way of avoiding null (one of many)
(Or if you want to look further, check out Future[T] - out of scope for this presentation)
Here’s code again – let’s step through things:
We create some options first…
Now we add a Person case class and a for-comprehension to push the Options through and yield a person instance.
Note we’re pushing both Options through
Clearly the “for” is doing something here to unpack the Options, as we get a “None” out the bottom from our yield – the None in the maybeSurname must have caused problems…
Note also we’re still typesafe – no null pointers here.
So now what happens if we have no “Nones” and two “Some[String]”s?
We get a Some of a Person, constructed from the inputs to the for.
Nice eh? And nothing to do with collections or iterating at all.
So now we dive into the bowels of things right?
Well, in a manner of speaking. Actually, it‘ll pay us now to step back a bit farther.
We’ve got a toe-hold. A nice solid one. Its a good place to consider what is a for comprehension made up of.
Like I said previously, it turns out that this is the first case where something in Scala really is "made up" of things which it's worth us looking at;
its worth considering it here because it helps us understand how the construct works and what it does.
Lets start with the first building block: Map.
Point number 1: We’re *not* talking about the Map collection type – it’s the map function were thinking about here
(Out! Out! Begone Imperative thinking!)
In Scala, Map is another higher order function - A function that takes a function – we’ve seen them before remember back in sections 2 and 3?
Now unhelpfully, the Scala map function (which is a concept which unsurprisingly comes from Maths) is usually encountered in the context of a collection
hence the frequent confusion
But it needn't be
Remember Option[T]?
Lets look at it in code:
Note:
def map[B](f: (A) => B): Option[B]
.map - Returns a Some[T] containing the result of applying function f to this Option's value if this Option is nonempty. Otherwise return None
Lets make some options again, and then see what happens when we call Map on them
When we call map-toUppercase on the non-empty Option we can see we get a Some of (uppercase) [“MARK”]
When we call it on the empty Option we get a None
Nice and simple, and also kind of expected based on what we saw with our for-example a minute ago
Next up, flatMap.
Again, its not a form of collection
But you're beginning to realise that
Instead, its another higher order function, which is again usually encountered in the context of a collection hence the frequent confusion (again)
And again it needn't be
It's _similar_ to map
It applies the function to each list element and returns the _concatenation_ of all function results
def flatMap[B](f: (A) => Option[B]): Option[B]
Returns the result of applying function f to this Option's value if this Option is nonempty. Returns None if this Option is empty
Lets see some code again which is nice and clear.
To see flatmap in action we need something a little more elaborate as input.
We’re starting here with a List of strings.
Then, as a handy comparison, let’s first call map-toInt on this List
Clearly some values in the List will be amenable to this function, but not all. We can see this in the output – we end up with a list of Option[Int], with Some[Int]s where things went well, and None’s where they didn’t. That’s good and everything has worked for us, but its not ideal and will require some hairy code to get the “good” bits out to work with them.
Can we get the list with just the Ints in it nice and simply? Yes, Flatmap can help. When we call flatMap-toInt on the same original list, this same function is applied to each element, but at the end, the resulting multidimensional collection is “flattened” – resulting in the Some[int]’s being unpacked and the Nones being discarded. Note now we have a List of Int, not Option of Int.
Super-useful.
Finally withfilter. This one is nice and easy
WithFilter() is Like filter(), but avoids an unnecessary creation of an intermediate data structure
So, for our purposes, dead like filter, and it does what is says on the tin
Code again:
Here we’re setting up a bunch of Person objects. Note that Lara and Julie are female, and that Julie has two kids – Lara and Bob.
Then we add them each to a collection
Finally we filter the collection, applying the predicate !p.isMale to each, which strips out male Person elements.
We’re left with a 2-element list, containing Lara and Julie (we’ve omitted her kids in the wrapped array for clarity)
OK. We’re done.
Finally we’ve got enough mentally in place to get back to for-comprehensions.
Perhaps now it’ll be no major surprise to learn that there are three main parts in the syntax:
Generator
Filter (aka "guard")
Definitions
(What about yield? We’ll get there…)
Here’s a simple example showing all three:
… at the top is the generator … this feeds the rest of the comprehension: v (whatever it is) produces values n until it is exhausted
… The filter (aka guard) where we can examine n (or anything else for that matter) and filter out n-values we don’t like the look of …
And the Definition, where we can create comprehension-scoped variables to help keep our code clean
We won’t cover these in the desugar (they don’t – they are what they are already)
And now that we know about our elements, we can finally move to the desugaring.
Which is how we translate from map, flatmap and withFilter to generators and guards.
For our first pass lets take a single generator and a filter
We can see the comprehension at the top of the slide
Then at the bottom we can see the equivalent function, the one the compiler makes for us.
And look: It turns into a map call on the value which feeds the generator, using the yield value as the function parameter.
The result of this is then (perhaps unsurprisingly) passed to withfilter which contains the predicate from the filter expression in the for.
I’ll say it again
– the generator has become a map call with the yield-expression as it’s parameter
- the filter has become a with filter which works on the output from map.
These simple rules are used consistently across all flavours of for-comprehension. It sounds too good to be true, but it isn’t.
So we’ve covered two (ok, three) of our concepts – map and withfilter. There’s one more to go – where’s flatMap?
To start seeing flatMap in action, we need to up the number of generators – you can have as many as you like, just as you can with filters and definitions.
Lets take the filter out of this next example to keep things simple and help them fit on a screen (you can guess how it’s come into play anyway right?)
Here’s the code:
We now have our two generators – the one we had before, and now a second, simpler one.
When this evaluates, each combination of elements is fed in – for the first value x, we then generate each value y, before moving back to the next value x - and the results yielded.
In this case the result is a Vector(true, false, false, false, false, false, false, false, false, false)
And how does it desugar? We start with the expected map on the first generator input, taking the yield predicate as the function parameter.
Next however, we flatmap the result of this map call and flatmaps it onto the second generator input.
Why not map? Because we’d get a vector of vectors – Vector(Vector(true), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false)).
Flatmap flattens it all out for us. If you have more than one generator, the last one is always desugared into a flatmap, the rest into maps.
And the best bit, this rule also holds true across all instances that you can come up with that match this pattern.
That’s enough for now. Lets looks at the traditional gotchas and finally return to the mindset.
Here’s the code:
We now have our two generators – the one we had before, and now a second, simpler one.
When this evaluates, each combination of elements is fed in – for the first value x, we then generate each value y, before moving back to the next value x - and the results yielded.
In this case the result is a Vector(true, false, false, false, false, false, false, false, false, false)
And how does it desugar? We start with the expected map on the first generator input, taking the yield predicate as the function parameter.
Next however, we flatmap the result of this map call and flatmaps it onto the second generator input.
Why not map? Because we’d get a vector of vectors – Vector(Vector(true), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false), Vector(false)).
Flatmap flattens it all out for us. If you have more than one generator, the last one is always desugared into a flatmap, the rest into maps.
And the best bit, this rule also holds true across all instances that you can come up with that match this pattern.
That’s enough for now. Lets looks at the traditional gotchas and finally return to the mindset.
And Gotchas? There are a few minor ones:
Firstly, the comprehension is executed *sequentially*
It doesn't parallelize, unless you create your elements ahead of, outside the "for“ which to some is a bit non-intuitive.
Secondly the type that goes in must come out - you're just filtering, mapping and flatmapping remember
And a few more major ones:
there are two valid forms of the comprehension:
One with parens and semi-colons
the other with curly braces
Also, I lied - people do refer to the "for-loop“
When you only have a single generator, and no filters or definitions
These desugar to a combo of withFilter and foreach
And so finally lets tie things up with the mindset – what’s the benefit to us of looking at for-comprehensions in such depth?
Well, for-comprehensions illustrate the third type of creeps-up-on-you Scala-functional mind blend and that is:
When you find that, beneath the covers, something is working in a way completely different to that which you might expect it to
Then suddenly, this understanding of the de-sugaring helps you properly understand not only the construct in question, but also the contributing constituent parts
It’s basically an enforced, but hand-held, letting go.
When I personally “got” this, it put me in a place where I could look back on my many experiences spent getting to here, and a lot fell into place. In fact, it was when I got this that I realised I might have a talk – some kind of consistent narrative – that I could pull together for you here today.
So we’re almost done. I’m not going to claim that just by sitting and listening to this you’ll suddenly have the same dawning of realisation I’ve just talked about. I think you need to travel the path yourself, like thousands have before me. It’s hard, but it is worth it.
And before I close I’d like to impart some insights that are my own, and I didn’t just read them or cut and paste them from the internet:
General Rules:
1. Read closely – these maths guys cram a lot into a tiny amount of code / text
2. Don’t automatically trust what you know from Java
3. But don’t automatically discount it either
4. Unlearning is harder than you think. You’ll feel the side-effects of a lot of things you stopped being conscious of, as they’ll start getting in the way. When you understand what these are, then you can move past them / put them to work properly.
And if you want to retrace my footsteps, how might you get to here?
Firstly I’d advise against reading Scala in Action if you’re at the stage I was (and still am). Try these instead, in this order, though you can (and should) overlap:
* “Atomic Scala” (Eckel & Marsh)
* The Scala Koans
* “Scala for the Impatient” (Horstmann)
* Twitter’s Scala School
* “Introduction to Functional Programming” (Coursera)(Odersky)
* “Programming in Scala (2nd Ed.)” (Odersky, Venners, Spoon)
* The Scala Language Specification
And where next?
* Firstly I’d encourage you to blog it as you progress – trying to explain what you think you understood helps you really understand it – You might even want to guest-post on my blog ;-) http://scalaeyeforthejavaguy.blogspot.com
* And of course desugar more constructs for yourself – there’s lots more out there to consider
And the next-step constructs beyond what we covered here?
* Learn Implicits
* Learn Type Classes
* Learn Haskell! (“Learn you a Haskell…” is great for this)
* Re-read things you thought you understood
Wait, what about those monadic constructs you mentioned as the goal right at the start?
Oh, those? That’s map and flatmap. Without knowing it, you’re now very nicely set up to start getting your head round Monads too. Take a look and see…