eamonn.boyle@instil.co
BelTech 2018
© Instil Software 2018
The Revolution Will Be Plagiarised
Language trends in 2018 and onward
eamonn.boyle@instil.co
BelTech 2018
© Instil Software 2018
The Revolution Will Be Plagiarised
Language trends in 2018 and onward
Me
Us
My Dog
Code
Languages
V1.0 Release TIOBE PYPL Redmonk
Java 1996 1 1 2
JavaScript 1995 8 3 1
Python 1994 4 2 3
C# 2002 5 5 5
TypeScript 2014 - 12 14
Swift 2014 15 9 10
Kotlin 2016 49 16 27
2018
Disclaimer – I am not an oracle
Expressionism
The Scream by Edvard Munch (1893)
Expressive
• Meaningful
• Telling
• Revealing
Code #include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#define O_o "sfX4.Fv8H!`uf"
"|~0y'vWtA@:LcO9d}y.!uL!Gd+ml(<+Ds!J"
"e.6!r!%l6G!n~^<i=%pEwL%P!'<!FQt%u 5toG57j/3"
"!:E%;!ea!!!WqE0z!f/y}!%!!Qi6!uzt!n}?]!bl!ak!SetR<"
"Zj$x!~V!n&g8!cK! KrgR'8@c]!%-q9V.3fa[E8X%dY'w!#H <P~6"
"?guhljL!^P% ?" "8!@dP,!!o+fb"
"!pv!;!Hm%Ro4" "n:}nkD!Q!kN"
"e:| 'b5sc!e" /* nothing */
#define mu(a) a a a a a //-
#define O_(Q_ ) "033[" #Q_
#define Q_(O) mu(mu(mu(O)))
#define Q/*-- ++--*/O9--||(
#define main( )main(){/**/
signal(13,1), _();}f()//--+
#define k( k) getenv( "D"#k
char*O0=O_o,OO,*Q1,O5[97];int*Q5,_Q=0,Q0=0,_O=0,_0=0,O=5,QQ,O6,Q6,O3
,Q4,O4=41088,O1=sizeof(O5),O7=234;long long __;_()Q_({)int*Q3,Q2,O2,C,
QO,O9=O,O8=!!!!!!!!!!k(RAFT));long long Q8;char*Q9=O_(1A)O_(%dB)O_(%dC
)O_(34m)"xe2%c%crn"O_(0m)O_(%dA),*Q7;__+=(__*92+*O0-35-__)*(QO=Q_(!
!)(*O0-33)*!O9--),O0+=O1*QO,QO&&_(),Q Q4&&(O--,_(),O0+=194,O++,Q4--,_(
))),Q O=0,__=0,_(),O=3,_()),Q __&&(C=__&15,_O+=(C<2)*12+!(QO=C&14^2)*(
4-_O)+(C==6)*( 12-2*_O)+(C>6)*(9-(C-7)%3),_Q+=!QO*(_Q%QQ+(C&1)*O3-_Q),
_0+=!_0*!QO+(1-2*_0)*!(C^4),(C==5)&&(__>>=4,Q8=__,Q7=O0,Q4=__&15,O=1,_
()|O ++&_(),__=Q8 ,O0=Q7 ),Q3=( _Q+= O8*(9 *O4*
O1 > lrand48()) +(_O%=8,( (_O% 6>2) -(_O%
7<2) )*QQ+((_O +7)%8<3 )-(_O>4) )*( C>5 ),
Q2 = _Q/ O3)* O6+Q5 +(O2=_Q%QQ )/ 2,*Q3=*
Q3 % O4+O4|(1 << Q_("" "@CADBEHI") [_Q%2+_Q
%O3/ QQ*2 ]- 64)* _0, sprintf(O5, Q9, Q2+1,
O2/2 ,*Q3>>8 ,85* 3&* Q3,Q2+1 )&& _0&&(O=8,
Q1 = O5,_()), Q0 +=(O2 >Q0)*_0*(O2 -Q0 ),__
+=!( C>9)*(3- __+ ( __>>4))-3, __ +=(C>12
) *( (__<<4 )+ C-3-__) ,usleep( O4* _0/(3*
O8+1 )),O =3,_() )) ,!O9 --&& read(
1 ,& OO,1)> 0&&(O= (QO=OO ==35 )*3+6 ,_()
,QO&&(OO=10,O=6,_(),1)||(O=4,_()),0)||close(dup2(3-dup2(1,dup(0)-3),1)
*0+2)*0||Q write(1,"> ",2),ioctl(Q0=0,TIOCGWINSZ,O5)^--O&(O3=(QQ=(O6=*
((short*)O5+1))*2)*4),Q6=-O1,Q5=calloc(3*O6,8),_()),Q (O=8,QO=!(O2=OO-
10)|!(Q2=OO-32)*(Q0+58>QQ)|(Q0+12>QQ))&&(Q1=O_(3B),_(),write(1,"> ",2)
),Q0+=!QO*!Q2*4-QO*Q0,O2*Q2&&(!Q0&&(memset(Q5,0,3*O3),Q0=4,Q1="nnn"
O_(3A),_()),O=7,_Q=7*QQ+Q0+2,_O=_0=0,OO+=(OO>64 &OO<91)*32,O0=Q_(O_o)+
O7,_(),(*O0-OO)||(O=2,O0+='a',_( )))),Q *O0-OO)&&(*(O0+=O1)-33)&&(O=0,
_(),O=7,O0+=O1,_()),Q write(0,Q1,strlen(Q1))),Q OO=Q_(O_o)[Q6+=O1],(Q6
%strlen(O_o)-O7)&&(O=6,_(),O=9,_()));Q_(})/*+++++ IOCCC 2015 +++++*/
main()
{
puts("hello world!");
}
Etienne Duble etienne.duble@imag.fr
The International Obfuscated C Code Contest
Code#/*
q{G.
*/include<stdio.h> /*G!*/
#define G(g,o)/**/int g=o;/**/
#define q(b)int o[]={0,0,0,0,
0};char*p=#b,P[9999],*d=P,*e[]={"('A`)"
,"(A`)","('A)","('A`)"},b/*3792/e887094c*/
q(*s=__TIME__;extern void w(){G(g,*o)for(;g--
;);}extern void x(){}extern void y(){}static void z
(char*p){for(;(*d=*p++)!=0;d++)*d-=061*(59==*d||*d==81);}int
main(){char N[]="<;iQ=/*do<;dQ=ook8?boc;aQ=odr8>oc;_Q<ox8>oc"
";^Q<d|8=o;]Q<dj8<Pk8<c]'?;QQdi8?P'Q)d8<9`8?c;Qdh8=P']Q<`c8>PQ9_8"
">b;og8=''`Q<`b8?'QQ9_8?c;dPe8dQa8<P]Q<``8=;'f8>QQ`]8?ocQQ_8=''_Q`8aQ"
"CYOUQWIN!]Q=;of8BQQ)88bc]QA98P'Qo]8>oQQ_8CP;QQ98b`_8@P8(Q`]'^Q=`']QB)88"
"bQQ]`8J;QQ`88bc99bd(`8iQ@''QQo^8E'`8c;QQ'Q``8?QQ`'kQ<o]8B9PQQ`';_Q<`_8<cbQ"
"<o_Q<o_QBdo`QQ';`Q=9`]8=bobQ_o_Q<o]8=';bQC(88cQ`bcgQ>oP']8<;cQ>98)^Q?''oc`Q>"
"oc']Q]8<;cQ>`8bbQA``QQ''`Q?88P;dQ=`)nQ?*/;;"/*}}=~/./;print"cp40sinon.c40r",
"un.cn";for($i=1;$i<21;$i++){for($j=0;$j<2;$j++){print"gccx20-O",$j*2,
"40run.cx20-o run&&./run|tee run.cn"if!($i%(2+$j));}print"sleep $jn";
} __DATA__ 8M*/;G(Z,60*(60*(10**s+s[1])+s[3]*10+s[4])+s[6]*10+s[7]-1933008
)G(l,(Z+86400-*o)%86400)G(M,o[3] *17+o[4]*11) G(O,(&x-&w)-(&y-&x)?1:0)G(
m,*o)G(n,m)G(i,0)G(j,O)if(M>197)for( p=N;*p; )if(*p>92){*N=p[1 ];N[1]
=0;for( O=*p++-90;0<O--;z( N));p++;}else{ s= p;for(O= *p++-59;O--;p++)
p[-1]=*p;p[-1]=0;z(s);}else{ if(M==0){*o=Z;l=0; }if(o[O+3]&&o[ O+1]+(O?3:5
)>l)Z=O;else++o[O+3];o[O+1] =l; if(l<60)d+= sprintf(d,"#include<stdio.h>"
"12#define G(g,o) int g=o;n#d" "efine 161(b" ")int40o[]={%d,%d,%d,%d,%d};char"
"*p=#b,P[9999],*d=P,*e[]=" "{"%s", "" "%s" "","%s","%s"}, bnq(%s)n"
,*o,o[01],o[2],o[3], o[4] ,e[3],e[1], e[2],*e,p);z("/*;; ");for(i=0; i++<18
;z(";"))for(j=0;j++<11;n=(n*193+287) %384 ){m=(97+(67*m ))%198;for
(O=0;O++<n%03;z("Q") );s=d;for(z(e[ ( n/3)&3]);m<M &&s-d;*s++
=040);}if(l<60) {for (z(";Time:Q") ;(l++<60);z ("#"));for
(z(";Heca"/* */ "t" "eQII:" "Q") ;o[3 ]++ <=24;z("#"));z
(Z?"":"Q(j" "a" "m" "me" /* @ */"d" ")");for(z(
";GlockQ18" "C:" /* * */ "Q");o[4]++<
25;z("#") );z( Z- 1? ";":"Q(jam"
"med);") /* */ ;} else z(";"
";Gam" /* */ "eQover."
";;" /* (- */);for
(O= 0;O <77;O
++) z("Q");z( "*" ""
"/" );}
puts (P);;
return+0;})
Don Yang omoikane@uguu.org
The International Obfuscated C Code Contest
Expressive
• Meaningful
• Telling
• Revealing
Theoretical vs Practical
Number of ideas it is
possible to express
Vs
The ease at which we can
express ideas
Theoretical vs Practical
SELECT MAX(Price) AS LargestPrice
FROM Products;
Balancing Act
Statically Typed
• Compile Time Error Checking
• Type Inference
• Const / Immutability
• Non-nullable Types
• Null Access Operations
Extensions
Coroutines / async await
Expressive Data Structures
Destructuring
Operator Overloading
Pattern Matching
OO Programming
• Properties
• Reified Generics
• Primary Constructors
• Initialisers
• Indexers
Functional Programming
• Lambdas / Closures
• Local Functions
• Expression Functions
Aspect Oriented Programming
Modularity
Multi-platform
Features that help me be Expressive in Code
Static types simply makes writing large amounts of code easier
Compile Time Error Checking
Better support within IDEs
A side benefit is it leads to faster code (if compiled)
Static Typing
Dynamic Languages envy this capability
JavaScript limitations led to the development of Flow
• Developed by Facebook and first released in 2014
• Add static typing and analysis to JavaScript
They market it as allowing you to,
• Code Faster – find bugs as you code
• Code Smarter – IDE understands your intent
• Code Confidently
• Code Bigger
Static Typing
Static Typing
JavaScript TypeScript
Python added type annotations in version 3.5
Static Typing
def scale(scalar: float, vector: Vector) -> Vector:
return ...
def scale(scalar, vector):
return ...
Type inference is a must for me
Explicitly defining types when obvious,
• Makes code unnecessarily verbose
• Makes refactoring commits noisier
• Exposes details that are often unimportant
Compare Java 9 and Kotlin
• Java finally got local type inference in v10
Static Typing – Not More Typing
Type Inference – Java vs Kotlin
private static boolean isEven(int i) {
return i % 2 == 0;
}
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5 };
List<Integer> evensList =
new ArrayList<Integer>();
for (int i: numbers) {
if (isEven(i)) {
evensList.add(i);
}
}
}
private fun isEven(i: Int) = i % 2 == 0
fun main(args: Array<String>) {
val numbers = intArrayOf(1, 2, 3, 4, 5)
val evensList = ArrayList<Int>()
for (i in array) {
if (isEven(i)) {
evensList.add(i)
}
}
}
Java Kotlin
Type Inference – Java vs Kotlin
private static final double DISCOUNT = 0.1;
private static void applyDiscount(User user) {
Cart cart = user.getCart();
Iterable<CartItem> items = cart.getItems();
double total = sumCartItems(items);
double discount = total * DISCOUNT;
cart.applyDiscount(discount);
}
private const val DISCOUNT = 0.1
private fun applyDiscount(user: User) {
val cart = user.cart
val items = cart.items
val total = sumCartItems(items)
val discount = total * DISCOUNT
cart.applyDiscount(discount)
}
Java Kotlin
With Type Inference - Good Naming is Even More Important
Many modern languages have the concept of non-nullable types
This removes a whole class of error
Const, Non-nullable and Value Types
Const, Non-nullables and Value Types
private fun processUserPolicy(user: User) {
val policy = user.policy
if (policy.isComplete) {
policyProcessor.process(policy)
}
}
private static void processUserPolicy(User user) {
if (user != null && user.getPolicy() != null) {
Policy policy = user.getPolicy();
if (policy.isComplete()) {
policyProcessor.process(policy);
}
}
}
Java
Kotlin
Object Oriented programming is a great way of modelling many problems
We want languages which offer succinct ways of implement classes
• Access modifiers (private, public, protected etc)
• Properties – get and/or set
• Primary Constructors
• Data Classes
OO Programming
Basic Model Classes – Java
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
}
Basic Model Classes – Java
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
}
Basic Model Classes – Java
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
Basic Model Classes – Java
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Rating getRating() {
return rating;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Genre getGenre() {
return genre;
}
public void setGenre(Genre genre) {
this.genre = genre;
}
}
Basic Model Classes – Java vs C#
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Rating getRating() {
return rating;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Genre getGenre() {
return genre;
}
public void setGenre(Genre genre) {
this.genre = genre;
}
}
public class Movie {
public string Title { get; set; }
public string Description { get; set; }
public Rating Rating { get; set; }
public Genre Genre { get; set; }
public Movie(string title, string description,
Rating rating, Genre genre) {
Title = title;
Description = description;
Rating = rating;
Genre = genre;
}
}
Java C#
Basic Model Classes – Java vs Swift
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Rating getRating() {
return rating;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Genre getGenre() {
return genre;
}
public void setGenre(Genre genre) {
this.genre = genre;
}
}
Java Swift
Basic Model Classes – Java vs Kotlin
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Rating getRating() {
return rating;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Genre getGenre() {
return genre;
}
public void setGenre(Genre genre) {
this.genre = genre;
}
}
data class Movie(var title: String,
var description: String,
var rating: Rating,
var genre: Genre) {
}
Java Kotlin
Basic Model Classes – Java vs Kotlin
import java.util.Objects;
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Rating getRating() {
return rating;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Genre getGenre() {
return genre;
}
public void setGenre(Genre genre) {
this.genre = genre;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Movie movie = (Movie) o;
return Objects.equals(title, movie.title) &&
Objects.equals(description, movie.description) &&
Objects.equals(rating, movie.rating) &&
Objects.equals(genre, movie.genre);
}
@Override
public int hashCode() {
return Objects.hash(title, description, rating, genre);
}
@Override
public String toString() {
return "Movie{" +
"title='" + title + ''' +
", description='" + description + ''' +
", rating=" + rating +
", genre=" + genre +
'}';
}
}
data class Movie(var title: String,
var description: String,
var rating: Rating,
var genre: Genre) {
}
We also get hashCode(), equals(), toString() and more…
External libraries and tools like Lombok will help with Java
Java Kotlin
Functional Programming also helps us solves lots of problems
Many languages now support this
• Functions as first class citizens
• Higher order functions – functions as arguments and return
• Inline functions and lambdas
• Closures
Java gained many of these features in Java 8
Blending OO and FP allows us to write elegant code
• Many modern language provide both
Functional Programming
Functional Chaining – C# vs Java
Reified Generics with support for primitives makes the code simpler
double averageSalary = employees
.stream()
.filter(x ->
x.getDepartment() == Engineering)
.mapToInt(Employee::getSalary)
.average()
.orElse(0);
Java
var averageSalary = employees
.Where(x => x.Department == Engineering)
.Select(x => x.Salary)
.Average();
C#
val averageSalary = employees
.filter { it.department === Engineering }
.map { it.salary }
.average()
Kotlin
Swift
$0
$0
Extensions also allow us write more expressive code
• Extend existing (even built-in types)
We can create Domain Specific Languages
Functional Chaining
val averageSalary = employees
.filter { it.department === Engineering }
.averageSalary()
Extensions also allow us write more expressive code
• Extend existing (even built-in types)
We can create Domain Specific Languages
Functional Chaining
deviceStatusStream()
.filterForErrors()
.collate().and()
.send()
Most systems we write have asynchronous components
Typically we can’t block due to limited resources
We need ways to hide the complexity of async programming
Asynchronous Programming
Sequential Algorithm – Asynchronous Steps
disableUI();
const exchangeRates = exchangeRateReader.read();
const report = reportBuilder.build(exchangeRates);
reportSaver.save(report);
enableUI();
Early Solution – Callback Hell
disableUI();
exchangeRateReader.onload = exchangeRates => {
reportBuilder.onload = report => {
reportSaver.onsave = () => {
enableUI();
};
reportSaver.save(report);
};
reportBuilder.build(exchangeRates);
};
exchangeRateReader.read();
Early Solution – Callback Hell
disableUI();
exchangeRateReader.read();
exchangeRateReader.onload = exchangeRates => {
reportBuilder.build(exchangeRates);
};
reportBuilder.onload = report => {
reportSaver.save(report);
};
reportSaver.onsave = () => {
enableUI();
};
Promises and Futures and Tasks...oh my
disableUI();
exchangeRateReader.read()
.then(exchangeRates => reportBuilder.build(exchangeRates))
.then(report => reportSaver.save(report)
.then(enableUI);
Async Await
disableUI();
const exchangeRates = await exchangeRateReader.read();
const report = await reportBuilder.build(exchangeRates);
await reportSaver.save(report);
enableUI();
disableUI();
const exchangeRates = exchangeRateReader.read();
const report = reportBuilder.build(exchangeRates);
reportSaver.save(report);
enableUI();
Coroutines - Kotlin
disableUI();
val exchangeRates = exchangeRateReader.read().await();
val report = reportBuilder.build(exchangeRates).await();
reportSaver.save(report).await();
enableUI();
Should I Care
Every Language is Leap Frogging the Others – Why?
Waste
Yeah!!!!
We get to do another port of
the library 
•Java: RxJava
•JavaScript: RxJS
•C#: Rx.NET
•C#(Unity): UniRx
•Scala: RxScala
•Clojure: RxClojure
•C++: RxCpp
•Lua: RxLua
•Ruby: Rx.rb
•Python: RxPY
•Go: RxGo
•Groovy: RxGroovy
•JRuby: RxJRuby
•Kotlin: RxKotlin
•Swift: RxSwift
•PHP: RxPHP
•Elixir: reaxive
•Dart: RxDart
RxNetty
RxAndroid
RxCocoa
We still see progress reinventing the wheel
Real-world constraints
• Legacy code – lock in, interop, re-use
• Existing team skills
• Domain specific considerations
Tooling
• IDE with Navigation, Refactoring etc
Test Frameworks and Tools
Active Community
Large open source library repository
Excellent documentation
What else do I consider?
Think carefully about the languages you choose
• If you’re in the JavaScript space, consider TypeScript
• If you’re in the Java space, consider Kotlin (a lot!)
• If you’re in the Objective C space, consider Swift
• If you’re in the C++ space, use C++17
• If you’re in C#, keep on truckin’
Consider how familiar you are with the languages you’ve got
Keep up to date with small upgrades
• Don’t wait until it’s too late
Refactor your code mercilessly
Summary
Questions?

Being Expressive in Code

  • 1.
    eamonn.boyle@instil.co BelTech 2018 © InstilSoftware 2018 The Revolution Will Be Plagiarised Language trends in 2018 and onward
  • 2.
    eamonn.boyle@instil.co BelTech 2018 © InstilSoftware 2018 The Revolution Will Be Plagiarised Language trends in 2018 and onward
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
    Languages V1.0 Release TIOBEPYPL Redmonk Java 1996 1 1 2 JavaScript 1995 8 3 1 Python 1994 4 2 3 C# 2002 5 5 5 TypeScript 2014 - 12 14 Swift 2014 15 9 10 Kotlin 2016 49 16 27 2018
  • 8.
    Disclaimer – Iam not an oracle
  • 9.
    Expressionism The Scream byEdvard Munch (1893)
  • 10.
  • 11.
    Code #include <sys/ioctl.h> #include<unistd.h> #include <string.h> #include <signal.h> #include <stdlib.h> #include <stdio.h> #define O_o "sfX4.Fv8H!`uf" "|~0y'vWtA@:LcO9d}y.!uL!Gd+ml(<+Ds!J" "e.6!r!%l6G!n~^<i=%pEwL%P!'<!FQt%u 5toG57j/3" "!:E%;!ea!!!WqE0z!f/y}!%!!Qi6!uzt!n}?]!bl!ak!SetR<" "Zj$x!~V!n&g8!cK! KrgR'8@c]!%-q9V.3fa[E8X%dY'w!#H <P~6" "?guhljL!^P% ?" "8!@dP,!!o+fb" "!pv!;!Hm%Ro4" "n:}nkD!Q!kN" "e:| 'b5sc!e" /* nothing */ #define mu(a) a a a a a //- #define O_(Q_ ) "033[" #Q_ #define Q_(O) mu(mu(mu(O))) #define Q/*-- ++--*/O9--||( #define main( )main(){/**/ signal(13,1), _();}f()//--+ #define k( k) getenv( "D"#k char*O0=O_o,OO,*Q1,O5[97];int*Q5,_Q=0,Q0=0,_O=0,_0=0,O=5,QQ,O6,Q6,O3 ,Q4,O4=41088,O1=sizeof(O5),O7=234;long long __;_()Q_({)int*Q3,Q2,O2,C, QO,O9=O,O8=!!!!!!!!!!k(RAFT));long long Q8;char*Q9=O_(1A)O_(%dB)O_(%dC )O_(34m)"xe2%c%crn"O_(0m)O_(%dA),*Q7;__+=(__*92+*O0-35-__)*(QO=Q_(! !)(*O0-33)*!O9--),O0+=O1*QO,QO&&_(),Q Q4&&(O--,_(),O0+=194,O++,Q4--,_( ))),Q O=0,__=0,_(),O=3,_()),Q __&&(C=__&15,_O+=(C<2)*12+!(QO=C&14^2)*( 4-_O)+(C==6)*( 12-2*_O)+(C>6)*(9-(C-7)%3),_Q+=!QO*(_Q%QQ+(C&1)*O3-_Q), _0+=!_0*!QO+(1-2*_0)*!(C^4),(C==5)&&(__>>=4,Q8=__,Q7=O0,Q4=__&15,O=1,_ ()|O ++&_(),__=Q8 ,O0=Q7 ),Q3=( _Q+= O8*(9 *O4* O1 > lrand48()) +(_O%=8,( (_O% 6>2) -(_O% 7<2) )*QQ+((_O +7)%8<3 )-(_O>4) )*( C>5 ), Q2 = _Q/ O3)* O6+Q5 +(O2=_Q%QQ )/ 2,*Q3=* Q3 % O4+O4|(1 << Q_("" "@CADBEHI") [_Q%2+_Q %O3/ QQ*2 ]- 64)* _0, sprintf(O5, Q9, Q2+1, O2/2 ,*Q3>>8 ,85* 3&* Q3,Q2+1 )&& _0&&(O=8, Q1 = O5,_()), Q0 +=(O2 >Q0)*_0*(O2 -Q0 ),__ +=!( C>9)*(3- __+ ( __>>4))-3, __ +=(C>12 ) *( (__<<4 )+ C-3-__) ,usleep( O4* _0/(3* O8+1 )),O =3,_() )) ,!O9 --&& read( 1 ,& OO,1)> 0&&(O= (QO=OO ==35 )*3+6 ,_() ,QO&&(OO=10,O=6,_(),1)||(O=4,_()),0)||close(dup2(3-dup2(1,dup(0)-3),1) *0+2)*0||Q write(1,"> ",2),ioctl(Q0=0,TIOCGWINSZ,O5)^--O&(O3=(QQ=(O6=* ((short*)O5+1))*2)*4),Q6=-O1,Q5=calloc(3*O6,8),_()),Q (O=8,QO=!(O2=OO- 10)|!(Q2=OO-32)*(Q0+58>QQ)|(Q0+12>QQ))&&(Q1=O_(3B),_(),write(1,"> ",2) ),Q0+=!QO*!Q2*4-QO*Q0,O2*Q2&&(!Q0&&(memset(Q5,0,3*O3),Q0=4,Q1="nnn" O_(3A),_()),O=7,_Q=7*QQ+Q0+2,_O=_0=0,OO+=(OO>64 &OO<91)*32,O0=Q_(O_o)+ O7,_(),(*O0-OO)||(O=2,O0+='a',_( )))),Q *O0-OO)&&(*(O0+=O1)-33)&&(O=0, _(),O=7,O0+=O1,_()),Q write(0,Q1,strlen(Q1))),Q OO=Q_(O_o)[Q6+=O1],(Q6 %strlen(O_o)-O7)&&(O=6,_(),O=9,_()));Q_(})/*+++++ IOCCC 2015 +++++*/ main() { puts("hello world!"); } Etienne Duble etienne.duble@imag.fr The International Obfuscated C Code Contest
  • 12.
    Code#/* q{G. */include<stdio.h> /*G!*/ #define G(g,o)/**/intg=o;/**/ #define q(b)int o[]={0,0,0,0, 0};char*p=#b,P[9999],*d=P,*e[]={"('A`)" ,"(A`)","('A)","('A`)"},b/*3792/e887094c*/ q(*s=__TIME__;extern void w(){G(g,*o)for(;g-- ;);}extern void x(){}extern void y(){}static void z (char*p){for(;(*d=*p++)!=0;d++)*d-=061*(59==*d||*d==81);}int main(){char N[]="<;iQ=/*do<;dQ=ook8?boc;aQ=odr8>oc;_Q<ox8>oc" ";^Q<d|8=o;]Q<dj8<Pk8<c]'?;QQdi8?P'Q)d8<9`8?c;Qdh8=P']Q<`c8>PQ9_8" ">b;og8=''`Q<`b8?'QQ9_8?c;dPe8dQa8<P]Q<``8=;'f8>QQ`]8?ocQQ_8=''_Q`8aQ" "CYOUQWIN!]Q=;of8BQQ)88bc]QA98P'Qo]8>oQQ_8CP;QQ98b`_8@P8(Q`]'^Q=`']QB)88" "bQQ]`8J;QQ`88bc99bd(`8iQ@''QQo^8E'`8c;QQ'Q``8?QQ`'kQ<o]8B9PQQ`';_Q<`_8<cbQ" "<o_Q<o_QBdo`QQ';`Q=9`]8=bobQ_o_Q<o]8=';bQC(88cQ`bcgQ>oP']8<;cQ>98)^Q?''oc`Q>" "oc']Q]8<;cQ>`8bbQA``QQ''`Q?88P;dQ=`)nQ?*/;;"/*}}=~/./;print"cp40sinon.c40r", "un.cn";for($i=1;$i<21;$i++){for($j=0;$j<2;$j++){print"gccx20-O",$j*2, "40run.cx20-o run&&./run|tee run.cn"if!($i%(2+$j));}print"sleep $jn"; } __DATA__ 8M*/;G(Z,60*(60*(10**s+s[1])+s[3]*10+s[4])+s[6]*10+s[7]-1933008 )G(l,(Z+86400-*o)%86400)G(M,o[3] *17+o[4]*11) G(O,(&x-&w)-(&y-&x)?1:0)G( m,*o)G(n,m)G(i,0)G(j,O)if(M>197)for( p=N;*p; )if(*p>92){*N=p[1 ];N[1] =0;for( O=*p++-90;0<O--;z( N));p++;}else{ s= p;for(O= *p++-59;O--;p++) p[-1]=*p;p[-1]=0;z(s);}else{ if(M==0){*o=Z;l=0; }if(o[O+3]&&o[ O+1]+(O?3:5 )>l)Z=O;else++o[O+3];o[O+1] =l; if(l<60)d+= sprintf(d,"#include<stdio.h>" "12#define G(g,o) int g=o;n#d" "efine 161(b" ")int40o[]={%d,%d,%d,%d,%d};char" "*p=#b,P[9999],*d=P,*e[]=" "{"%s", "" "%s" "","%s","%s"}, bnq(%s)n" ,*o,o[01],o[2],o[3], o[4] ,e[3],e[1], e[2],*e,p);z("/*;; ");for(i=0; i++<18 ;z(";"))for(j=0;j++<11;n=(n*193+287) %384 ){m=(97+(67*m ))%198;for (O=0;O++<n%03;z("Q") );s=d;for(z(e[ ( n/3)&3]);m<M &&s-d;*s++ =040);}if(l<60) {for (z(";Time:Q") ;(l++<60);z ("#"));for (z(";Heca"/* */ "t" "eQII:" "Q") ;o[3 ]++ <=24;z("#"));z (Z?"":"Q(j" "a" "m" "me" /* @ */"d" ")");for(z( ";GlockQ18" "C:" /* * */ "Q");o[4]++< 25;z("#") );z( Z- 1? ";":"Q(jam" "med);") /* */ ;} else z(";" ";Gam" /* */ "eQover." ";;" /* (- */);for (O= 0;O <77;O ++) z("Q");z( "*" "" "/" );} puts (P);; return+0;}) Don Yang omoikane@uguu.org The International Obfuscated C Code Contest
  • 13.
  • 14.
    Theoretical vs Practical Numberof ideas it is possible to express Vs The ease at which we can express ideas
  • 15.
    Theoretical vs Practical SELECTMAX(Price) AS LargestPrice FROM Products;
  • 16.
  • 17.
    Statically Typed • CompileTime Error Checking • Type Inference • Const / Immutability • Non-nullable Types • Null Access Operations Extensions Coroutines / async await Expressive Data Structures Destructuring Operator Overloading Pattern Matching OO Programming • Properties • Reified Generics • Primary Constructors • Initialisers • Indexers Functional Programming • Lambdas / Closures • Local Functions • Expression Functions Aspect Oriented Programming Modularity Multi-platform Features that help me be Expressive in Code
  • 18.
    Static types simplymakes writing large amounts of code easier Compile Time Error Checking Better support within IDEs A side benefit is it leads to faster code (if compiled) Static Typing
  • 19.
    Dynamic Languages envythis capability JavaScript limitations led to the development of Flow • Developed by Facebook and first released in 2014 • Add static typing and analysis to JavaScript They market it as allowing you to, • Code Faster – find bugs as you code • Code Smarter – IDE understands your intent • Code Confidently • Code Bigger Static Typing
  • 20.
  • 21.
    Python added typeannotations in version 3.5 Static Typing def scale(scalar: float, vector: Vector) -> Vector: return ... def scale(scalar, vector): return ...
  • 22.
    Type inference isa must for me Explicitly defining types when obvious, • Makes code unnecessarily verbose • Makes refactoring commits noisier • Exposes details that are often unimportant Compare Java 9 and Kotlin • Java finally got local type inference in v10 Static Typing – Not More Typing
  • 23.
    Type Inference –Java vs Kotlin private static boolean isEven(int i) { return i % 2 == 0; } public static void main(String[] args) { int[] numbers = {1, 2, 3, 4, 5 }; List<Integer> evensList = new ArrayList<Integer>(); for (int i: numbers) { if (isEven(i)) { evensList.add(i); } } } private fun isEven(i: Int) = i % 2 == 0 fun main(args: Array<String>) { val numbers = intArrayOf(1, 2, 3, 4, 5) val evensList = ArrayList<Int>() for (i in array) { if (isEven(i)) { evensList.add(i) } } } Java Kotlin
  • 24.
    Type Inference –Java vs Kotlin private static final double DISCOUNT = 0.1; private static void applyDiscount(User user) { Cart cart = user.getCart(); Iterable<CartItem> items = cart.getItems(); double total = sumCartItems(items); double discount = total * DISCOUNT; cart.applyDiscount(discount); } private const val DISCOUNT = 0.1 private fun applyDiscount(user: User) { val cart = user.cart val items = cart.items val total = sumCartItems(items) val discount = total * DISCOUNT cart.applyDiscount(discount) } Java Kotlin
  • 25.
    With Type Inference- Good Naming is Even More Important
  • 26.
    Many modern languageshave the concept of non-nullable types This removes a whole class of error Const, Non-nullable and Value Types
  • 27.
    Const, Non-nullables andValue Types private fun processUserPolicy(user: User) { val policy = user.policy if (policy.isComplete) { policyProcessor.process(policy) } } private static void processUserPolicy(User user) { if (user != null && user.getPolicy() != null) { Policy policy = user.getPolicy(); if (policy.isComplete()) { policyProcessor.process(policy); } } } Java Kotlin
  • 28.
    Object Oriented programmingis a great way of modelling many problems We want languages which offer succinct ways of implement classes • Access modifiers (private, public, protected etc) • Properties – get and/or set • Primary Constructors • Data Classes OO Programming
  • 29.
    Basic Model Classes– Java public class Movie { private String title; private String description; private Rating rating; private Genre genre; }
  • 30.
    Basic Model Classes– Java public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } }
  • 31.
    Basic Model Classes– Java public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; }
  • 32.
    Basic Model Classes– Java public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Rating getRating() { return rating; } public void setRating(Rating rating) { this.rating = rating; } public Genre getGenre() { return genre; } public void setGenre(Genre genre) { this.genre = genre; } }
  • 33.
    Basic Model Classes– Java vs C# public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Rating getRating() { return rating; } public void setRating(Rating rating) { this.rating = rating; } public Genre getGenre() { return genre; } public void setGenre(Genre genre) { this.genre = genre; } } public class Movie { public string Title { get; set; } public string Description { get; set; } public Rating Rating { get; set; } public Genre Genre { get; set; } public Movie(string title, string description, Rating rating, Genre genre) { Title = title; Description = description; Rating = rating; Genre = genre; } } Java C#
  • 34.
    Basic Model Classes– Java vs Swift public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Rating getRating() { return rating; } public void setRating(Rating rating) { this.rating = rating; } public Genre getGenre() { return genre; } public void setGenre(Genre genre) { this.genre = genre; } } Java Swift
  • 35.
    Basic Model Classes– Java vs Kotlin public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Rating getRating() { return rating; } public void setRating(Rating rating) { this.rating = rating; } public Genre getGenre() { return genre; } public void setGenre(Genre genre) { this.genre = genre; } } data class Movie(var title: String, var description: String, var rating: Rating, var genre: Genre) { } Java Kotlin
  • 36.
    Basic Model Classes– Java vs Kotlin import java.util.Objects; public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Rating getRating() { return rating; } public void setRating(Rating rating) { this.rating = rating; } public Genre getGenre() { return genre; } public void setGenre(Genre genre) { this.genre = genre; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Movie movie = (Movie) o; return Objects.equals(title, movie.title) && Objects.equals(description, movie.description) && Objects.equals(rating, movie.rating) && Objects.equals(genre, movie.genre); } @Override public int hashCode() { return Objects.hash(title, description, rating, genre); } @Override public String toString() { return "Movie{" + "title='" + title + ''' + ", description='" + description + ''' + ", rating=" + rating + ", genre=" + genre + '}'; } } data class Movie(var title: String, var description: String, var rating: Rating, var genre: Genre) { } We also get hashCode(), equals(), toString() and more… External libraries and tools like Lombok will help with Java Java Kotlin
  • 37.
    Functional Programming alsohelps us solves lots of problems Many languages now support this • Functions as first class citizens • Higher order functions – functions as arguments and return • Inline functions and lambdas • Closures Java gained many of these features in Java 8 Blending OO and FP allows us to write elegant code • Many modern language provide both Functional Programming
  • 38.
    Functional Chaining –C# vs Java Reified Generics with support for primitives makes the code simpler double averageSalary = employees .stream() .filter(x -> x.getDepartment() == Engineering) .mapToInt(Employee::getSalary) .average() .orElse(0); Java var averageSalary = employees .Where(x => x.Department == Engineering) .Select(x => x.Salary) .Average(); C# val averageSalary = employees .filter { it.department === Engineering } .map { it.salary } .average() Kotlin Swift $0 $0
  • 39.
    Extensions also allowus write more expressive code • Extend existing (even built-in types) We can create Domain Specific Languages Functional Chaining val averageSalary = employees .filter { it.department === Engineering } .averageSalary()
  • 40.
    Extensions also allowus write more expressive code • Extend existing (even built-in types) We can create Domain Specific Languages Functional Chaining deviceStatusStream() .filterForErrors() .collate().and() .send()
  • 41.
    Most systems wewrite have asynchronous components Typically we can’t block due to limited resources We need ways to hide the complexity of async programming Asynchronous Programming
  • 42.
    Sequential Algorithm –Asynchronous Steps disableUI(); const exchangeRates = exchangeRateReader.read(); const report = reportBuilder.build(exchangeRates); reportSaver.save(report); enableUI();
  • 43.
    Early Solution –Callback Hell disableUI(); exchangeRateReader.onload = exchangeRates => { reportBuilder.onload = report => { reportSaver.onsave = () => { enableUI(); }; reportSaver.save(report); }; reportBuilder.build(exchangeRates); }; exchangeRateReader.read();
  • 44.
    Early Solution –Callback Hell disableUI(); exchangeRateReader.read(); exchangeRateReader.onload = exchangeRates => { reportBuilder.build(exchangeRates); }; reportBuilder.onload = report => { reportSaver.save(report); }; reportSaver.onsave = () => { enableUI(); };
  • 45.
    Promises and Futuresand Tasks...oh my disableUI(); exchangeRateReader.read() .then(exchangeRates => reportBuilder.build(exchangeRates)) .then(report => reportSaver.save(report) .then(enableUI);
  • 46.
    Async Await disableUI(); const exchangeRates= await exchangeRateReader.read(); const report = await reportBuilder.build(exchangeRates); await reportSaver.save(report); enableUI(); disableUI(); const exchangeRates = exchangeRateReader.read(); const report = reportBuilder.build(exchangeRates); reportSaver.save(report); enableUI();
  • 47.
    Coroutines - Kotlin disableUI(); valexchangeRates = exchangeRateReader.read().await(); val report = reportBuilder.build(exchangeRates).await(); reportSaver.save(report).await(); enableUI();
  • 48.
  • 49.
    Every Language isLeap Frogging the Others – Why?
  • 50.
    Waste Yeah!!!! We get todo another port of the library  •Java: RxJava •JavaScript: RxJS •C#: Rx.NET •C#(Unity): UniRx •Scala: RxScala •Clojure: RxClojure •C++: RxCpp •Lua: RxLua •Ruby: Rx.rb •Python: RxPY •Go: RxGo •Groovy: RxGroovy •JRuby: RxJRuby •Kotlin: RxKotlin •Swift: RxSwift •PHP: RxPHP •Elixir: reaxive •Dart: RxDart RxNetty RxAndroid RxCocoa
  • 51.
    We still seeprogress reinventing the wheel
  • 52.
    Real-world constraints • Legacycode – lock in, interop, re-use • Existing team skills • Domain specific considerations Tooling • IDE with Navigation, Refactoring etc Test Frameworks and Tools Active Community Large open source library repository Excellent documentation What else do I consider?
  • 53.
    Think carefully aboutthe languages you choose • If you’re in the JavaScript space, consider TypeScript • If you’re in the Java space, consider Kotlin (a lot!) • If you’re in the Objective C space, consider Swift • If you’re in the C++ space, use C++17 • If you’re in C#, keep on truckin’ Consider how familiar you are with the languages you’ve got Keep up to date with small upgrades • Don’t wait until it’s too late Refactor your code mercilessly Summary
  • 54.