QUESTIONING THE STATUS QUO (THROUGH THE LOOKING GLASS) OF JAVA, OOP AND BEYOND
Nov 27, 2014
QUESTIONINGTHE STATUS
QUO
(THROUGH THE LOOKING GLASS) OFJAVA, OOP AND BEYOND
WHO AM I?A software developer just like you
... probably less smart than you, actuallyBy the way let's see who we are
WHAT WILL YOU GET OUTOF THIS TALK?
What will you get out of this talk?
image © collien
SOME FOOD FOR THOUGHT AND BRAINTEASING
What will you get out of this talk?
A PRETTY COOL LIST OF FUTUREREADINGS & VIDEOS
What will you get out of this talk?
THINGS YOU DIDN'T KNOWTHINGS YOU ALREADY KNEW
THINGS YOU DIDN'T CARE TO KNOW
What will you get out of this talk?
EXTRA UNSOLICITED SCALA AND FPPROMOTION!
Think about your first steps in programming...
You probably felt excited, curious and every bit of script thatworked was so satisfying!
Even if you've been forced to learn programming asschoolwork, you probably got addicted to it sooner or later...otherwise you wouldn't be here today, listening to this talk
It can happen though, that such passion fades in thebackground, trampled by daily chores
We should strive to try and keep caring for what we do, andkeep alive that initial spark of passion for this activity
“AS DEVELOPERS, AS ANINDUSTRY, WE HAVE THEPOTENTIAL TO CREATE A
BETTER SOCIETY”Hadi Hariri from jetbrains - Codemotion Rome 2014
slides available here www.slideshare.net/Codemotion/developing-in-a-decade
Do you still care?
WHERE DID I GET LOST?
A DAILY ROUTINEMESSY ENTERPRISEY CODE
BUGS, CODE SMELLS, OVER-COMPLEXITY, IMPERFECTIONS
SOPHISTICATED SOLUTIONS TOPROBLEMS...
... NEEDED TO SOLVE THE INDUSTRYNEEDS
LIKE FASTER TIME TO MARKET ANDTIGHT DELIVERY SCHEDULES
THE ENTIRE AGILE MOVEMENT WASBORN TO ADAPT TO AND HANDLE THIS
KIND OF ISSUESAs a personal note, I recommend to take a look at the idea underlying agile, forgetting about costly
certifications and easy promises
Let's take a look at some code
code@Controller@RequestMapping("/orders/{id}")@ExposesResourceFor(Payment.class)@RequiredArgsConstructor(onConstructor = @__(@Autowired))public class PaymentController {
private final @NonNull PaymentService paymentService; private final @NonNull EntityLinks entityLinks;
/** * Accepts a payment for an {@link Order} */ @RequestMapping(value = PaymentLinks.PAYMENT, method = PUT) ResponseEntity<PaymentResource> submitPayment( @PathVariable("id") Order order, @RequestBody CreditCardNumber number) {
if (order == null || order.isPaid()) { return new ResponseEntity<PaymentResource>(HttpStatus.NOT_FOUND); }
CreditCardPayment payment = paymentService.pay(order, number);
PaymentResource resource = new PaymentResource(order.getPrice(), payment.getCreditCard()); resource.add(entityLinks.linkToSingleResource(order));
return new ResponseEntity<PaymentResource>(resource, HttpStatus.CREATED); }
source from https://github.com/olivergierke/spring-restbucks
code/** * Base class for entity implementations. Uses a {@link Long} id. */@MappedSuperclass@Getter@ToString@EqualsAndHashCodepublic class AbstractEntity implements Identifiable<Long> {
@Id @GeneratedValue(strategy = GenerationType.AUTO) @JsonIgnore private final Long id;
protected AbstractEntity() { this.id = null; }}
source from https://github.com/olivergierke/spring-restbucks
pretty terse... uh?
Annotatiomania@Entity@Table(name = "Person", catalog = "TestDB", schema = "dbo")@XmlRootElement@NamedQueries({ @NamedQuery( name = "Person.findAll", query = "SELECT p FROM Person p"), @NamedQuery( name = "Person.findByPersonId", query = "SELECT p FROM Person p WHERE p.personId = :pId"), @NamedQuery( name = "Person.findByPersonName", query = "SELECT p FROM Person p WHERE p.personName = :pName"), @NamedQuery( name = "Person.findByPersonFamily", query = "SELECT p FROM Person p WHERE p.personFamily = :pFamily"), @NamedQuery( name = "Person.findByPersonReference", query = "SELECT p FROM Person p WHERE p.personReference = :pRef")})public class Person implements Serializable { private static final long serialVersionUID = 1L; @Id @Basic(optional = false) @NotNull @Column(name = "person_id", nullable = false) private Integer personId; @Size(max = 50) @Column(name = "person_name", length = 50)
source from https://groups.google.com/forum/#!topic/querydsl/4lgLx3QQqBA
root-context.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<import resource="db-context.xml"/>
<!-- Detects annotations like @Component, @Service, @Controller, @Repository, @Configuration --> <context:component-scan base-package="xpadro.spring.web,controller,xpadro.spring.web.service"/>
<!-- Detects MVC annotations like @RequestMapping --> <mvc:annotation-driven/></beans>
source from https://github.com/xpadro/spring-rest
pom.xml<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.springsource.restbucks</groupId> <artifactId>restbucks</artifactId> <packaging>war</packaging> <version>1.0.0.BUILD-SNAPSHOT</version> <name>Spring RESTBucks</name>
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.1.4.RELEASE</version> </parent>
<properties> <spring-data-releasetrain.version>Evans-BUILD-SNAPSHOT</spring-data-releasetrain.version> <spring-hateoas.version>0.15.0.RELEASE</spring-hateoas.version> <tomcat.version>8.0.9</tomcat.version> </properties>
<dependencies>
<!-- Spring Data REST -->
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency>
source from https://github.com/olivergierke/spring-restbucks
still there?well, this can get pretty verbose
can get hard to decode.486P
CR0_CD equ 040000000h ; Cache Disable bit of CR0CR0_NW equ 020000000h ; Not Write-through bit of CR0
DisableCache proc pushf ; save the flags push eax ; save eax cli ; disable interrupts while we do this mov eax,cr0 ; read CR0 or eax,CR0_CD ; set CD but not NW bit of CR0 mov cr0,eax ; cache is now disabled wbinvd ; flush and invalidate cache
; the cache is effectively disabled at this point, but memory ; consistency will be maintained. To completely disable cache, ; the following two lines may used as well:
or eax,CR0_NW ; now set the NW bit mov cr0,eax ; turn off the cache entirely pop eax ; restore eax popf ; restore the flags ret ; return to callerDisableCache endpcode ends end
"Traditional" enterprise code today looks just like that
codepublic class Application extends Controller {
/** Display the login page or dashboard if connected */ public static Result index() { String email = ctx().session().get("email"); if (email != null) { User user = User.findByEmail(email); if (user != null && user.validated) { return GO_DASHBOARD; } else { Logger.debug("Clearing invalid session credentials"); session().clear(); } }
return ok(index.render(form(Register.class), form(Login.class))); }
source from https://github.com/yesnault/PlayStartApp
codepublic String validate() { User user = null; try { user = User.authenticate(email, password); } catch (AppException e) { return Messages.get("error.technical"); } if (user == null) { return Messages.get("invalid.user.or.password"); } else if (!user.validated) { return Messages.get("account.not.validated.check.mail"); } return null;}
source from https://github.com/yesnault/PlayStartApp
application.conf# This is the main configuration file for the application.# ~~~~~
# Secret key# ~~~~~# The secret key is used to secure cryptographics functions.# If you deploy your application to several instances be sure to use the same key!application.secret="..."
# Global object # ~~~~~# Define the Global object type for this application.# Default to Global in the root package.# global=Global
# Database configuration# ~~~~~ # You can declare as many datasources as you want.# By convention, the default datasource is named `default`#db.default.driver=org.h2.Driverdb.default.url="jdbc:h2:mem:play"
## You can expose this datasource via JNDI if needed (Useful for JPA)# db.default.jndiName=DefaultDS
# Evolutions# ~~~~~# You can disable evolutions if needed# evolutions=disabled
source from https://github.com/yesnault/PlayStartApp
routes.conf# Home pageGET / controllers.Application.index()GET /dashboard controllers.Dashboard.index()
POST /login controllers.Application.authenticate()GET /logout controllers.Application.logout()
GET /settings controllers.account.settings.Index.index()GET /settings/password controllers.account.settings.Password.index()POST /settings/password controllers.account.settings.Password.runPassword()GET /settings/email controllers.account.settings.Email.index()POST /settings/email controllers.account.settings.Email.runEmail()
...
source from https://github.com/yesnault/PlayStartApp
build.sbtimport sbt.Keys._
name := "PlayStartApp"
version := "1.0-SNAPSHOT"
scalaVersion := "2.10.4"
libraryDependencies ++= Seq( jdbc, javaEbean, cache, "org.mindrot" % "jbcrypt" % "0.3m", "com.typesafe" %% "play-plugins-mailer" % "2.2.0", filters)resolvers ++= Seq( "Apache" at "http://repo1.maven.org/maven2/", "jBCrypt Repository" at "http://repo1.maven.org/maven2/org/", "Sonatype OSS Snasphots" at "http://oss.sonatype.org/content/repositories/snapshots")
lazy val root = (project in file(".")).enablePlugins(play.PlayJava)
source from https://github.com/yesnault/PlayStartApp
It's all here folks
WHAT AM I TRYING TO SAY?It's too easy to get lost in cluttered technicalities
Complex environments can blur the overall pictureEvery so often it's good to critically examine the tools we use
Moreso if they result from some predetermined policyFind some time to explore new opportunities, they don't
always pay back, but sometimes they doDon't be scared by the learning curve, you've been there
already!
ABOUT THE "LEARNING CURVE"Rich Hickey (clojure, datomic) made interesting remarks
about the different meaning ofsimple and easy
presentation available here www.infoq.com/presentations/Simple-Made-Easy-QCon-London-2012
HAMMOCK DRIVEN DEVELOPMENTHickey also discussed about the creative process and
problem solving
HAMMOCK DRIVEN DEVELOPMENTAbout how solutions from related or unrelated fields can
inspire new perspectives
HAMMOCK DRIVEN DEVELOPMENTAbout the need to focus
HAMMOCK DRIVEN DEVELOPMENT
presentation available here https://www.youtube.com/watch?v=f84n5oFoZBc
QUIZ TIME
In “The Art of Agile Development” the author explores theconcept that source code is actually the real software designHe supports the concept with an example showing how
modern structured programming conveys the program flowmuch better than Assembly code
1000 NS% = (80 - LEN(T$)) / 21010 S$ 0= ""1020 IF NS$ = 0 GOTO 10601030 S$ = S$ + " "1040 NS% = NS$ - 11050 GOTO 10201060 PRINT S$ + T$1070 RETURN
So much that we seldom need flow diagrams anymore
Can you make out what both of these functions do?def version1(text: String) { val center = (LENGTH - text.size) / 2 var space = "" for (i <- 0 until center) { space += " " } println(space + text + space) }
def version2(text: String) = { def recurse(space: String): String = if ((space*2 + text).size == LENGTH) space + text + space else recurse(space + " ")
println(recurse(""))}
Which version was easier to grok?
Before the second test we need some preparation//A class with some simple-to-understand attributesclass Person(val name: String, val age: Int, val gender: String)
//An appendable "array-like" classclass ArrayBuffer
ready?
So let's rock it!def version1(queued: Iterable[Person]): Iterable[Person] = { val (boyz, girlz) = queued.filter(_.age > 18) .partition(_.gender == "male")
val boyzIn = boyz take (girlz.size / 2)
val in = (boyzIn ++ girlz).to[Set]
for (boy <- boyz if !in(boy)) println(s"Go home, ${boy.name}. Better luck tommorrow, kiddo!")
in}
def version2(queued: Iterable[Person]): Iterable[Person] = { val girlz = ArrayBuffer[Person]() val boyz = ArrayBuffer[Person]() for (person <- queued) { if (person.age > 18) { if (person.gender == "male") boyz.append(person) else girlz.append(person) } } val in = ArrayBuffer[Person]() in.appendAll(girlz) for (i <- 0 until boyz.size) { if (i < girlz.size / 2) in.append(boyz(i)) else println(s"Go home, ${boyz(i).name}. Better luck tommorrow, kiddo!") } return in}
SAME RESULTS?
MAYBE WE LEARNED SOMETHING“It is not only the violin that shapes the
violinist, we are all shaped by the tools wetrain ourselves to use, and in this respectprogramming languages have a devious
influence: they shape our thinking habits.”
Edsger W. Dijkstra - Letter to the budget council of TheUniversity of Texas at Austin
the whole letter is herewww.cs.utexas.edu/users/EWD/OtherDocs/To%20the%20Budget%20Council%20concerning%20Haskell.pdf
WATCH OUT FOR THE "HAMMER SYNDROME"
Try to get a deeper understanding of the tools at yourdisposal
So you can take informed decisions about the best solutionto the problem at hand
"Conventional" solutions are stable but sometimes besttailored to yesterday's problems
Look for opportunities to explore new ideas
A SHORT AND APPROXIMATEPARADE OF EXPLORATIONOPPORTUNITIES FOR THE
MODERN JAVA DEVELOPER
AT THE DESIGN LEVEL
Conventional UnusualCRUD Domain Driven DesignORM Event SourcingMVC CQRS
AT THE FRAMEWORK STACK LEVEL
Conventional UnusualServlet Play!
JSP Vert.xJSF Typesafe Config
Spring JOOQJava-EE GradleMaven sbt
AT THE LANGUAGE LEVEL
Conventional Unusualjava groovy
javascript kotlinsql ceylon
scalaclojurehaskell!
Have a look at
'S DEVOXX '13 PRESENTATION
MATT RAIBLE
to get some inspiration regarding modern webdevelopment technologies
here is the videowww.parleys.com/play/5298cbe3e4b039ad2298c9db/
and here the slidesstatic.raibledesigns.com/repository/presentations/The_Modern_Java_Web_Developer_Bootcamp_Devoxx2013.pdf
[beware! heavy pdf]
TIME TO TAKE OFF AND FLY A LITTLEHIGHER
THE OBJECT-ORIENTED VS.FUNCTIONAL DEBATE
Even though it's hard to define both, we can try to identifysome core features of each
OOP FPModularity/Scoping Composability
Encapsulation (reducedependencies)
Abstraction
Mathematical Reasoning(pureness & immutability)
both approaches have reusability and simplicity as goals
SUGGESTED READINGS ON THESUBJECT
D.L. Parnas - On the Criteria To Be Used in DecomposingSystems into Modules
www.cs.umd.edu/class/spring2003/cmsc838p/Design/criteria.pdf
M.Odersky; M.Zenger - Scalable Component Abstractionslampwww.epfl.ch/~odersky/papers/ScalableComponent.pdf
J.Hughes - Why Functional Programming Matterswww.cse.chalmers.se/~rjmh/Papers/whyfp.html
H.Abelson; G.J.Sussman - Structure and Interpretation ofComputer Programs
mitpress.mit.edu/sicp/
IMPEDANCE MISMATCHOOP attaches behaviour to dataFP separates functions from data
Interestingly, the FP approach to data is considered an in OOPanti-pattern
IMPEDANCE MISMATCH (DETOUR)Object Relational Mapping has been called
“The Vietnam of Computer Science”
Ted Neward cited in blog.codinghorror.com/object-relational-mapping-is-the-vietnam-of-computer-science/
IS RELATIONAL DATABASE ALWAYS THEBEST CHOICE?
“Database Driven Development” anyone?Once again, keep watch for opportunities!
NoSql NoDB!
STILL MORE HIGH LEVEL
and a little out-of-the-box
WHERE'S INNOVATION INTHE PROGRAMMING
WORLD?Internet of Things?
Raspberry Pi?Arduino?
Smart Glasses?...?
WHO'S INNOVATING?Bill Gates?Steve Jobs?
Mark Zuckerberg?...?
What I'm looking after is tools that could change
THE WAY WE THINK ABOUTPROGRAMMING
in out daily work
often with tech available even as we speak
TOOLS FROM THE NEAR FUTURE?REPLScala WorksheetChris Granger's
Microsoft is also researching in the area of with along the same lines
Light TableElm debuggerSwift Playground
Live UIProgramming TouchDevelop
As Light Table came out, Granger made some researchto figure out “what's wrong in programming”, and what kind
of solutions he could come up withHis reasoning is better explained on his blog
www.chris-granger.com/2014/03/27/toward-a-better-programming/
where he shows the progress of a new project called AuroraSimilar ideas can be found on this blog entry about
Legible Mathematicsglench.com/LegibleMathematics/
WOLFRAM LANGUAGE
knowledge based and cloud deployedmath functions and algorithmsdata visualizationnlpdata and visualisation from many world-wide domainseverything based on symbolic functions manipulation(includes symbols, images, docs, graphs...)Wolfram Data Framework ontology
THE PEOPLE WHO IMAGINED SUCHTOOLS
stopped thinking about what we already know aboutsoftware developmentand asked what we can actually do with the technology atour disposalcan we stop taking for granted the way we develop andfocus on how we would like to develop?
Most of the ideas we just saw were inspired by the creativityof this young talented guy
BRET VICTORHis area of interest is the future of computing, education,
data visualization and manipulation
SUGGESTED MATERIAL INCLUDES
The future of programming:
Inventing on principle:
Magic Ink:
worrydream.com/#!/TheFutureOfProgramming
worrydream.com/#!/InventingOnPrinciple
worrydream.com/#!/MagicInk
INFLUENCESIt strikes me how often Victor cites works and "explorers"
from the historical or contemporary computer scienceresearch and other fields
NAMES SUCH AS
Alan KayDouglas EngelbartTony HoareEdsger DijkstraAlan CooperEdward TufteDon NormanJeff RaskinDavid Hestenes
Many of these influencial people's stunning innovations,date back to the early days of the computer age
THE POINT HERE IS HOW MUCH CAN WE LEARN
FROM THE PAST?
“I have this strong feeling that the more Ilook into the latest approaches or hard
problems in today's software, the more I findmyself looking back”
JUST ME
Whenever we discover new cool approaches and ideasabout computer science, they're probably inspired by past
research, tackling the same old fundamental issuesDESIGN PATTERNS
λ-CALCULUS
TYPE SYSTEMS
DATA REPRESENTATION
BIG DATA
DISTRIBUTED SYSTEMS
ACTORS
REACTIVE PROGRAMMING
QUOTING SOME HASKELLEVANGELIST?
“One inconvenient thing about a purely imperative language is that you haveto specify far too much sequencing. For example, if you wish to do a matrixmultiplication, you have to do n³ multiplications. If you write an ordinary
program to do this, you have to specify the exact sequence which they are allto be done. Actually, it doesn't matter in what order you do the
multiplications so long as you add them together in the right groups. Thusthe ordinary sort of imperative language imposes much too much
sequencing, which makes it very difficult to rearrange if you want to makethings more efficient.”
P.J. Landin - The Next 700 Programming Languages, 1966www.cs.cmu.edu/~crary/819-f09/Landin66.pdf
THOUGH THE INFORMATION AGE IS ALLAROUND US NOW, THE HISTORY OF
SOFTWARE AND COMPUTERS IS STILLVERY YOUNG
TO LOOK FORWARD WEALSO NEED TO LOOK BACK
BACK FROMTHE FUTURE
FUTURE OF: APPLICATIONSSep 2013the reactive manifesto - Feb 2009 (first public commit)support by the akka framework - 1990 (first presentation)inspired by erlang language - 1973based on the actor model from Carl Hewitt - Hewitt; Bishop;Steiger; “A Universal Modular Actor Formalism for ArtificialIntelligence. IJCAI”
www.reactivemanifesto.org
www.akka.io
www.erlang.org
FUTURE OF: SOFTWARE DESIGN2012Uncle Bob Martin quotes an article about software designfrom Jack W. Reeves in his book on “Agile SoftwareDevelopment, principles, patterns and practices”1985the author published a reply to said article, after 13 years ofreviews and comments - “What is software design: 13 yearslater”1972the original article - “What is software design?”1962the idea supported in the article, that “the code, as written bythe developer, is the actual application design”, had beenalready clear to Reeves for 10 years
www.developerdotstar.com/mag/articles/reeves_design_main.html
FUTURE OF: DATA MODELINGTHE LATE WILLIAM KENT'S BOOK “DATA & REALITY”
2012 (3rd ed.)updated and commented by Steve Hobermann2000 (2nd ed.)reprinted practically unchanged from the original edition1978 (1st ed.)1967 - a sentence, quoted in the book preface“We do not, it seems, have a very clear and commonly agreedupon set of notions about data - either what they are, how theyshould be fed and cared for, or their relation to the design ofprogramming languages and operating systems” [G.H.Mealy]
Both Kent, in the first edition, and Hobermann, in the mostrecent, confirm the validity of this sentence from 1967 at thetime of writing!
I think that innovation comes from the same open-mindedapproach of those past years, when the future of computing
was still largely unwritten
LEAVING BACK SOME UNNEEDEDBAGGAGE COULD MAKE CREATIVITY
SPROUT
POSSIBLE VISIONS OF SOFTWARE'SFUTURE
Paul Chiusano - The future of software, the end of apps,and why UX designers should care about type theory
pchiusano.github.io/2013-05-22/future-of-software.html
Jamie Brandon - Imperative thinking and the making ofsandwiches
http://www.lighttable.com/2014/07/18/imperative-thinking/
CONCLUSIONSThe interesting problems of computer science don't seem to
have changed much over the last 50 years or socode reasoning/ease of useprogram correctnessmemory allocation/GCconcurrency/parallelismdistributed computingartificial intelligence/data mining...
We can get a lot of inspiration from field pioneers andresearch material
NEVER STOP LEARNING
FREEDOM
Being free is not about doing whatever we please, but aboutnot being constrained by our limited knowledge
CONTACTS
plus.google.com/u/0/+IvanoPagano/ twitter.com/pagoda_5b github.com/ivanopagano stackoverflow.com/users/1237450/pagoda-5b www.linkedin.com/in/ivanopagano
FURTHER DISCUSSION
The problems of the past are not solved... Why? What can we do about it?
WHAT IS YOUR POINT OF VIEW?
COPYRIGHTS NOTICE
Lilo & Stitch copyrights belong to Walt Disney Pictures
The Wolfram Language logo copyrights belong to Wolfram Research Inc.
Back to the future copyrights belong to Universal Studios
The Matrix copyrights belong to Warner Bros. Entertainment Inc.
Questioning The Status Quo by Ivano Pagano is licensed under a .
Based on a work at .
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://github.com/ivanopagano/questioning-status-quo