Scala Days 2013Gilt Groupeebowman@gilt.comhttp://www.flickr.com/photos/justusthane/1252907196/
Gilt provides insider access to today’s top designer labels, at up to 60% off retail.Through our daily flash sales, which be...
http://search.savills.com/property-detail/gbedrseds090073http://en.wikipedia.org/wiki/File:John_Paul_Jones_by_Charles_Wils...
“Symmetry,aswideorasnarrowasyoumaydefineitsmeaning,isoneideabywhichmanthroughtheageshastriedtocomprehendandcreateorder,bea...
Symmetry:NotHowItLooks
Symmetryischangingwithoutchanging.
HowisScalaSymmetric?
EverythingisanObjectJava Scalavoid dump(int x) {System.out.println(Integer.toString(x));}def dump(x: Int): Unit = {println...
UniformAccessPrincipleJava Scalapublic class Datum {public final int x;public Datum(int x) {this.x = x;}}class Datum(val x...
Immutable|MutableList<String> foo() {ArrayList<String> items = computeItems();return items;}
Immutable|MutableList<String> foo() {ArrayList<String> items = computeItems();if (unlikelyThing()) {return items.subList(0...
PatternMatchingx match {case even if (x % 2) == 0 => even/2case odd => odd + 1}
PatternMatchingx match {case even if (x % 2) == 0 => even/2case odd => odd + 1}catch {case io: IOException => ...case e: E...
PatternMatchingx match {case even if (x % 2) == 0 => even/2case odd => odd + 1}catch {case io: IOException => ...case e: E...
Monadsfor {x <- monad1y <- monad2} yield x op y
Monadsfor {x <- monad1y <- monad2} yield x op yTraversableOptionFutureIOReaderWriterErrorContinuation
Asymmetry
PointlessSymmetrytry {Class c = Class.forName("MyClass");Object instance = c.newInstance();c.getMethod("myMethod").invoke(...
http://www.metalev.org/2011/04/source-code-symmetry-and-transcendent.htmla[i].x += a[i - 1].x;a[i].y += a[i - 1].y;Ill-Con...
http://www.metalev.org/2011/04/source-code-symmetry-and-transcendent.htmla[i].x += a[i - 1].x;a[i].y += a[i - 1].y;a(i) +=...
private def immediateAstNodes(n: Any): List[AstNode] = n match {case a: AstNode List(a)case t: Token Nilcase Some(x) immed...
Symmetry&Aesthetics
Symmetry&Aestheticshttp://pages.cs.wisc.edu/~dyer/vsam/images/mona.gif
Symmetry&Aestheticshttp://pages.cs.wisc.edu/~dyer/vsam/images/mona.gifhttp://www.leonardodavinci.net/images/gallery/monali...
Symmetry&Aestheticshttp://pages.cs.wisc.edu/~dyer/vsam/images/mona.gifhttp://www.leonardodavinci.net/images/gallery/monali...
BalanceRestBindingOrderLawRigidityConstraintMotionLooseningArbitrarinessAccidentLife & PlayFreedomhttp://www.acadeuro.org/...
BalanceRestBindingOrderLawRigidityConstraintMotionLooseningArbitrarinessAccidentLife & PlayFreedomhttp://www.acadeuro.org/...
http://upload.wikimedia.org/wikipedia/commons/thumb/d/db/MaryRose-carpentry_tools1.jpg/250px-MaryRose-carpentry_tools1.jpg...
http://upload.wikimedia.org/wikipedia/commons/6/63/Michelangelos_David.jpghttp://amolife.com/image/images/stories/Art&Abst...
http://upload.wikimedia.org/wikipedia/commons/6/63/Michelangelos_David.jpghttp://amolife.com/image/images/stories/Art&Abst...
http://www.iie.org/~/media/Images/Corporate/Static-Header/D-F/SH-EmmyNoether.ashx?mh=235&mw=300
http://memegenerator.net/instance/38640565
FinFinhttp://tech.gilt.com@gilttech@ebowmanebowman@gilt.com
Upcoming SlideShare
Loading in …5
×

Scala & symmetry

3,692 views

Published on

Slides for the lunchtime talk on Scala & Symmetry on 11 June 2013 at ScalaDays 2013.

Published in: Technology, Art & Photos
  • Be the first to comment

Scala & symmetry

  1. 1. Scala Days 2013Gilt Groupeebowman@gilt.comhttp://www.flickr.com/photos/justusthane/1252907196/
  2. 2. Gilt provides insider access to today’s top designer labels, at up to 60% off retail.Through our daily flash sales, which begin at noon EST, we offer everything fromhigh-end designer clothing and home furnishings to fine dining experiences. Ourproducts are grouped into five stores: Women, Men, Baby & Kids, Home and City.Working from New York City, Dublin, or home/remotely, Gilt Tech’s 120 engineersdevelop all of our technology in-house. Since Gilt’s founding days, we havepursued a structure that enables us to address unique needs other e-commerceplatforms simply cannot support. These needs include the ability to handleintense traffic spikes, offer prompt customer service, manage operations(inventory, payments and shipping), and execute many other tasks.As a rapidly growing company with an international customer base, Gilt’s prioritiesfocus on scalability and personalization. Gilt.com was originally built on Ruby onRails, but our rapid growth quickly led to scalability issues — prompting us tomigrate many parts of our website to the Java Virtual Machine. In 2011 we beganmigrating our operations to Scala, which is currently our core stack.
  3. 3. http://search.savills.com/property-detail/gbedrseds090073http://en.wikipedia.org/wiki/File:John_Paul_Jones_by_Charles_Wilson_Peale,_c1781.jpghttp://books.google.ie/books?id=diROAAAAYAAJ&pg=PA400&img=1&zoom=3&hl=en&sig=ACfU3U35lRj3v5Hwfzqe6ANIFr5f4L5RdA&ci=365%2C82%2C311%2C259&edge=0
  4. 4. “Symmetry,aswideorasnarrowasyoumaydefineitsmeaning,isoneideabywhichmanthroughtheageshastriedtocomprehendandcreateorder,beauty,andperfection.”--HermannWeyl
  5. 5. Symmetry:NotHowItLooks
  6. 6. Symmetryischangingwithoutchanging.
  7. 7. HowisScalaSymmetric?
  8. 8. EverythingisanObjectJava Scalavoid dump(int x) {System.out.println(Integer.toString(x));}def dump(x: Int): Unit = {println(x.toString)}void dump(Complex x) {System.out.println(x.toString());}def dump(x: Complex): Unit = {println(x.toString)}:(def dump[T](x: T): Unit = {println(x.toString)}
  9. 9. UniformAccessPrincipleJava Scalapublic class Datum {public final int x;public Datum(int x) {this.x = x;}}class Datum(val x: Int)public class Datum {private final int y;public int x() {return f(g(y));}public Datum(int y) {this.y = y;}}class Datum(y: Int) {def x = f(g(y))}“All services offered by a module should be available through auniform notation, which does not betray whether they are implementedthrough storage or through computation” - Bertrand Meyerhttp://en.wikipedia.org/wiki/Uniform_access_principle
  10. 10. Immutable|MutableList<String> foo() {ArrayList<String> items = computeItems();return items;}
  11. 11. Immutable|MutableList<String> foo() {ArrayList<String> items = computeItems();if (unlikelyThing()) {return items.subList(0, items.size() / 2);} else {return items;}}List<String> foo() {ArrayList<String> items = computeItems();return items;}
  12. 12. PatternMatchingx match {case even if (x % 2) == 0 => even/2case odd => odd + 1}
  13. 13. PatternMatchingx match {case even if (x % 2) == 0 => even/2case odd => odd + 1}catch {case io: IOException => ...case e: Exception => ...}
  14. 14. PatternMatchingx match {case even if (x % 2) == 0 => even/2case odd => odd + 1}catch {case io: IOException => ...case e: Exception => ...}val split: String => String = {case null => Nonecase str => Some(str)}
  15. 15. Monadsfor {x <- monad1y <- monad2} yield x op y
  16. 16. Monadsfor {x <- monad1y <- monad2} yield x op yTraversableOptionFutureIOReaderWriterErrorContinuation
  17. 17. Asymmetry
  18. 18. PointlessSymmetrytry {Class c = Class.forName("MyClass");Object instance = c.newInstance();c.getMethod("myMethod").invoke(instance);} catch (NullPointerException e) {} catch (IllegalAccessException e) {} catch (InvocationTargetException e) {} catch (ClassNotFoundException e) {} catch (NoSuchMethodException e) {} catch (InstantiationException e) {}
  19. 19. http://www.metalev.org/2011/04/source-code-symmetry-and-transcendent.htmla[i].x += a[i - 1].x;a[i].y += a[i - 1].y;Ill-ConceivedSymmetry
  20. 20. http://www.metalev.org/2011/04/source-code-symmetry-and-transcendent.htmla[i].x += a[i - 1].x;a[i].y += a[i - 1].y;a(i) += a(i - 1)Ill-ConceivedSymmetry
  21. 21. private def immediateAstNodes(n: Any): List[AstNode] = n match {case a: AstNode List(a)case t: Token Nilcase Some(x) immediateAstNodes(x)case xs @ (_ :: _) xs flatMap { immediateAstNodes(_) }case Left(x) immediateAstNodes(x)case Right(x) immediateAstNodes(x)case (l, r) immediateAstNodes(l) ++ immediateAstNodes(r)case (x, y, z) immediateAstNodes(x) ++ immediateAstNodes(y) ++ immediateAstNodes(z)case true | false | Nil | None Nil}http://stackoverflow.com/questions/8618082/visitor-pattern-in-scalaBeautifulAsymmetry
  22. 22. Symmetry&Aesthetics
  23. 23. Symmetry&Aestheticshttp://pages.cs.wisc.edu/~dyer/vsam/images/mona.gif
  24. 24. Symmetry&Aestheticshttp://pages.cs.wisc.edu/~dyer/vsam/images/mona.gifhttp://www.leonardodavinci.net/images/gallery/monalisa_detail1.jpg
  25. 25. Symmetry&Aestheticshttp://pages.cs.wisc.edu/~dyer/vsam/images/mona.gifhttp://www.leonardodavinci.net/images/gallery/monalisa_detail1.jpghttp://www.saylor.org/site/wp-content/uploads/2012/04/6-mona-lisa.gif
  26. 26. BalanceRestBindingOrderLawRigidityConstraintMotionLooseningArbitrarinessAccidentLife & PlayFreedomhttp://www.acadeuro.org/fileadmin/user_upload/publications/ER_Symmetry_supplement/Lorenz.pdf
  27. 27. BalanceRestBindingOrderLawRigidityConstraintMotionLooseningArbitrarinessAccidentLife & PlayFreedomhttp://www.acadeuro.org/fileadmin/user_upload/publications/ER_Symmetry_supplement/Lorenz.pdfPlatform ProductSymmetry Asymmetry
  28. 28. 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
  29. 29. http://upload.wikimedia.org/wikipedia/commons/6/63/Michelangelos_David.jpghttp://amolife.com/image/images/stories/Art&Abstract/most_popular_sculptures%20(7).jpghttp://www.biographyonline.net/artists/images/Much-The_Scream.jpghttp://www.pics24h.com/img/artwork/5-most-famous-paintings/5-most-famous-paintings03.jpg
  30. 30. http://upload.wikimedia.org/wikipedia/commons/6/63/Michelangelos_David.jpghttp://amolife.com/image/images/stories/Art&Abstract/most_popular_sculptures%20(7).jpghttp://www.biographyonline.net/artists/images/Much-The_Scream.jpghttp://www.pics24h.com/img/artwork/5-most-famous-paintings/5-most-famous-paintings03.jpg
  31. 31. http://www.iie.org/~/media/Images/Corporate/Static-Header/D-F/SH-EmmyNoether.ashx?mh=235&mw=300
  32. 32. http://memegenerator.net/instance/38640565
  33. 33. FinFinhttp://tech.gilt.com@gilttech@ebowmanebowman@gilt.com

×