D lang

21
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Transcript of D lang

.. ..... ..... ..... . ..................... ..................... ..................... ..... ..... . ..... ..... ..... ..

..

..20

13-1

0-09

D Programing

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.Walter Bright..

......

If a language can capture 90% of the power of C++with 10% of its complexityI argue that is a worthwhile tradeoff.

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 2 / 21 .

..

.Walter Bright..

......

If a language can capture 90% of the power of C++with 10% of its complexityI argue that is a worthwhile tradeoff.

..20

13-1

0-09

D Programing

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Factorial number: C++ vs DImperative

..

1 typedef unsigned long ulong;23 ulong factorial (ulong n){4 if (n < 2)5 return 1;6 else7 return n ∗ factorial (n − 1);8 } ..

1 ulong factorial (ulong n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 3 / 21 .

..

Factorial number: C++ vs DImperative

..

1 typedef unsigned long ulong;23 ulong factorial (ulong n){4 if (n < 2)5 return 1;6 else7 return n ∗ factorial (n − 1);8 } ..

1 ulong factorial (ulong n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

..20

13-1

0-09

D Programing

Factorial number: C++ vs D

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Factorial number: C++ vs DImperative and generics

..

1 template<class T> T factorial(T n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

..

1 T factorial (T n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 4 / 21 .

..

Factorial number: C++ vs DImperative and generics

..

1 template<class T> T factorial(T n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

..

1 T factorial (T n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

..20

13-1

0-09

D Programing

Factorial number: C++ vs D

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Factorial number: C++ vs DImperative, generics and contract

..

1 template<class T> T factorial(T n){2 assert ( n >= 1 );3 if (n < 2)4 return 1;5 else6 return n ∗ factorial (n − 1);7 }

..

1 T factorial (T n)2 in{ assert ( n >= 1 ); }3 out{ assert ( n >= 1 ); }4 body{5 if (n < 2)6 return 1;7 else8 return n ∗ factorial (n − 1);9 }

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 5 / 21 .

..

Factorial number: C++ vs DImperative, generics and contract

..

1 template<class T> T factorial(T n){2 assert ( n >= 1 );3 if (n < 2)4 return 1;5 else6 return n ∗ factorial (n − 1);7 }

..

1 T factorial (T n)2 in{ assert ( n >= 1 ); }3 out{ assert ( n >= 1 ); }4 body{5 if (n < 2)6 return 1;7 else8 return n ∗ factorial (n − 1);9 }

..20

13-1

0-09

D Programing

Factorial number: C++ vs D

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Factorial number: C++ vs DMeta-programing

..

1 typedef unsigned long ulong;23 template <ulong N> struct Factorial {4 enum { value = N ∗ Factorial<N − 1>::value };5 };67 template <> struct Factorial<0> {8 enum { value = 1 };9 };

1011 const ulong x = Factorial<4>::value;12 const ulong y = Factorial<0>::value;

..

1 template Factorial (ulong n){2 static if (n < 2)3 const Factorial = 1;4 else5 const Factorial = n ∗ Factorial !(n − 1);6 }78 immutable ulong x = Factorial !( 4 ) ;9 immutable ulong y = Factorial !( 0 ) ;

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 6 / 21 .

..

Factorial number: C++ vs DMeta-programing

..

1 typedef unsigned long ulong;23 template <ulong N> struct Factorial {4 enum { value = N ∗ Factorial<N − 1>::value };5 };67 template <> struct Factorial<0> {8 enum { value = 1 };9 };

1011 const ulong x = Factorial<4>::value;12 const ulong y = Factorial<0>::value;

..

1 template Factorial (ulong n){2 static if (n < 2)3 const Factorial = 1;4 else5 const Factorial = n ∗ Factorial !(n − 1);6 }78 immutable ulong x = Factorial !( 4 ) ;9 immutable ulong y = Factorial !( 0 ) ;

..20

13-1

0-09

D Programing

Factorial number: C++ vs D

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Factorial number: C++ vs DCTFE

..

1 typedef unsigned long ulong;23 ulong factorial (ulong n){4 if (n < 2)5 return 1;6 else7 return n ∗ factorial (n − 1);8 }9

10 enum ulong x = factorial ( 4 );11 enum ulong y = factorial ( 0 ); ..

1 ulong factorial (ulong n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }78 enum ulong x = factorial ( 4 ) ;9 enum ulong y = factorial ( 0 ) ;

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 7 / 21 .

..

Factorial number: C++ vs DCTFE

..

1 typedef unsigned long ulong;23 ulong factorial (ulong n){4 if (n < 2)5 return 1;6 else7 return n ∗ factorial (n − 1);8 }9

10 enum ulong x = factorial ( 4 );11 enum ulong y = factorial ( 0 ); ..

1 ulong factorial (ulong n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }78 enum ulong x = factorial ( 4 ) ;9 enum ulong y = factorial ( 0 ) ;

..20

13-1

0-09

D Programing

Factorial number: C++ vs D

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.John Carmack..

......Using D for my daily work is not an option,but I applaud their inclusion of a pure attribute.

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 8 / 21 .

..

.John Carmack..

......Using D for my daily work is not an option,but I applaud their inclusion of a pure attribute.

..20

13-1

0-09

D Programing

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Factorial number: C++ vs Dfunctional

..

1 typedef unsigned long ulong;23 ulong factorial (ulong n){4 if (n < 2)5 return 1;6 else7 return n ∗ factorial (n − 1);8 } ..

1 @safe pure nothrow2 ulong factorial (immutable ulong n){3 if (n < 2)4 return 1;5 else6 return n ∗ factorial (n − 1);7 }

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 9 / 21 .

..

Factorial number: C++ vs Dfunctional

..

1 typedef unsigned long ulong;23 ulong factorial (ulong n){4 if (n < 2)5 return 1;6 else7 return n ∗ factorial (n − 1);8 } ..

1 @safe pure nothrow2 ulong factorial (immutable ulong n){3 if (n < 2)4 return 1;5 else6 return n ∗ factorial (n − 1);7 }

..20

13-1

0-09

D Programing

Factorial number: C++ vs D

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Imperative.

Generics

.

Contracts

.

Meta-programing

.

Functional

..

.

.

.

.

..

.

.

.

.

..

.

.

.

.

..

.

.

.

.

.

C++DPythonJava

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 10 / 21 .

..

.. Imperative.

Generics

.

Contracts

.

Meta-programing

.

Functional

..

.

.

.

.

..

.

.

.

.

..

.

.

.

.

..

.

.

.

.

.

C++DPythonJava

..20

13-1

0-09

D Programing

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Do you like it ?

... Yes ... No

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 11 / 21 .

..

Do you like it ?

... Yes ... No

..20

13-1

0-09

D Programing

..... continue

..... ..... ..... . ..................... ..................... ..................... ..... ..... . ..... ..... ..... ..

.. ... continue

..20

13-1

0-09

D Programing

.. ..... ..... ..... . ..................... ..................... ..................... ..... ..... . ..... ..... ..... ..

..

..20

13-1

0-09

D Programing

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Factorial number: Java vs DA language survey

..

1 public class Factorial {2 public static int factorial ( int n ){3 if (n < 2)4 return 1;5 else6 return n ∗ Factorial . factorial (n − 1);7 }8 } ..

1 pure ulong factorial ( immutable ulong n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 14 / 21 .

..

Factorial number: Java vs DA language survey

..

1 public class Factorial {2 public static int factorial ( int n ){3 if (n < 2)4 return 1;5 else6 return n ∗ Factorial . factorial (n − 1);7 }8 } ..

1 pure ulong factorial ( immutable ulong n){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

..20

13-1

0-09

D Programing

Factorial number: Java vs D

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Factorial number: Python vs DA language survey

..

1 def factorial ( n ):2 if n < 2:3 return 14 else :5 return n ∗ factorial (n − 1)

..

1 pure ulong factorial ( immutable ulong n ){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 15 / 21 .

..

Factorial number: Python vs DA language survey

..

1 def factorial ( n ):2 if n < 2:3 return 14 else :5 return n ∗ factorial (n − 1)

..

1 pure ulong factorial ( immutable ulong n ){2 if (n < 2)3 return 1;4 else5 return n ∗ factorial (n − 1);6 }

..20

13-1

0-09

D Programing

Factorial number: Python vs D

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Computing Factorial 50, 1 million time

.....java

.C++

.D

.Python

.0 .

2

.

4

.

6

.

8

.

10

. 0.167

. 0.003

. 0.014

.

11.39

9

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 16 / 21 .

..

Computing Factorial 50, 1 million time

.....java

.C++

.D

.Python

.0 .

2

.

4

.

6

.

8

.

10

. 0.167

. 0.003

. 0.014

.

11.39

9

..20

13-1

0-09

D Programing

Computing Factorial 50, 1 million time

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Computing Factorial 50, 20 millions times

.....java

.C++

.D

.Python

.0 .

50

.

100

.

150

.

200

. 1.692

. 0.002

. 0.006

.

228.8

15

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 17 / 21 .

..

Computing Factorial 50, 20 millions times

.....java

.C++

.D

.Python

.0 .

50

.

100

.

150

.

200

. 1.692

. 0.002

. 0.006

.

228.8

15

..20

13-1

0-09

D Programing

Computing Factorial 50, 20 millions times

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Do you like it ?

... Yes ... No

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 18 / 21 .

..

Do you like it ?

... Yes ... No

..20

13-1

0-09

D Programing

..... continue

..... ..... ..... . ..................... ..................... ..................... ..... ..... . ..... ..... ..... ..

.. ... continue

..20

13-1

0-09

D Programing

.. ..... ..... ..... . ..................... ..................... ..................... ..... ..... . ..... ..... ..... ..

..

..20

13-1

0-09

D Programing

.......

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.Andrei Alexandrescu..

......D rox !!!

Thanks

Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 21 / 21 .

..

.Andrei Alexandrescu..

......D rox !!!

Thanks

..20

13-1

0-09

D Programing