the learning curve - aleksandar prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · i...
TRANSCRIPT
![Page 1: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/1.jpg)
Scala The learning curve
Aleksandar Prokopec
![Page 2: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/2.jpg)
Sometime back in 2008…
beans
![Page 3: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/3.jpg)
Sometime back in 2008…
List<AbstractSingletonProxyFactoryBean> beans =
![Page 4: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/4.jpg)
Sometime back in 2008…
List<AbstractSingletonProxyFactoryBean> beans =
new ArrayList<AbstractSingletonProxyFactoryBean>();
![Page 5: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/5.jpg)
![Page 6: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/6.jpg)
List<AbstractSingletonProxyFactoryBean> beans =
new ArrayList<AbstractSingletonProxyFactoryBean>();
beans.add(myBean);
Sometime back in 2008…
![Page 7: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/7.jpg)
![Page 8: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/8.jpg)
List<AbstractSingletonProxyFactoryBean> beans =
new ArrayList<AbstractSingletonProxyFactoryBean>();
beans.add(myBean);
for (b : oldBeans) {
}
Sometime back in 2008…
![Page 9: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/9.jpg)
List<AbstractSingletonProxyFactoryBean> beans =
new ArrayList<AbstractSingletonProxyFactoryBean>();
beans.add(myBean);
for (b : oldBeans) {
beans.add(modernizeBean(b));
}
Sometime back in 2008…
![Page 10: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/10.jpg)
List<AbstractSingletonProxyFactoryBean> beans =
new ArrayList<AbstractSingletonProxyFactoryBean>();
beans.add(myBean);
for (b : oldBeans) {
beans.add(modernizeBean(b));
}
singletonBeanMap.put(“myBeanKey”, beans);
Sometime back in 2008…
![Page 11: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/11.jpg)
List<AbstractSingletonProxyFactoryBean> beans =
new ArrayList<AbstractSingletonProxyFactoryBean>();
beans.add(myBean);
for (b : oldBeans) {
beans.add(modernizeBean(b));
}
singletonBeanMap.put(“myBeanKey”, beans);
Map<
String,
List<AbstractSingletonProxyFactoryBean>>
singletonBeanMap = new HashMap<
String,
List<AbstractSingletonProxyFactoryBean>>();
Sometime back in 2008…
![Page 12: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/12.jpg)
![Page 13: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/13.jpg)
![Page 14: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/14.jpg)
![Page 15: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/15.jpg)
5 golden features …that got me hooked
![Page 16: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/16.jpg)
JVM
List<AbstractSingletonProxyFactoryBean> beans =
new ArrayList<AbstractSingletonProxyFactoryBean>();
beans.add(myBean);
for (b : oldBeans) {
beans.add(modernizeBean(b));
}
![Page 17: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/17.jpg)
No semicolon
List<AbstractSingletonProxyFactoryBean> beans =
new ArrayList<AbstractSingletonProxyFactoryBean>()
beans.add(myBean)
for (b : oldBeans) {
beans.add(modernizeBean(b))
}
![Page 18: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/18.jpg)
Local type inference
val beans =
new ArrayList<AbstractSingletonProxyFactoryBean>()
beans.add(myBean)
for (b : oldBeans) {
beans.add(modernizeBean(b))
}
![Page 19: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/19.jpg)
Local type inference
val beans =
new ArrayList[AbstractSingletonProxyFactoryBean]()
beans.add(myBean)
for (b : oldBeans) {
beans.add(modernizeBean(b))
}
![Page 20: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/20.jpg)
Collections
val beans =
Buffer[AbstractSingletonProxyFactoryBean]()
beans.add(myBean)
for (b : oldBeans) {
beans.add(modernizeBean(b))
}
![Page 21: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/21.jpg)
Collections
val beans =
Buffer[AbstractSingletonProxyFactoryBean]()
beans += myBean
for (b : oldBeans) {
beans += modernizeBean(b)
}
![Page 22: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/22.jpg)
Collections
val beans =
Buffer[AbstractSingletonProxyFactoryBean]()
beans += myBean
for (b <- oldBeans) {
beans += modernizeBean(b)
}
![Page 23: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/23.jpg)
Collections
val beans =
Buffer[AbstractSingletonProxyFactoryBean](myBean)
for (b <- oldBeans) {
beans += modernizeBean(b)
}
![Page 24: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/24.jpg)
Collections
val beans =
Buffer(myBean)
for (b <- oldBeans) {
beans += modernizeBean(b)
}
![Page 25: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/25.jpg)
Collections
val beans = Buffer(myBean)
for (b <- oldBeans) {
beans += modernizeBean(b)
}
![Page 26: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/26.jpg)
Lambdas
val beans = Buffer(myBean)
beans ++= oldBeans.map(modernizeBean)
![Page 27: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/27.jpg)
Lambdas
val beans = Buffer(myBean)
beans ++= oldBeans.map(modernizeBean)
![Page 28: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/28.jpg)
knowledge
time
![Page 29: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/29.jpg)
Best way to learn a language
Solve a problem
![Page 30: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/30.jpg)
Best way to learn a language
Solve a problem
Implement a user input API
for a command-line client
![Page 31: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/31.jpg)
Best way to learn a language
Solve a problem
Implement a user input API
for a command-line SSH client
![Page 32: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/32.jpg)
Best way to learn a language
Solve a problem
Ask if custom host needed
If yes, ask to enter custom host
![Page 33: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/33.jpg)
print(“Custom [Y/N]: “)
val yn = readln()
![Page 34: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/34.jpg)
print(“Custom [Y/N]: “)
val yn = readln()
var host = “”
![Page 35: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/35.jpg)
print(“Custom [Y/N]: “)
val yn = readln()
var host = “”
if (yn.trim == “Y”) {
} else ...
![Page 36: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/36.jpg)
print(“Custom [Y/N]: “)
val yn = readln()
var host = “”
if (yn.trim == “Y”) {
print(“Enter host: “)
host = readln()
} else ...
![Page 37: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/37.jpg)
print(“Custom [Y/N]: “)
val yn = readln()
var host = “”
if (yn.trim == “Y”) {
print(“Enter host: “)
host = readln()
} else host = “server.lan:22”
![Page 38: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/38.jpg)
print(“Custom [Y/N]: “)
val yn = readln()
var host = “”
if (yn.trim == “Y”) {
print(“Enter host: “)
host = readln()
} else host = “server.lan:22”
connect(new Remote(host))
![Page 39: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/39.jpg)
print(“Custom [Y/N]: “)
val yn = readln()
var host = “”
if (yn.trim == “Y”) {
print(“Enter host: “)
host = readln()
} else host = “server.lan:22”
connect(new Remote(host))
> Custom [Y/N]:
java.lang.NullPointerException
![Page 40: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/40.jpg)
Fundamental problem
readln() returns null for empty entries
![Page 41: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/41.jpg)
I call it my billion-dollar mistake. It was the
invention of the null reference in 1965.
Tony Hoare
![Page 42: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/42.jpg)
abstract class Option[T]
![Page 43: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/43.jpg)
abstract class Option[T]
class Some[T](x: T) extends Option[T]
class None[T] extends Option[T]
![Page 44: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/44.jpg)
abstract class Option[T] {
def get: T
}
class Some[T](x: T) extends Option[T]
class None[T] extends Option[T]
![Page 45: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/45.jpg)
abstract class Option[T] {
def get: T
}
class Some[T](x: T) extends Option[T] {
def get = x
}
class None[T] extends Option[T]
![Page 46: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/46.jpg)
abstract class Option[T] {
def get: T
}
class Some[T](x: T) extends Option[T] {
def get = x
}
class None[T] extends Option[T] {
def get = sys.error(“None.get”)
}
![Page 47: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/47.jpg)
def text(q: String): Option[String] = {
print(q)
val input = readln()
if (input != null) Some(input)
else None
}
![Page 48: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/48.jpg)
val yn = text(“Custom [Y/N]: “)
![Page 49: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/49.jpg)
val yn = text(“Custom [Y/N]: “)
var host = “”
if (yn.trim == “Y”) {
host = text(“Enter host: “)
}
![Page 50: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/50.jpg)
val yn = text(“Custom [Y/N]: “)
var host = “”
if (yn.trim == “Y”) {
host = text(“Enter host: “)
} else host = “server.lan:22”
connect(new Remote(host))
![Page 51: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/51.jpg)
val yn = text(“Custom [Y/N]: “)
var host = “”
if (yn.trim == “Y”) {
host = text(“Enter host: “)
} else host = “server.lan:22”
connect(new Remote(host))
error: trim not a member of Option[String]
yn.trim
^
![Page 52: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/52.jpg)
val yn: Option[String] = text(“Custom: “)
var host = “”
if (yn.trim == “Y”) {
host = text(“Enter host: “)
} else host = “server.lan:22”
connect(new Remote(host))
error: trim not a member of Option[String]
yn.trim
^
![Page 53: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/53.jpg)
val yn = text(“Custom [Y/N]: “).get
var host = “”
if (yn.trim == “Y”) {
host = text(“Enter host: “).get
} else host = “server.lan:22”
connect(new Remote(host))
![Page 54: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/54.jpg)
val yn = text(“Custom [Y/N]: “).get
var host = “”
if (yn.trim == “Y”) {
host = text(“Enter host: “).get
} else host = “server.lan:22”
connect(new Remote(host))
> Custom [Y/N]:
java.lang.RuntimeError: None.get
![Page 55: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/55.jpg)
val yn = text(“Custom [Y/N]: “)
if (yn == None) return
var host: Option[String] = None
if (yn.get.trim == “Y”) {
val h = text(“Enter host: “)
if (h == None) return else host = h
} else host = Some(“server.lan:22”)
connect(new Remote(host.get))
![Page 56: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/56.jpg)
val yn = text(“Custom [Y/N]: “)
if (yn == None) return
var host: Option[String] = None
if (yn.get.trim == “Y”) {
val h = text(“Enter host: “)
if (h == None) return else host = h
} else host = Some(“server.lan:22”)
return new Remote(host.get)
def startClient() {
val remote: Option[Remote] = query()
connect(remote)
}
![Page 57: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/57.jpg)
def query(): Option[Remote] = {
val yn = text(“Custom [Y/N]: “)
if (yn == None) return None
var host: Option[String] = None
if (yn.get.trim == “Y”) {
val h = text(“Enter host: “)
if (h == None) return None
else host = h
} else host = Some(“server.lan:22”)
return Some(new Remote(host.get))
}
def startClient() {
val remote: Option[Remote] = query()
connect(remote)
}
![Page 58: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/58.jpg)
def query(): Option[Remote] = {
val yn = text(“Custom [Y/N]: “)
if (yn == None) return None
var host: Option[String] = None
if (yn.get.trim == “Y”) {
val h = text(“Enter host: “)
if (h == None) return None
else host = h
} else host = Some(“server.lan:22”)
return Some(new Remote(host.get))
}
def startClient() {
val remote: Option[Remote] = query()
connect(remote)
}
![Page 59: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/59.jpg)
def startClient() {
println(“Now selecting remote.“)
val remote: Option[Remote] = query()
remote match {
}
}
![Page 60: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/60.jpg)
def startClient() {
println(“Now selecting remote.“)
val remote: Option[Remote] = query()
remote match {
case Some(r) => connect(r)
}
}
![Page 61: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/61.jpg)
def startClient() {
println(“Now selecting remote.“)
val remote: Option[Remote] = query()
remote match {
case Some(r) => connect(r)
case None => println(“Can’t connect.”)
}
}
![Page 62: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/62.jpg)
def startClient() {
println(“Now selecting remote.“)
val remote: Option[Remote] = query()
remote match {
case Some(r) => connect(r)
case None => println(“Can’t connect.”)
}
}
if (flag_testing)
startClient(() => Some(localhost))
else
startClient(query)
![Page 63: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/63.jpg)
def startClient(q: () => Option[Remote]) {
println(“Now selecting remote.“)
val remote: Option[Remote] = q()
remote match {
case Some(r) => connect(r)
case None => println(“Can’t connect.”)
}
}
if (flag_testing)
startClient(() => Some(localhost))
else
startClient(query)
![Page 64: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/64.jpg)
def query: () => Option[Remote] = {
() =>
val yn = text(“Custom [Y/N]: “)
if (yn == None) return None
var host: Option[String] = None
if (yn.get.trim == “Y”) {
val h = text(“Enter host: “)
if (h == None) return None
else host = h
} else host = Some(“server.lan:22”)
return Some(new Remote(host.get))
}
![Page 65: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/65.jpg)
Token soup
![Page 66: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/66.jpg)
Token soup
An incomprehensible jumble
of characters which it is
difficult or impossible to discern
the meaning from.
![Page 67: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/67.jpg)
Plan to throw one away; you will, anyhow.
Fred Brooks
The Mythical Man-Month
![Page 68: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/68.jpg)
() => Option[T]
![Page 69: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/69.jpg)
type Query[T] = () => Option[T]
![Page 70: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/70.jpg)
type Query[T] = () => Option[T]
def const[T](x: T): Query[T] =
![Page 71: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/71.jpg)
type Query[T] = () => Option[T]
def const[T](x: T): Query[T] =
() => Some(x)
![Page 72: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/72.jpg)
type Query[T] = () => Option[T]
def const[T](x: T): Query[T] =
() => Some(x)
startClient(
const(new Remote(“localhost”)))
![Page 73: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/73.jpg)
type Query[T] = () => Option[T]
def text(q: String): Query[String] = {
}
![Page 74: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/74.jpg)
type Query[T] = () => Option[T]
def text(q: String): Query[String] = {
() =>
}
![Page 75: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/75.jpg)
type Query[T] = () => Option[T]
def text(q: String): Query[String] = {
() =>
print(q)
}
![Page 76: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/76.jpg)
type Query[T] = () => Option[T]
def text(q: String): Query[String] = {
() =>
print(q)
val input = readln()
}
![Page 77: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/77.jpg)
type Query[T] = () => Option[T]
def text(q: String): Query[String] = {
() =>
print(q)
val input = readln()
if (input != null) Some(input)
else None
}
![Page 78: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/78.jpg)
val hostQuery = text(“Enter host: “)
![Page 79: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/79.jpg)
val hostQuery: Query[String] =
text(“Enter host: “)
![Page 80: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/80.jpg)
val hostQuery: Query[String] =
text(“Enter host: “)
val remoteQuery: Query[Remote]
![Page 81: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/81.jpg)
val hostQuery: Query[String] =
text(“Enter host: “)
val remoteQuery: Query[Remote] =
host => new Remote(host)
![Page 82: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/82.jpg)
val hostQuery: Query[String] =
text(“Enter host: “)
val remoteQuery: Query[Remote] =
hostQuery.map(host => new Remote(host))
![Page 83: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/83.jpg)
val hostQuery: Query[String] =
text(“Enter host: “)
val hostOption: Option[String] =
hostQuery()
val remoteOption: Option[Remote] =
hostOption.map(host => new Remote(host))
![Page 84: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/84.jpg)
val hostQuery: Query[String] =
text(“Enter host: “)
val hostOption: Option[String] =
hostQuery()
val remoteOption: Option[Remote] =
hostOption.map(host => new Remote(host))
for (host <- hostOption) yield {
new Remote(host)
}
![Page 85: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/85.jpg)
def map[T, S](q: Option[T], f: T => S):
Option[S] =
![Page 86: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/86.jpg)
def map[T, S](q: Option[T], f: T => S):
Option[S] =
t s
![Page 87: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/87.jpg)
def map[T, S](q: Option[T], f: T => S):
Option[S] = q match {
}
t s
![Page 88: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/88.jpg)
def map[T, S](q: Option[T], f: T => S):
Option[S] = q match {
case Some(v) => Some(f(v))
case None => None
}
t s
![Page 89: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/89.jpg)
def map[T, S]
(q: Query[T], f: T => S): Query[S] =
type Query[T] = () => Option[T]
![Page 90: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/90.jpg)
def map[T, S]
(q: Query[T], f: T => S): Query[S] =
() =>
type Query[T] = () => Option[T]
![Page 91: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/91.jpg)
def map[T, S]
(q: Query[T], f: T => S): Query[S] =
() => q()
type Query[T] = () => Option[T]
![Page 92: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/92.jpg)
def map[T, S]
(q: Query[T], f: T => S): Query[S] =
() => q() match {
}
type Query[T] = () => Option[T]
![Page 93: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/93.jpg)
def map[T, S]
(q: Query[T], f: T => S): Query[S] =
() => q() match {
case Some(v) => Some(f(v))
case None => None
}
type Query[T] = () => Option[T]
![Page 94: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/94.jpg)
val hostQuery: Query[String] =
text(“Enter host: “)
val remoteQuery: Query[String] =
for (host <- hostQuery) yield {
new Remote(host)
}
![Page 95: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/95.jpg)
for (host <- hostQuery) yield {
new Remote(host)
}
![Page 96: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/96.jpg)
val yn = text(“Custom [Y/N]: “)
for {
host <- if (???) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 97: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/97.jpg)
val yn: Query[String] =
text(“Custom [Y/N]: “)
for {
host <- if (???) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 98: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/98.jpg)
for {
yn <- text(“Custom [Y/N]”)
host <- if (???) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 99: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/99.jpg)
for {
yn <- text(“Custom [Y/N]”)
host <- if (yn == “Y”) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 100: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/100.jpg)
for {
yn <- Some(“Y”)
host <- if (yn == “Y”) Some(“localhost”)
else Some(“server.lan:22”)
} yield new Remote(host)
![Page 101: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/101.jpg)
for {
yn <- Some(“Y”)
host <- Some(“localhost”)
} yield new Remote(host)
![Page 102: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/102.jpg)
for {
yn <- Some(“Y”)
host <- Some(“localhost”)
} yield new Remote(host)
Some(“Y”).map(yn =>
)
![Page 103: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/103.jpg)
for {
yn <- Some(“Y”)
host <- Some(“localhost”)
} yield new Remote(host)
Some(“Y”).map(yn =>
Some(“localhost”)
)
![Page 104: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/104.jpg)
for {
yn <- Some(“Y”)
host <- Some(“localhost”)
} yield new Remote(host)
Some(“Y”).map(yn =>
Some(“localhost”).map(host =>
new Remote(host)
)
)
![Page 105: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/105.jpg)
for {
yn <- Some(“Y”)
host <- Some(“localhost”)
} yield new Remote(host)
Some(“Y”).map(yn =>
Some(“localhost”).map(host =>
new Remote(host)
)
): Option[???]
![Page 106: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/106.jpg)
for {
yn <- Some(“Y”)
host <- Some(“localhost”)
} yield new Remote(host)
Some(“Y”).map(yn =>
Some(“localhost”).map(host =>
new Remote(host)
)
): Option[Option[Remote]]
![Page 107: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/107.jpg)
def map[T, S](q: Option[T],
f: T => S): Option[S]
![Page 108: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/108.jpg)
def map[T, Option[S]](q: Option[T],
f: T => Option[S]): Option[Option[S]]
![Page 109: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/109.jpg)
def flatMap[T, S](q: Option[T],
f: T => Option[S]): Option[S]
![Page 110: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/110.jpg)
def flatMap[T, S](q: Option[T],
f: T => Option[S]): Option[S] = {
q match {
case None => None
}
}
![Page 111: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/111.jpg)
def flatMap[T, S](q: Option[T],
f: T => Option[S]): Option[S] = {
q match {
case None => None
case Some(v) => f(v)
}
}
![Page 112: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/112.jpg)
def flatMap[T, S](q: Option[T],
f: T => Option[S]): Option[S]
for {
yn <- Some(“Y”)
host <- if (yn == “Y”) Some(“localhost”)
else Some(“server.lan:22”)
} yield new Remote(host)
Some(“Y”).flatMap(yn =>
Some(“localhost”).map(host =>
new Remote(host)
)
): Option[Remote]
![Page 113: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/113.jpg)
def flatMap[T, S](q: Option[T],
f: T => Option[S]): Option[S]
for {
yn <- Some(“Y”)
host <- if (yn == “Y”) Some(“localhost”)
else Some(“server.lan:22”)
} yield new Remote(host)
Some(“Y”).flatMap(yn =>
Some(“localhost”).map(host =>
new Remote(host)
)
): Option[Remote]
![Page 114: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/114.jpg)
def flatMap[T, S](q: Option[T],
f: T => Option[S]): Option[S]
for {
yn <- Some(“Y”)
host <- if (yn == “Y”) Some(“localhost”)
else Some(“server.lan:22”)
} yield new Remote(host)
Some(“Y”).flatMap(yn =>
Some(“localhost”).map(host =>
new Remote(host)
)
): Option[Remote]
![Page 115: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/115.jpg)
def flatMap[T, S](q: Query[T],
f: T => Query[S]): Query[S]
type Query[T] = () => Option[T]
![Page 116: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/116.jpg)
def flatMap[T, S](q: Query[T],
f: T => Query[S]): Query[S] =
() => q() match {
case Some(v) => f(v)()
case None => None
}
type Query[T] = () => Option[T]
![Page 117: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/117.jpg)
for {
yn <- text(“Custom [Y/N]: “)
host <- if (yn == “Y”) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 118: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/118.jpg)
Query[T]
is a monad!
![Page 119: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/119.jpg)
val yn = text(“Custom [Y/N]? ”)()
if (yn == None) return None
var host = null
if (yn.get == “Y”) host = text(“Host: ”)()
else host = const(“server.lan:22”)()
if (host == None) return None
return Some(new Remote(host.get))
for {
yn <- text(“Custom [Y/N]: “)
host <- if (yn == “Y”) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
VS.
![Page 120: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/120.jpg)
Argument #1 The monad approach is more concise,
more readable and more beautiful.
![Page 121: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/121.jpg)
val yn = text(“Custom [Y/N]? ”)()
if (yn == None) return None
var host = null
if (yn.get == “Y”) host = text(“Host: ”)()
else host = const(“server.lan:22”)()
if (host == None) return None
return Some(new Remote(host.get))
for {
yn <- text(“Custom [Y/N]: “)
host <- if (yn == “Y”) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 122: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/122.jpg)
val yn = text(“Custom [Y/N]? ”)()
if (yn == None) return None
var host = null
if (yn.get == “Y”) host = text(“Host: ”)()
else host = const(“server.lan:22”)()
if (host == None) return None
return Some(new Remote(host.get))
for {
yn <- text(“Custom [Y/N]: “)
host <- if (yn == “Y”) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 123: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/123.jpg)
But, beauty is in the eye of the
beholder.
![Page 124: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/124.jpg)
Argument #2 The monad approach is shorter.
![Page 125: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/125.jpg)
val yn = text(“Custom [Y/N]? ”)()
if (yn == None) return None
var host = null
if (yn.get == “Y”) host = text(“Host: ”)()
else host = const(“server.lan:22”)()
if (host == None) return None
return Some(new Remote(host.get))
for {
yn <- text(“Custom [Y/N]: “)
host <- if (yn == “Y”) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 126: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/126.jpg)
But, does shorter code imply
better code?
while(*dst++ = *src++);
![Page 127: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/127.jpg)
Argument #3
In the monad approach,
there is no duplicated code.
![Page 128: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/128.jpg)
val yn = text(“Custom [Y/N]? ”)()
if (yn == None) return None
var host = null
if (yn.get == “Y”) host = text(“Host: ”)()
else host = const(“server.lan:22”)()
if (host == None) return None
return Some(new Remote(host.get))
for {
yn <- text(“Custom [Y/N]: “)
host <- if (yn == “Y”) text(“Host: “)
else const(“server.lan:22”)
} yield new Remote(host)
![Page 129: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/129.jpg)
val yn = text(“Custom [Y/N]? ”)()
if (yn == None) return None
var host = null
if (yn.get == “Y”) host = text(“Host: ”)()
else host = const(“server.lan:22”)()
if (host == None) return None
return Some(new Remote(host.get))
Not just more boilerplate,
more of the same code.
![Page 130: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/130.jpg)
DRY principle Reduce repetition of any kind.
![Page 131: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/131.jpg)
Monad Abstracts how the statements in the
program are chained together.
![Page 132: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/132.jpg)
Monad A programmable semicolon.
![Page 133: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/133.jpg)
Congratulations, you understand monads!
![Page 134: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/134.jpg)
knowledge
time
lambdas, collections, no semicolons
for-comprehensions
flatMap
![Page 135: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/135.jpg)
Abstraction
abstraction concrete code
abstraction concrete code
![Page 136: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/136.jpg)
Abstraction
abstraction concrete code
abstraction concrete code
abstraction concrete code
![Page 137: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/137.jpg)
![Page 138: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/138.jpg)
knowledge
time
lambdas, collections, no semicolons
for-comprehensions
flatMap
knowledge
applied knowledge
![Page 139: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/139.jpg)
Disallow abstractions
![Page 140: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/140.jpg)
Disallow abstractions
![Page 141: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/141.jpg)
Better tooling Programmable lint checkers
![Page 142: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/142.jpg)
It’s useful to customize your semicolons,
but even more useful to omit them.
![Page 143: The learning curve - Aleksandar Prokopecaleksandar-prokopec.com/resources/docs/jazoon15.pdf · I call it my billion-dollar mistake. It was the invention of the null reference in 1965](https://reader034.vdocuments.site/reader034/viewer/2022050209/5f5bf4cc71d299645c50067a/html5/thumbnails/143.jpg)
Thank you!