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.
10. public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello, world");
}
}
11. public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello, world");
}
}
object HelloWorld extends App {
println("hello, world")
}
!
12. public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello, world");
}
}
object HelloWorld extends App {
println("hello, world")
}
!
println("hello, world")
13. for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
System.out.println(i*j);
}
}
!
!
14. 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)
!
15. Future<Integer> f = callService1();
Future<Integer> f2 = callService2(f.get());
System.out.println(f2.get());
16. 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))
!
21. “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
23. 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.
29. “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
30. “the symmetry group of a program ... is the
group of all refactorings under which the
program behaves identically after applying
refactorings in any order”
31. for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
System.out.println(i*j);
}
}
!
!
Future<Integer> f = callService1();
Future<Integer> f2 = callService2(f.get());
System.out.println(f2.get());
Ja
va
String capitalize(String name) {
if (name == null) return null;
else return Character.toUpperCase(
name.charAt(0)) + name.substring(1);
}
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)
}
!
!
Sc
al
a