D lang
Upcoming SlideShare
Loading in...5
×
 

D lang

on

  • 586 views

Why to use D programming?

Why to use D programming?

Statistics

Views

Total Views
586
Views on SlideShare
584
Embed Views
2

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 2

https://twitter.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

D lang D lang Presentation Transcript

  • .. .......... ...... ..................... ..................... ..................... ..... ..... . ..... .......... .
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . . Walter Bright .. ...... If a language can capture 90% of the power of C++ with 10% of its complexity I argue that is a worthwhile tradeoff. Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 2 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Factorial number: C++ vs D Imperative .. 1 typedef unsigned long ulong; 2 3 ulong factorial (ulong n){ 4 if (n < 2) 5 return 1; 6 else 7 return n ∗ factorial (n − 1); 8 } .. 1 ulong factorial (ulong n){ 2 if (n < 2) 3 return 1; 4 else 5 return n ∗ factorial (n − 1); 6 } Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 3 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Factorial number: C++ vs D Imperative and generics .. 1 template<class T> T factorial(T n){ 2 if (n < 2) 3 return 1; 4 else 5 return n ∗ factorial (n − 1); 6 } .. 1 T factorial (T n){ 2 if (n < 2) 3 return 1; 4 else 5 return n ∗ factorial (n − 1); 6 } Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 4 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Factorial number: C++ vs D Imperative, generics and contract .. 1 template<class T> T factorial(T n){ 2 assert ( n >= 1 ); 3 if (n < 2) 4 return 1; 5 else 6 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 else 8 return n ∗ factorial (n − 1); 9 } Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 5 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Factorial number: C++ vs D Meta-programing .. 1 typedef unsigned long ulong; 2 3 template <ulong N> struct Factorial { 4 enum { value = N ∗ Factorial<N − 1>::value }; 5 }; 6 7 template <> struct Factorial<0> { 8 enum { value = 1 }; 9 }; 10 11 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 else 5 const Factorial = n ∗ Factorial !(n − 1); 6 } 7 8 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 D CTFE .. 1 typedef unsigned long ulong; 2 3 ulong factorial (ulong n){ 4 if (n < 2) 5 return 1; 6 else 7 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 else 5 return n ∗ factorial (n − 1); 6 } 7 8 enum ulong x = factorial ( 4 ); 9 enum ulong y = factorial ( 0 ); Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 7 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . . 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
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Factorial number: C++ vs D functional .. 1 typedef unsigned long ulong; 2 3 ulong factorial (ulong n){ 4 if (n < 2) 5 return 1; 6 else 7 return n ∗ factorial (n − 1); 8 } .. 1 @safe pure nothrow 2 ulong factorial (immutable ulong n){ 3 if (n < 2) 4 return 1; 5 else 6 return n ∗ factorial (n − 1); 7 } Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 9 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . .. Imperative. Generics . Contracts . Meta- programing . Functional . . . . . . . . . . . . . . . . . . . . . . . . . C++ D Python Java Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 10 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Do you like it ? .. .Yes .. .No Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 11 / 21
  • .. .. .continue .......... ...... ..................... ..................... ..................... ..... ..... . ..... .......... .
  • .. .......... ...... ..................... ..................... ..................... ..... ..... . ..... .......... .
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Factorial number: Java vs D A language survey .. 1 public class Factorial { 2 public static int factorial ( int n ){ 3 if (n < 2) 4 return 1; 5 else 6 return n ∗ Factorial . factorial (n − 1); 7 } 8 } .. 1 pure ulong factorial ( immutable ulong n){ 2 if (n < 2) 3 return 1; 4 else 5 return n ∗ factorial (n − 1); 6 } Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 14 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Factorial number: Python vs D A language survey .. 1 def factorial ( n ): 2 if n < 2: 3 return 1 4 else : 5 return n ∗ factorial (n − 1) .. 1 pure ulong factorial ( immutable ulong n ){ 2 if (n < 2) 3 return 1; 4 else 5 return n ∗ factorial (n − 1); 6 } Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 15 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Computing Factorial 50, 1 million time ..... java . C++ . D . Python .0 . 2 . 4 . 6 . 8 . 10 . 0.167 . 0.003 . 0.014 . 11.399 Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 16 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Computing Factorial 50, 20 millions times ..... java . C++ . D . Python .0 . 50 . 100 . 150 . 200 . 1.692 . 0.002 . 0.006 . 228.815 Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 17 / 21
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . Do you like it ? .. .Yes .. .No Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 18 / 21
  • .. .. .continue .......... ...... ..................... ..................... ..................... ..... ..... . ..... .......... .
  • .. .......... ...... ..................... ..................... ..................... ..... ..... . ..... .......... .
  • .. ..... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . .... . .... . ..... . .... . ..... . .... . .... . . Andrei Alexandrescu .. ......D rox !!! Thanks Jonathan MERCIER aka bioinfornatics D Programing October 9, 2013 21 / 21