Stop coding Pascal ...emotional sketch about past, present and future of programming languages, Python, compilers, developers, Life, Universe and Everything

Saturday, April 6, 13

About me

Saturday, April 6, 13

• • • •

Alexey Kachayev



Erlang, Python, Scala, Clojure, Go, Haskell

• • •

@kachayev

CTO at KitApps Inc. Open source activist Functional programming advocate

kachayev <$> gmail github.com/kachayev/fn.py

Einstein problem solving principle

Saturday, April 6, 13

So, next 55 minutes we will talk about the core of the problems

Saturday, April 6, 13

What are we going to talk about?

Saturday, April 6, 13



difference between syntax and semantic



imperative code: when and WHY?



machine VS language: problems and solutions



where did Python features come from



what is the current problem



why should I care?

Simple task count of unique substring

Saturday, April 6, 13

Pascal

Saturday, April 6, 13

* just sample... it’s really hard to show Pascal version in slide

Saturday, April 6, 13

Python v.1

Saturday, April 6, 13

Python v.2

Saturday, April 6, 13

Haskell

Saturday, April 6, 13

What the difference is?



“pascal” VS “python.v1” syntax (mostly)



“python.v1” VS “python.v2” - semantic



“python.v2” VS “haskell” (mostly) syntax (*)

* iterators VS. lazy-evaluation is a different story Saturday, April 6, 13

Let’s dig deeper

Saturday, April 6, 13

Why is Haskell code so compact?

Saturday, April 6, 13

• • •

transformations compositions * unix way, BTW

Where did all these i, j, k come from?

Saturday, April 6, 13

Instructions VS.

Transformations

Saturday, April 6, 13

... and deeper

Saturday, April 6, 13

Turing machine VS.

λ-calculus

Saturday, April 6, 13

Turing machine

Saturday, April 6, 13

• •

infinite memory instructions (finite)

λ - calculus

Saturday, April 6, 13

• • • •

terms abstraction application β-reduction

The are many application operators in Haskell, ML

application abstraction

(λx.2 * x + 1) 3 β-reduction

Saturday, April 6, 13

Q: “How it’s possible that everything is a transformation?”

Saturday, April 6, 13

A: “Have you ever thought about how (4+5-2*9) works?”

Saturday, April 6, 13

Hardware & compiler VS.

Programming language

Saturday, April 6, 13

What the problem is? “reusability” && “composability” ... oh, off course modularity matters, but we created many ways to split our programs since goto

Saturday, April 6, 13

Imperative

Saturday, April 6, 13



hard to reuse/compose (context)

• • •

hard to test (context)

• • • •

parallelism is impossible

“interactive style” is hard it’s not the language that I want to talk

... but it’s widespread ... but it’s common ... but it’s hard to see the root of the problems (“Vietnam”)

Imperative advantages(?)

Saturday, April 6, 13



algorithms O(*) - the same



low level optimization? oh, not in Python



manual memory control? - oh, not in Python

Set theory

Logic combinators

Type theory

AST-base

λ-calculus as PL

Lisp (family)

Python

ABC

SETL

Pascal

λ-notation λ-calculus ML (family) Haskell С

Algol 60/8

Fortran Speedcoding Assembly Turing machine Saturday, April 6, 13

OCaml

When somebody tells you that each language is sugar over Turing machine... do not believe

Saturday, April 6, 13

Python * ast/abt ** sequence-based semantic Saturday, April 6, 13

• •

mostly imperative, but...

• • • •

lambdas (*)

• •

generators (**)

higher-ordered functions (*)

no for(i=0;i<10;i++) (**) iterators (**) map/filter/zip/itertools (**)

futures (concurrency, tulip)

Move on to more practical questions * starting from easiest: looking for high-level patterns

Saturday, April 6, 13

http://wrongsideofmemphis.files.wordpress.com/2013/03/screen-shot-2013-03-23-at-12-32-17.png

Saturday, April 6, 13

Do you see the patterns?

Saturday, April 6, 13

Do you see the patterns?

Saturday, April 6, 13

Do you see the patterns?

Saturday, April 6, 13

Do you see the patterns?

Saturday, April 6, 13

Saturday, April 6, 13

Saturday, April 6, 13

Saturday, April 6, 13

Saturday, April 6, 13

Do you see the patterns?

* we already talked that loops do not compose Saturday, April 6, 13

Do you see the patterns?

Saturday, April 6, 13

Saturday, April 6, 13

Not only syntax...

Saturday, April 6, 13



transformations instead of instructions



reduction declarations without dealing with application



reuse pure function in some context (functor)



high(er) level of composability

When syntax sucks...

Saturday, April 6, 13

Iterators is not only about lists ... this is the semantic way to think about possible solutions

Saturday, April 6, 13

Saturday, April 6, 13

Only last function matters ... other functions are common and you can find them in Python documentation or implemented in Fn.py library

Saturday, April 6, 13

More examples Lazy evaluation and declarative approach: http://kachayev.github.com/talks/

Saturday, April 6, 13

What stuff do you know about?

Saturday, April 6, 13

• • • • • • • • • •

iterators generators lazy-evaluation undelimited continuations delimited continuations coroutines macros monads “staging” “deref scope”

What stuff do you use in code?

Saturday, April 6, 13

• • • • • • • • • •

iterators generators lazy-evaluation undelimited continuations delimited continuations coroutines macros monads “staging” “deref scope”

What stuff do you want to use?

Saturday, April 6, 13

• • • • • • • • • •

iterators generators lazy-evaluation undelimited continuations delimited continuations coroutines macros monads “staging” “deref scope”

I saw many coroutines during conference talks

Saturday, April 6, 13

I never saw coroutines in real-life projects

Saturday, April 6, 13

Can you describe* coroutine advantages? * using one word

Saturday, April 6, 13

Can you describe coroutine disadvantages?

Saturday, April 6, 13

What the problem is?

Saturday, April 6, 13



easy to start with simplest stuff (it’s cool, but don’t stop!)

• •

habits, traditions (???)



syntax doesn’t support non-imperative semantic (“for” is only one good example of support, “yield from” is also cool) (**)



internal contradictions (***)

mutable variables and assignments dictate (*)

Can you see semantic under the syntax?

Saturday, April 6, 13

https://gist.github.com/e000/1023982

Saturday, April 6, 13

Are you getting on a bit?

Saturday, April 6, 13

Can you see ABT under your AST?

Saturday, April 6, 13

I don’t want you to write code this way I just want you to understand how it works and why it’s possible

Saturday, April 6, 13

BTW, it’s common pattern in JS code...

Saturday, April 6, 13

yield from is not only the new syntax! Saturday, April 6, 13

Saturday, April 6, 13

Saturday, April 6, 13

It’s all about composition. Saturday, April 6, 13

You can (*) write pointfree (**) code * you just don’t have readable syntax to do this ** applyTwice is good example to show

Saturday, April 6, 13

Isn’t this wonderful?

Saturday, April 6, 13

Contra

Saturday, April 6, 13

• •

no composition syntax!!!

• •

no recursion!!!



oh, I know! recursion = fold + unfold :)



no fold!!! we have list comprehensions



but... LC = map&filter... okay...

okay... def new function (not readable enough)

okay... the list is...? iterators is...?

Code vs. Ideas So now reduce(). This is actually the one I've always hated most, ... almost every time I see a reduce() call with a non-trivial function argument, I need to grab pen and paper to diagram... it's better to write out the accumulation loop explicitly. (c) Guido Van Rossum

Saturday, April 6, 13

fold / unfold ... dig deeper

Saturday, April 6, 13

Everybody knows this examples... Saturday, April 6, 13

Dig deeper. Saturday, April 6, 13

Saturday, April 6, 13

I want you to think about semantic

Saturday, April 6, 13

In 5 years Python will solve other problems

Saturday, April 6, 13

In 5 years Python should (*) solve other problems * technologies are changing very fast Saturday, April 6, 13

Is Python ready to be a cutting-edge language?

Saturday, April 6, 13

Are you ready?

Saturday, April 6, 13

Questions? * other talks: https://kachayev.github.com/talks ** fn.py: https://github.com/kachayev/fn.py Saturday, April 6, 13

emotional sketch about past, present and future of ... - GitHub

I saw many coroutines during conference talks. Saturday, April 6, 13 ... hated most, ... almost every time I see a reduce() call with a non-trivial function argument, ...

2MB Sizes 0 Downloads 86 Views

Recommend Documents

The past, present and future of childhood malaria ...
Centre for Geographic. Medicine, Kenya Medical. Research Institute, ..... in Africa: sexual contact patterns and the predicted demographic impact of AIDS. Nature.

The Past, Present, and Future of Meridian System ... - Springer Link
and different forms of acupuncture point stimulation such as electro acupuncture, .... negative membrane potential generated by the mitochondria at a high level of energy ...... (ed),Fundamentals of complementary and alternative medicine.

The Past, Present, and Future of Software Architecture ...
guest editors' introduction. Philippe Kruchten, University of British Columbia ... Judith Stafford, Tufts University .... tions offer architect training courses, and an ..... heads the architecture research team for software-intensive healthcare syst

The past, present and future of childhood malaria ...
established in 1998 to develop a database of all ... database searches (Medline, Embase and Popline) and .... in Africa for which temporal data were available.

Physical therapy: past, present and future- a paradigm ...
... of Physiotherapy,. Kasturba Medical College (Manipal University), Mangalore, India. .... programs integrate theory, evidence and practice along a continuum of learning. This begins ..... 1984;64:347-350. 7. Wikipedia Online Encyclopedia.