Polyglot And Poly-paradigm Programming

2y ago
7 Views
2 Downloads
3.73 MB
101 Pages
Last View : 1y ago
Last Download : 3m ago
Upload by : Kairi Hasson
Transcription

Polyglot andPoly-paradigmProgrammingDean Wamplerdean@deanwampler.com@deanwampler1Monday, June 14, 2010

day, June 14, 2010

Guest Editor,IEEE SoftwareSpecial Issue onMulti-paradigm Programmingcomputer.org/software3Monday, June 14, 2010

4Monday, June 14, 2010

Times Change.Monday, June 14, 2010

Today’sapplications: Are networked, Have graphicaland nMonday, June 14, 20106

Today’sapplications: Persist data, Must be resilientand secure, Must scale,flickr.com/photos/jerryjohnMonday, June 14, 20107

Today’sapplications: and must doall that by Friday.flickr.com/photos/jerryjohnMonday, June 14, 20108

Polyglot orMultilingual:many languages9Monday, June 14, 2010

Poly-paradigm orMultiparadigm:many modularityparadigms10Monday, June 14, 2010

Thesis:modern problemsare poorly served by“Monocultures”11Monday, June 14, 2010monocultures “monoglot” and “mono-paradigm” programming.

Monoparadigm:Object-OrientedProgramming:right for y, June 14, 201012

MonolingualIs one languagebest for all domains?twitter.com/photos/watchsmart13Monday, June 14, 2010domains: e.g., the problem domain for the app (usually an object model), the security model, the network/web topology, therelational or other data model, .

Symptoms ofMonocultures Why is there so much XML in my Java? Why do I have similar code for persistence,transactions, security, etc. scattered all over mycode base?14Monday, June 14, 2010

Symptoms ofMonocultures How can I scale my application to internet scales? Why is my application so hard to extend? Why can’t I respond quickly when requirementschange?15Monday, June 14, 2010

switch (elementItem){case "header1:SearchBox" :{doPostBack('header1:goSearch','');break;}case "Text1":{window.event.returnValue false;window.event.cancel true;document.forms[0].elements[n 1].focus();break;} .Pervasive Symptom:hcumooT!edocthedailywtf.com16Monday, June 14, 2010

Let’s examine somecommon problemswith PPP solutions:17Monday, June 14, 2010

Changeis slowand painful.Problem #1flickr.com/photos/arrrikaMonday, June 14, 201018

Symptoms Features take too long toimplement. We can’t react fast enoughto change. Uses want to customize thesystem themselves.19Monday, June 14, 2010

SolutionApplicationUser ScriptsBuilt-in ScriptsKernel of Components(C Components) (Lisp scripts) Emacs20Monday, June 14, 2010

Components Scripts Applicationssee John Ousterhout, IEEE Computer, March ’9821Monday, June 14, 2010Pronunciation: OH-stir-howt

Kernel Components Statically-typed language: C, C , Java, C#, . Compiled for speed, efficiency.rd Access OS services, 3 -partylibraries. Lower developer productivity.22Monday, June 14, 2010

Scripts Dynamically-typed language: Ruby, Lisp, JavaScript, Lua, . Interpreted for agility. Performance less important. Glue together components. Raise developer productivity.23Monday, June 14, 2010In practice, the divide between components and scripts is not so distinct.

In practice,the boundaries betweencomponents and scriptsare not so distinct.24Monday, June 14, 2010

Other Examples: UNIX/Linux shells. Also find, make, grep, . Have their own DSLs.25Monday, June 14, 2010

C /Lua Examples: Adobe Lightroom 40-50% written in Lua. Game Engines26Monday, June 14, 2010Lightroom: Lua API used for 3rd-party plugins.Lots of games combine C and Lua, too.

Embedded Systems: Tektronix Oscilloscopes: C Smalltalk. NRAO Telescopes: C Python. Google Android: Linux libraries (C) Java.27Monday, June 14, 2010

Other Examples:Multilingual VM’s On the JVM: JRuby, Groovy, Jython,Scala. Ruby on Rails on JRuby.28Monday, June 14, 2010Another realization of C S A is to put several languages on the same VM, rather than using the OS as the component layer.

Other Examples:Multilingual VM’s Dynamic Language Runtime(DLR). Ruby, Python, . onthe .NET CLR.29Monday, June 14, 2010Another realization of C S A is to put several languages on the same VM, rather than using the OS as the component layer.

XML in Java view-state id "displayResults" view "/searchResults.jsp" render-actions bean-action bean "phonebook" method "search" method-arguments argument expression "searchCriteria"/ /method-arguments method-result name "results" scope "flash"/ /bean-action /render-actions transition on "select" to "browseDetails"/ transition on "newSearch" to "enterCriteria"/ /view-state /flow Why not replace XMLwith JavaScript , Groovyor JRuby?30Monday, June 14, 2010De facto “scripting language” in Java.Not an optimal choice:- All data.- No behavior (to speak of.).- Verbose.

BenefitsApplicationUser ScriptsBuilt-in ScriptsKernel of Components Optimize performance where it matters. Optimize productivity, extensibility, agility andend-user customization everywhere else.31Monday, June 14, 2010This is an underutilized architecture.

DisadvantagesApplicationUser ScriptsBuilt-in ScriptsKernel of Components More complexity with 2 languages. Interface between the layers. Splitting behavior between layers.32Monday, June 14, 2010The complexity includes idioms, tools, and developer expertise for more than 1 language.

ApplicationUser ScriptsBuilt-in ScriptsKernel of ComponentsAn underutilizedarchitecture!33Monday, June 14, 2010

Parting Thought.Why don’t Eclipse, IntelliJ, etc.have built-in scripting engines?34Monday, June 14, 2010

Parting Thought.erewCell phone makers areXdrowning in C .(One reason the IPhoneand Android are interesting.)35Monday, June 14, 2010

I don’tknow whatmy code isdoing.Problem #2flickr.com/photos/dominic99Monday, June 14, 2010

The intentof our codeis lostin the noise.37Monday, June 14, 2010

Symptoms New team members have along learning curve. The system breaks when wechange it. Translating requirements to codeis error prone.38Monday, June 14, 2010

Solution #1Writeless code!You’re welcome.39Monday, June 14, 2010

Less Code Means problems are smaller: Maintenance Duplication Testing Performance etc.40Monday, June 14, 2010

How to WriteLess Code Root out duplication. Use economical designs. Functional vs. Object-Oriented? Use economical languages.41Monday, June 14, 2010

Solution #2Separateimplementation detailsfrom business logic.42Monday, June 14, 2010

Domain SpecificLanguagesMake the code read like“structured” domain prose.43Monday, June 14, 2010

Example DSLinternal {case extensionwhen 100.200callee User.find by extension extensionunless callee.busy? then dial calleeelsevoicemail extensionwhen 111 then join 111when 888play weather report('Dallas, Texas')when 999play %w(a-connect-charge-of 22cents-per-minute will-apply)sleep 2.secondsplay 'just-kidding-not-upset'check voicemailend}Adhearsion Ruby DSL Asterisk Jabber/XMPP .44Monday, June 14, 2010PBX Private Branch Exchange, the telephony exchange that serves a business or other office, etc.

DSL Advantages Code looks like domain prose: Is easier to understand byeveryone, Is easier to align with therequirements, Is more succinct.45Monday, June 14, 2010

DSL DisadvantagesMany people arepoor API designers.DSLs are harder to design.46Monday, June 14, 2010

DSL DisadvantagesDSLs can be hard toimplement, test, and debug.47Monday, June 14, 2010

A DSL Tower of Babel?48Brueghel the ElderMonday, June 14, 2010Not too many of this examples yet, but one comes to mind: mocking (for testing) frameworks in Ruby, BDD tools in severallanguages.

Parting Thought.Perfection is achieved,not when there is nothing left to add,but when there is nothing left to remove.-- Antoine de Saint-Exupery49Monday, June 14, 2010He wrote “The Little Prince”, among other books. He was an aviator who disappeared over the Mediterranean in 1944, flying forFree French Forces.

Parting Thought #2.Everything should be made as simpleas possible, but not simpler.-- Albert Einstein50Monday, June 14, 2010

Corollary:Entia non sunt multiplicandapraeter necessitatem.-- Occam’s Razor51Monday, June 14, 2010a.k.a. “Law of Parsimony” or “Law of Succinctness”. Paraphrased translation.

Corollary:All other things being equal,the simplest solution is the best.-- Occam’s Razor52Monday, June 14, 2010a.k.a. “Law of Parsimony” or “Law of Succinctness”. Paraphrased translation.

We havecode duplicationeverywhere.Problem #3deanwamplerMonday, June 14, 2010

Symptoms Persistence logic is embeddedin every “domain” class. Error handling and logging isinconsistent.Cross-Cutting Concerns.54Monday, June 14, 2010

SolutionAspect-OrientedProgramming55Monday, June 14, 2010

Removing Duplication In order, use: Object or functional decomposition. DSLs. Aspects.56Monday, June 14, 2010Make sure your object and functional decomposition is right first, then use DSLs appropriately. Finally, use aspects.

An Example.57Monday, June 14, 2010

class BankAccountattr reader :balancedefcredit(amount)@balance amountenddefdebit(amount)@balance - amountend end58Monday, June 14, 2010Clean Code

But, real applications need:def BankAccountattr reader nddefdebit(amount).Securityendend59Monday, June 14, 2010

So credit becomes def credit(amount)raise “ ” if unauthorized()save balance @balancebeginbegin transaction()@balance amountpersist balance(@balance) 60Monday, June 14, 2010

rescue errorlog(error)@balance saved balanceensureend transaction()endend61Monday, June 14, 2010

We’re mixing multiple domains,with fine-grained intersections.“tangled” codeTransactionsPersistenceSecurity“Problem Domain”“scattered” logic62Monday, June 14, 2010In principle, I can reason about transactions, etc. in isolation, but in reality, the code for transactions is scattered over the wholesystem. Similarly, the once-clean domain model code is tangled with code from the other concerns.Objects don’t prevent this problem (in most cases).

Objects alone don’tprevent tangling.63Monday, June 14, 2010

Aspect-OrientedProgramming:restore modularity forcross-cutting concerns.64Monday, June 14, 2010

Aspects restore modularity byencapsulating the curityAspectSee “extra” slides65Monday, June 14, 2010TransactionsPersistenceSecurity

If you have used theSpring Framework,you haveused aspects.66Monday, June 14, 2010

Parting Thought.Metaprogramming can be usedfor some aspect-like functionality.DSLs can solve somecross-cutting concerns, by localizingbehaviors expressed by the DSL.67Monday, June 14, 2010

Our servicemust beavailable 24x7and highlyscalable.Problem #4flickr.com/photos/wolfro54Monday, June 14, 2010

Symptoms Only one of our developersreally knows how to writethread-safe code. The system freezes every fewweeks or so.69Monday, June 14, 2010

SolutionFunctionalProgramming70Monday, June 14, 2010(At least, it’s one solution.)

Functional ProgrammingModeled after mathematics.y sin(x)71Monday, June 14, 2010

Functional ProgrammingValues are immutable.Variables are assigned once.y sin(x)72Monday, June 14, 2010

Functional ProgrammingFunctions are side-effect free.Functions don’t alter state.The result depends solelyon the arguments.y sin(x)73Monday, June 14, 2010

Functional Programming:Concurrency Is EasierNo writes, so no synchronization.Hence, no locks, semaphores, mutexes.y sin(x)74Monday, June 14, 2010

Functional Programming:Reasoning is EasierWithout side effects,functions are easier to test, understand, .and reuse!y sin(x)75Monday, June 14, 2010

Which fits your raw(.)deposit(.)withdraw(.)Object Oriented76Monday, June 14, 2010Do operations vary significantly, depending on data type or .

Which fits your needs?listmapfilterfold/reduceFunctional77Monday, June 14, 2010 or do operations more or less work the same independent of the data type?

What ifyou’redoing cloudcomputing?E.g., is map-reduceobject-orientedor functional?78Monday, June 14, 2010flickr.com/photos/deanwamplerdeanwampler

FP Code:more declarativethan imperative.F(n) F(n-1) F(n-2)where: F(0) 0 and F(1) 10, 1, 1, 2, 3, 5, 8, 13, .79Monday, June 14, 2010The Fibonacci Sequence.I tell the system what I want (e.g., what are the relationships between data, the constraints, etc.) and let the system figure outhow to do it.

and so are DSLs.class Customer ActiveRecord::Basehas many :accountsvalidates uniqueness of :name,:on create,:message ‘Evil twin!’end80Monday, June 14, 2010By hiding the implementation details, we have much more leeway in implementing aspect behavior, etc.

A FewFunctional Languages81Monday, June 14, 2010

Erlang Ericsson Functional Language. For distributed, reliable, soft real-time,highly concurrent systems. Used in telecom switches. 9-9’s reliability for AXD301 switch.82Monday, June 14, 2010

Erlang No mutable variables and side effects. Uses the actor model of concurrency. All IPC is optimized message passing. Let it fail philosophy. Very lightweight and fast processes. Lighter than most OS threads.83Monday, June 14, 2010

Scala Hybrid: object and functional. Targets the JVM and .NET. “Endorsed” by James Gosling at JavaOne. Could be the most popularreplacement for Java.84Monday, June 14, 2010

Times Change.Monday, June 14, 2010

Clojure Functional, with principled support formutability. Targets the JVM and .NET. Best buzz? Too many good ideas to name here.86Monday, June 14, 2010

Functional Languages inIndustry Erlang CouchDB, Basho Riak, and Amazon’sSimple DB. GitHub Jabber/XMPP server ejabberd.87Monday, June 14, 2010

Functional Languages inIndustry OCaml Jane Street Capital Scala Twitter LinkedIn Clojure Flightcaster88Monday, June 14, 2010

Parting Thought.Which is better:A hybrid object-functional languagefor everything?An object language for some code anda functional language for other code?e.g., Scala vs. Java Erlang?89Monday, June 14, 2010Scala is more complex than “mono-paradigm” languages, so it’s harder to master. However, using multiple languages has it’sown challenges.

Recap:Polyglot and Poly-paradigmProgramming (PPP)90Monday, June 14, 2010

Disadvantages of PPP N tool chains, languages, libraries,“ecosystems”, idioms, . Impedance mismatch between tools. Different meta-models. Overhead of calls between languages.91Monday, June 14, 2010

Advantages of PPP Can use the best tool for a particular job. Can minimize the amount of coderequired. Can keep code closer to the domainusing DSLs. Encourages thinking about architecture.92Monday, June 14, 2010

Is This New? Functional Programming Comes of Age. Dr. Dobbs, 1994 Scripting: Higher Level Programming forstthe 21 Century. IEEE Computer, 1998 In Praise of Scripting: Real ProgrammingPragmatism. IEEE Computer, 2008Monday, June 14, 2010

Why go mainstream now? Rapidly increasing pace of development, Scripting (dynamic languages), DSLs. Pervasive concurrency (e.g., Multicore CPUs) Functional programming. Cross-cutting concerns Aspect-oriented programming.94Monday, June 14, 2010

Thank You! dean@deanwampler.com Watch for the IEEE Softwarespecial issue, Sept/Oct 2010. polyglotprogramming.com95Monday, June 14, 2010

Extra Slides96Monday, June 14, 2010

Aspect-Oriented Toolsshameless plug Ruby Aquarium Facets AspectR Java AspectJ Spring AOP JBoss AOP97Monday, June 14, 2010Options for Java and Ruby. Some other languages have AOP toolkits.

I would like to write Before returning the balance, read thecurrent value from the database.After setting the balance, write thecurrent value to the database.Before accessing the BankAccount,authenticate and authorize the user.98Monday, June 14, 2010

I would like to write Before returning the balance, read thecurrent value from the database.After setting the balance, write thecurrent value to the database.Before accessing the BankAccount,authenticate and authorize the user.99Monday, June 14, 2010

Aquariumuse aquarium lib.reopen classrequire ‘aquarium’class BankAccount “event” to trigger onafter :writing :balance \do context, account, *args persist balance accountend new behavior100Monday, June 14, 2010aquarium.rubyforge.org

Back to clean codedef credit(amount)@balance amountend101Monday, June 14, 2010

JRuby, Groovy, Jython, Scala. Ruby on Rails on JRuby. 28 Monday, June 14, 2010 Another realization of C S A is to put several languages on the same VM, rather than using the OS as the component layer.

Related Documents:

Polyglot at a deeper level. The latest revision of Polyglot can be fetched from the project SVN [9]. The Polyglot distribution contains several directories: /bin/ : contains Polyglot base compiler and script newext.sh that generates the skeleton for a new language extension /doc/ :

Polyglot allows one to learn word repre-sentations from massive amounts of unannotated text. We have used Polyglot to learn word embeddings for more than 100 di erent languages1. A detailed description of the Polyglot project is available in [1].At a high level, we measure the performance of training a Polyglot model in terms of the number of .

Reactive programming in Java Implementing inventory Summary 10. Finalizing Java Knowledge to a Professional Level Java deep technologies Java agent Polyglot programming Polyglot configuration Polyglot scripting Business DSL Problems with polyglot Annotation processing Programming in the en

Poly(vinylcarbazo1e) Poly(vinylbutyra1) Poly(p-vinylphenol) Polystyrene Ethyl cellulose Poly(capro1actone) GE DC 11 Poly(methy1 methacrylate) Poly(butadieneacry1onitrile) Poly(viny1 chloride) Poly(viny1 isobutyl ether) Poly- 1 -butene 27.7 19.5 14-5 9-6 25-0 18.4 10.4 10-3 3

WebRTC and the new Poly EVO signaling) that provide a feature-rich user experience. Poly Clariti App and Poly Clariti Roster deliver high-quality video, . Click-to-join support for Outlook plugin 10.0.0.9 3.6.7 CentOS 6.10 OpenJDK 1.8.0.265 PostgreSQL 10.14-1 April 2021 Conference participant counts ACLs in log archives

Functional programming paradigm History Features and concepts Examples: Lisp ML 3 UMBC Functional Programming The Functional Programming Paradigm is one of the major programming paradigms. FP is a type of declarative programming paradigm Also known as applicative programming and value-oriented

Programming paradigm A programming paradigm is a style, or w, ay of programming. Paradigm can also be termed as method to solve some problem or do some task. Programming paradigm is an approach to solve problem using some programming language or also we can say it is a meth

and support for polyglot workflows. The industrial data science landscape is increasingly polyglot, with end-to-end workflows for data preparation, model building, and inference often straddling PLs such as Python, R, Java, and Javascript. Thus, Trinity’s unified approach can help reduce implementation costs and maintenance