learning and modern programming languages

Post on 20-May-2015

383 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

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

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)?

I was asked to first talk about myself

… and about LMU CS

But enough about me

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

Who's going to teach everyone?

At least it is not as hard as this

Because of this visionary

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

But alas, not everyone can

All images from theDailyWTF.com

Seriously, it can't be this hard?

And it's just not about "mistakes"

What is WRONG with you people?

We need to ask

How do we get people to understand programming?

This guy knows

He wrote a really great essay

With this answer

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

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.

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.

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."

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

Languages and Learning

What can the language do for the learner?

It's been done right before!

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!)

Metaphor

GOOD● Turtle

● Objects and messages

● Stack of cards

● Movable players

POOR

● Shuffling bits

● Memory cell

LACK OF

● rect(0,0,10,10)

Decomposition

NICE THINGS

modulesobjectsfunctions

BARRIERS

Top level event handlers

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

Recomposition

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

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

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?

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)

How about some new 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

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

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

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

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++".

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

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

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

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!

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

Okay that's it

Questions?Discussion.Thanks!

top related