symmetry, scala & software -- refresh dublin october 2013
DESCRIPTION
Talk given as part of the Refreshing Series, about how symmetry manifests itself in software, using Scala as an example where internal symmetry leads to much greater expressiveness.TRANSCRIPT
Symmetry, Scala & Software
Refresh Dublin 15 October 2013
Eric Bowman @ebowman
[email protected] http://tech.gilt.com
“harmonious and beautiful proportion
and balance”
http://en.wikipedia.org/wiki/Symmetry
http://en.wikipedia.org/wiki/Symmetry
“patterned self-similarity”
Symmetry is changing without changing.
Symmetry in Scala
•Object-Oriented/Functional Hybrid
•Statically Typed
Scala
public class HelloWorld { public static void main(String[] args) { System.out.println("hello, world"); } }
public class HelloWorld { public static void main(String[] args) { System.out.println("hello, world"); } }
object HelloWorld extends App { println("hello, world") } !
println("hello, world")
public class HelloWorld { public static void main(String[] args) { System.out.println("hello, world"); } }
object HelloWorld extends App { println("hello, world") } !
for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { System.out.println(i*j); } } !!
for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { System.out.println(i*j); } } !!
for { i <- 1 to 10 j <- 1 to 10 } println(i * j) !
Future<Integer> f = callService1(); Future<Integer> f2 = callService2(f.get()); System.out.println(f2.get());
Future<Integer> f = callService1(); Future<Integer> f2 = callService2(f.get()); System.out.println(f2.get());
val f = for { x <- callService1() y <- callService2(x) } yield y println(Await.result(f, Duration.Inf)) !
String capitalize(String name) { if (name == null) return null; else return Character.toUpperCase( name.charAt(0)) + name.substring(1); }
String capitalize(String name) { if (name == null) return null; else return Character.toUpperCase( name.charAt(0)) + name.substring(1); }
def capitalize(n: Option[String]): Option[String] = { for (name <- n) yield { name(0).toUpper + name.substring(1) } } !!
String capitalize(String name) { if (name == null) return null; else return Character.toUpperCase( name.charAt(0)) + name.substring(1); }
Future<Integer> f = callService1(); Future<Integer> f2 = callService2(f.get()); System.out.println(f2.get());
for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { System.out.println(i*j); } } !!
for { i <- 1 to 10 j <- 1 to 10 } println(i * j) !
val f = for { x <- callService1() y <- callService2(x) } yield y println(Await.result(f, Duration.Inf)) !!
def capitalize(name: Option[String]): Option[String] = for (n <- name) yield { n(0).toUpper + n.substring(1) } !!
Java
Scala
Refactoring
“By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you'll find that it is easier to extend and maintain code.”
http://en.wikipedia.org/wiki/Code_refactoring
•Abstraction
•Composition/Decomposition
•Name & Location
1. Finite, unchanging list of possible refactorings.
2. Every refactoring is reversible.
3. Every refactoring is deterministic.
4. Refactorings can be combined in any order.
Group Theory
“‘Numbers measure size; groups measure symmetry.”
Groups and Symmetry, Armstrong, Spring-Verlag, 1988, p.1
http://upload.wikimedia.org/wikipedia/commons/5/53/Evariste_galois.jpg
“The most substantial piece of writing in the whole literature of mankind”
http://opinionator.blogs.nytimes.com/2010/05/02/group-think/
http://opinionator.blogs.nytimes.com/2010/05/02/group-think/
“the symmetry group of an object is the group of all isometries under which the
object is invariant with composition as the operation”
http://en.wikipedia.org/wiki/Symmetry_group
“the symmetry group of a program ... is the group of all refactorings under which the
program behaves identically after applying refactorings in any order”
String capitalize(String name) { if (name == null) return null; else return Character.toUpperCase( name.charAt(0)) + name.substring(1); }
Future<Integer> f = callService1(); Future<Integer> f2 = callService2(f.get()); System.out.println(f2.get());
for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { System.out.println(i*j); } } !!
for { i <- 1 to 10 j <- 1 to 10 } println(i * j) !
val f = for { x <- callService1() y <- callService2(x) } yield y println(Await.result(f, Duration.Inf)) !!
def capitalize(name: Option[String]): Option[String] = for (n <- name) yield { n(0).toUpper + n.substring(1) } !!
Java
Scala
Breaking Symmetry
a[i].x += a[i - 1].x; a[i].y += a[i - 1].y;
http://www.metalev.org/2011/04/source-code-symmetry-and-transcendent.html
http://www.metalev.org/2011/04/source-code-symmetry-and-transcendent.html
a(i) += a(i-1)
a[i].x += a[i - 1].x; a[i].y += a[i - 1].y;
http://pages.cs.wisc.edu/~dyer/vsam/images/mona.gif
http://www.leonardodavinci.net/images/gallery/monalisa_detail1.jpg
http://www.saylor.org/site/wp-content/uploads/2012/04/6-mona-lisa.gif
http://upload.wikimedia.org/wikipedia/commons/thumb/d/db/MaryRose-carpentry_tools1.jpg/250px-MaryRose-carpentry_tools1.jpghttp://test.classconnection.s3.amazonaws.com/324/flashcards/95324/png/altarpiece.png
http://upload.wikimedia.org/wikipedia/commons/thumb/d/db/MaryRose-carpentry_tools1.jpg/250px-MaryRose-carpentry_tools1.jpghttp://test.classconnection.s3.amazonaws.com/324/flashcards/95324/png/altarpiece.png
http://upload.wikimedia.org/wikipedia/commons/6/63/Michelangelos_David.jpghttp://amolife.com/image/images/stories/Art&Abstract/most_popular_sculptures%20(7).jpg
http://www.biographyonline.net/artists/images/Much-The_Scream.jpg
http://www.pics24h.com/img/artwork/5-most-famous-paintings/5-most-famous-paintings03.jpg
FinFin
http://tech.gilt.com@gilttech
join us.