learning and modern programming languages

41
Are Modern Programming Languages Easier to Learn? Ray Toal, Loyola Marymount University @rtoal

Upload: ray-toal

Post on 20-May-2015

383 views

Category:

Technology


3 download

DESCRIPTION

A brief look at learnability of a few modern programming languages, drawing a lot from Bret Victor's Learnable Programming.

TRANSCRIPT

Page 1: Learning and Modern Programming Languages

Are Modern Programming Languages Easier to Learn?Ray Toal, Loyola Marymount University@rtoal

Page 2: Learning and Modern Programming Languages

What will this talk be about?

● "Anyone Can Program" (really?)

● What does it mean to learn or understand programming?

● How are modern languages helping (or not)?

Page 3: Learning and Modern Programming Languages

I was asked to first talk about myself

Page 4: Learning and Modern Programming Languages

… and about LMU CS

Page 5: Learning and Modern Programming Languages

But enough about me

Page 6: Learning and Modern Programming Languages

Really, Michael?

A noble gesture to garner the NYC tech community vote, for sure, but if the mayor of New York City actually needs to sling JavaScript code to do his job, something is deeply, horribly, terribly wrong with politics in the state of New York. --- Jeff Atwood

Page 7: Learning and Modern Programming Languages

Who's going to teach everyone?

Page 8: Learning and Modern Programming Languages

At least it is not as hard as this

Page 9: Learning and Modern Programming Languages

Because of this visionary

"But Grace, then anyone will be able to write programs!"

Page 10: Learning and Modern Programming Languages

But alas, not everyone can

All images from theDailyWTF.com

Page 11: Learning and Modern Programming Languages

Seriously, it can't be this hard?

Page 12: Learning and Modern Programming Languages

And it's just not about "mistakes"

What is WRONG with you people?

Page 13: Learning and Modern Programming Languages

We need to ask

How do we get people to understand programming?

Page 14: Learning and Modern Programming Languages

This guy knows

Page 15: Learning and Modern Programming Languages

He wrote a really great essay

Page 16: Learning and Modern Programming Languages

With this answer

"We change programming. We turn it into something that's understandable by people."

Page 17: Learning and Modern Programming Languages

Why did he write this essay?

In Inventing on Principle (2011), Bret Victor demonstrated a remarkable live coding environment.

Inspired, Khan Academy implemented it in their programming section.

But KA missed the point: he was talking about creating, not learning.

Page 18: Learning and Modern Programming Languages

What does he say?

A system should ● support and encourage powerful ways of

thinking● allow people to see and understand the

execution of their code.

Page 19: Learning and Modern Programming Languages

What's wrong with KA's approach?

"A live-coding Processing environment addresses neither of these goals. JavaScript and Processing are poorly-designed languages that support weak ways of thinking, and ignore decades of learning about learning. And live coding, as a standalone feature, is worthless."

Page 20: Learning and Modern Programming Languages

Bret Victor's Nine Principles:The learner should be able to...

E1. See labeled code (not consult manuals)E2. Follow the flowE3. See the stateE4. Start somewhere, then sculptE5. Start somewhere, then generalizeL1. Work with sensible metaphorsL2. Decompose thoughtsL3. Glue thoughts togetherL4. Know what the code means just by reading

Page 21: Learning and Modern Programming Languages

Languages and Learning

What can the language do for the learner?

Page 22: Learning and Modern Programming Languages

It's been done right before!

Page 23: Learning and Modern Programming Languages

What did they do right?

● Concepts are directly related to the programmer's world (metaphor)

● Elements decompose into things people can think about independently

● Program elements can be composed from other programs and molded to new uses

● State is minimized, or at least explicit● Syntax (It matters!)● Names (they matter!)

Page 24: Learning and Modern Programming Languages

Metaphor

GOOD● Turtle

● Objects and messages

● Stack of cards

● Movable players

POOR

● Shuffling bits

● Memory cell

LACK OF

● rect(0,0,10,10)

Page 25: Learning and Modern Programming Languages

Decomposition

NICE THINGS

modulesobjectsfunctions

BARRIERS

Top level event handlers

Without objects how do you make animations, multiple copies, vary behavior?

Page 26: Learning and Modern Programming Languages

Recomposition

BAD STUFF:● mutable state● invisible state● global variables● lack of encapsulation● "leakiness"

Page 27: Learning and Modern Programming Languages

Syntax

draw_circle(center=(2,5), radius=10)drawCircleCenteredAt: (2,5) withRadius: 10[3, 5, 9]{name: "Rex", breed: "G-SHEP", age: 5}

drawCircle(2,5,10)… however you make arrays in C or Java… however you make maps in C or Java

Page 28: Learning and Modern Programming Languages

Names

vectorFromStartAndEndPoint(start, end) // you can tell this is constructing and returning // a new vectorvectorFrom:To:

fill(...) // to set a fill color // why not at least set_fill_color?rectangle(....) // should be draw_rectangleconcat(a, b) // ambiguous if b is an array, no?

Page 29: Learning and Modern Programming Languages

So, the BIG things to look for are

Primary metaphorsIdentifiable objectsIndependent modulesStreamlined syntax (no clutter)No ambiguity (almost)Language support for modelessnessParts of speech used properly in keywords and librariesParameter names in calls

Nice environments (IDEs, Playgrounds)

Page 30: Learning and Modern Programming Languages

How about some new languages?

Page 31: Learning and Modern Programming Languages

They're all adopting nice features

● Loop through structures without "for i"● "for k,v in map" and other destructurings● Ways to avoid loops (higher order functions)● String interpolation● Multiline strings● x,y = y,x● a[3..5]● Patterns● Optional or inferential typing, for the

statically typed languages

Page 32: Learning and Modern Programming Languages

Explain some of those, please

for dog in kennel: dog.bark()

sum(n*n for n in numbers if n % 2 == 0)

sum(map(square, filter(odd, numbers)))

numbers | filter odd | map square | sum

Page 33: Learning and Modern Programming Languages

CoffeeScript

number = -42 if opposite

square = (x) -> x * x

list = [1, 2, 3, 4, 5]

math = root: Math.sqrt square: square cube: (x) -> x * square x

race = (winner, runners...) -> print winner, runners

alert "I knew it!" if elvis?

cubes = (math.cube num for num in list)

These examples are from coffeescript.org

Page 34: Learning and Modern Programming Languages

Clojure

"A general-purpose language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming."

Lots of statelessness, powerful combining forms

(defn scramble [s] (if (empty? s) "" (-> s seq shuffle join)))

See Rich Hickey's Simple Made Easy

Page 35: Learning and Modern Programming Languages

Go

"Did the C++ committee really believe that was wrong with C++ was that it didn't have enough features? Surely … it would be a greater achievement to simplify the language rather than to add to it." -- Rob Pike

In one of his talks, Pike identifies 35 "significant simplifications in Go over Cand C++".

Page 36: Learning and Modern Programming Languages

Rust

Rust is a systems programming language that runs blazingly fast, prevents almost all crashes*, and eliminates data races.

So…. what are the chances it is easy to learn?

"Rust's pointers are one of its more unique and compelling features. Pointers are also one of the more confusing topics for newcomers to Rust. They can also be confusing for people coming from other languages that support pointers"

But it's pretty clean, with pattern matching closures type inference

Page 37: Learning and Modern Programming Languages

Julia

The Julia programming language fills this role: it is a flexible dynamic language, appropriate for scientific and numerical computing, with performance comparable to traditional statically-typed languages.x = [1,2,3]

y = [1 2 3]A = [1 2 3 4; 5 6 7 8; 9 10 11 12]A[2,1] = 0u, v = (15.03, 1.2e-27)f(x) = 3xx -> 3xx[2:12]x[2:end]A[5,1:3]A[5,:]

for animal in ["dog", "cat", "mouse"] println("$animal is a mammal")end

map(x -> x^2 + 2x - 1, [1,3,-1])

[add_10(i) for i in [1, 2, 3]]

... and keyword args too

Page 38: Learning and Modern Programming Languages

Swift

I think Apple did a good job here:● Named Parameters

o counter.incrementBy(5, numberOfTimes: 3)● Closures● Tuples and multiple return values● Fast and concise iteration over a range or collection● map and filter● Eliminates much unsafe code: Variables are always

initialized before use, arrays and integers are checked for overflow, and memory is managed automatically.

● Option chaining! (e.g., p.car?.color)● Great interactive playground (within XCode)● Uses the readable Cocoa API

Page 39: Learning and Modern Programming Languages

So…?

● All have REPLs or Playgrounds and great online examples.

● All adopt nice features to make programming a little more pleasant

● But all are industrial strength - do we expect the learner to quickly master all 7 types of Rust pointers?

● And none really have the turtle metaphor!

Page 40: Learning and Modern Programming Languages

Takeaways

● We have decades of research on teaching and learning that is often ignored

● Learning and understanding programming requires more than just live coding

● Language should expose metaphor, allow decomposition and recomposition, and make meaning transparent

● We saw some modern languages and saw they did a few things right

Page 41: Learning and Modern Programming Languages

Okay that's it

Questions?Discussion.Thanks!