Your SlideShare is downloading. ×
Fudcon D programming
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Fudcon D programming

241
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
241
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. D Programming .Jonathan MERCIERIntroduction D ProgrammingObject . In nutshellFunctionalMeta-programmingParallelismRessource ManagementContract Jonathan MERCIERSystem and Safe CodeReference and pointerGenericsInferenceLoopsFunctions December 9, 2012DebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . 1/122 .Let start it! D Programming . . . . Forward .GTK D
  • 2. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . 2/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 3. D ProgrammingJonathan MERCIER Before startingIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . 3/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 4. D ProgrammingJonathan MERCIER Why a new language?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Few significant datesSystem and Safe Code .Reference and pointer C++ 1983GenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . 4/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 5. D ProgrammingJonathan MERCIER Why a new language?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Few significant datesSystem and Safe Code .Reference and pointer C++ 1983GenericsInferenceLoops Java 1990FunctionsDebugsVersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . 4/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 6. D ProgrammingJonathan MERCIER Why a new language?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Few significant datesSystem and Safe Code .Reference and pointer C++ 1983GenericsInferenceLoops Java 1990FunctionsDebugs Python 1995VersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . 4/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 7. D ProgrammingJonathan MERCIER Why a new language?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Few significant datesSystem and Safe Code .Reference and pointer C++ 1983GenericsInferenceLoops Java 1990FunctionsDebugs Python 1995VersionsRequirement Ruby 1995EditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . 4/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 8. D ProgrammingJonathan MERCIER Why a new language?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Few significant datesSystem and Safe Code .Reference and pointer C++ 1983GenericsInferenceLoops Java 1990FunctionsDebugs Python 1995VersionsRequirement Ruby 1995 And now?EditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . 4/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 9. D ProgrammingJonathan MERCIER What is D programming?IntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code D is a modern language programming inspired by:Reference and pointerGenerics C++InferenceLoops JavaFunctionsDebugs HaskellVersionsRequirement PythonEditorsBasics RubyMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . 5/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 10. D ProgrammingJonathan MERCIER Why a new language?IntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code .Reference and pointer D CombinesGenerics .Inference Modeling PowerLoopsFunctionsDebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 6/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 11. D ProgrammingJonathan MERCIER Why a new language?IntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code .Reference and pointer D CombinesGenerics .Inference Modeling PowerLoopsFunctionsDebugs Modern ConvenienceVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 6/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 12. D ProgrammingJonathan MERCIER Why a new language?IntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code .Reference and pointer D CombinesGenerics .Inference Modeling PowerLoopsFunctionsDebugs Modern ConvenienceVersions Native Efficiency .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 6/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 13. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . 7/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 14. D ProgrammingJonathan MERCIER ObjectIntroductionObjectFunctionalMeta-programming .ParallelismRessource Management InterfaceContract 1 interface foo { …}System and Safe Code .Reference and pointerGenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 8/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 15. D ProgrammingJonathan MERCIER ObjectIntroductionObjectFunctionalMeta-programming .ParallelismRessource Management InterfaceContract 1 interface foo { …}System and Safe Code .Reference and pointerGenerics classInferenceLoops 1 class bar { …}Functions .DebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 8/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 16. D ProgrammingJonathan MERCIER ObjectIntroductionObjectFunctionalMeta-programming .ParallelismRessource Management InterfaceContract 1 interface foo { …}System and Safe Code .Reference and pointerGenerics classInferenceLoops 1 class bar { …}Functions .DebugsVersions inheritanceRequirement 1 class bar: foo { …}Editors .BasicsMy first D programTypesArraysString and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 8/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 17. D ProgrammingJonathan MERCIER ObjectIntroductionObjectFunctionalMeta-programming .ParallelismRessource Management InterfaceContract 1 interface foo { …}System and Safe Code .Reference and pointerGenerics classInferenceLoops 1 class bar { …}Functions .DebugsVersions inheritanceRequirement 1 class bar: foo { …}Editors .BasicsMy first D program multi class inheritance not allowed, instead usedTypesArrays interface.String and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 8/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 18. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . 9/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 19. D ProgrammingJonathan MERCIER FunctionalIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Data immutabilitySystem and Safe CodeReference and pointer 1 immutable int[] a = [ 4, 6, 1, 2];Generics .InferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypes .ArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 10/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 20. D ProgrammingJonathan MERCIER FunctionalIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Data immutabilitySystem and Safe CodeReference and pointer 1 immutable int[] a = [ 4, 6, 1, 2];Generics .InferenceLoops Pure functionsFunctions 1 pure int square(int x) { return x * x; }DebugsVersions .RequirementEditorsBasicsMy first D programTypes .ArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 10/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 21. D ProgrammingJonathan MERCIER FunctionalIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Data immutabilitySystem and Safe CodeReference and pointer 1 immutable int[] a = [ 4, 6, 1, 2];Generics .InferenceLoops Pure functionsFunctions 1 pure int square(int x) { return x * x; }DebugsVersions .RequirementEditors Lambda functions 1 a.sort!( (x,y) => x < y ); // [ 1, 2, 4, 6 ]Basics .My first D programTypes .ArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . 10/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 22. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . 11/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 23. D ProgrammingJonathan MERCIER Meta-programmingIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract .System and Safe Code Combination ofReference and pointer .Generics templatesInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . 12/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 24. D ProgrammingJonathan MERCIER Meta-programmingIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract .System and Safe Code Combination ofReference and pointer .Generics templatesInferenceLoopsFunctions compile time function executionDebugsVersionsRequirementEditorsBasics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . 12/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 25. D ProgrammingJonathan MERCIER Meta-programmingIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract .System and Safe Code Combination ofReference and pointer .Generics templatesInferenceLoopsFunctions compile time function executionDebugsVersions tuplesRequirementEditorsBasics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . 12/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 26. D ProgrammingJonathan MERCIER Meta-programmingIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract .System and Safe Code Combination ofReference and pointer .Generics templatesInferenceLoopsFunctions compile time function executionDebugsVersions tuplesRequirementEditors string mixinsBasics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . 12/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 27. D ProgrammingJonathan MERCIER Meta-programmingIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer Code 1: ExampleGenerics 1 template Factorial(ulong n){Inference 2 static if(n < 2)Loops 3 const Factorial = 1;Functions 4 elseDebugs 5 const Factorial = n * Factorial!(n − 1);Versions 6 }Requirement 7 const ulong var = Factorial!( 8 ); // compute at compile−timeEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . 13/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 28. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . 14/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 29. D ProgrammingJonathan MERCIER ParallelismIntroductionObjectFunctionalMeta-programming .ParallelismRessource Management module to useContract 1 import std.parallelism;System and Safe Code .Reference and pointerGenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . .. . 15/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 30. D ProgrammingJonathan MERCIER ParallelismIntroductionObjectFunctionalMeta-programming .ParallelismRessource Management module to useContract 1 import std.parallelism;System and Safe Code .Reference and pointerGenerics parallel loopInferenceLoops 1 foreach( i; parallel( list ) ){ …}Functions .DebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . .. . 15/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 31. D ProgrammingJonathan MERCIER ParallelismIntroductionObjectFunctionalMeta-programming .ParallelismRessource Management module to useContract 1 import std.parallelism;System and Safe Code .Reference and pointerGenerics parallel loopInferenceLoops 1 foreach( i; parallel( list ) ){ …}Functions .DebugsVersionsRequirement Pool threadEditors 1 void myfunction( int param1, int param 2 ){ …} 2 auto myTask = task!myfunction( param1, param2 );Basics 3 taskPool.put( myTask );My first D program 4 doSomething(); // another work in parallelTypes 5 taskPool.finish( true ); // wait alls jobs endingArrays .String and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . .. . 15/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 32. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . 16/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 33. D ProgrammingJonathan MERCIER Ressource ManagementIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer Code 2: ExampleGenericsInference 1 File f = File( ”myfile.txt”, ”r”);Loops 2 scope(exit) f.close(); 3 lockFile( f );Functions 4 doFoo( f );Debugs 5 scope(success) doBar( f );Versions 6 scope(failure) unlock( f );RequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . 17/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 34. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . 18/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 35. D ProgrammingJonathan MERCIER ContractIntroductionObject .Functional check a statementMeta-programming 1 assert( var != null );ParallelismRessource Management .ContractSystem and Safe CodeReference and pointerGenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and Class .TemplateMiscellanous . . . . . . . 19/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 36. D ProgrammingJonathan MERCIER ContractIntroductionObject .Functional check a statementMeta-programming 1 assert( var != null );ParallelismRessource Management .ContractSystem and Safe Code check before entering into a functionReference and pointer 1 double foo ( int a )Generics 2 in{ assert( a > 0 ); }Inference 3 body { return a − 2; }LoopsFunctions .DebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and Class .TemplateMiscellanous . . . . . . . 19/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 37. D ProgrammingJonathan MERCIER ContractIntroductionObject .Functional check a statementMeta-programming 1 assert( var != null );ParallelismRessource Management .ContractSystem and Safe Code check before entering into a functionReference and pointer 1 double foo ( int a )Generics 2 in{ assert( a > 0 ); }Inference 3 body { return a − 2; }LoopsFunctions .DebugsVersions check at function exitRequirement 1 int foo ( int a )Editors 2 out{ assert( a > 0 ); } 3 body { return a − 2; }BasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and Class .TemplateMiscellanous . . . . . . . 19/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 38. D ProgrammingJonathan MERCIER ContractIntroductionObject .Functional check a statementMeta-programming 1 assert( var != null );ParallelismRessource Management .ContractSystem and Safe Code check before entering into a functionReference and pointer 1 double foo ( int a )Generics 2 in{ assert( a > 0 ); }Inference 3 body { return a − 2; }LoopsFunctions .DebugsVersions check at function exitRequirement 1 int foo ( int a )Editors 2 out{ assert( a > 0 ); } 3 body { return a − 2; }BasicsMy first D program . -release flag will not compute contractTypesArraysString and charactersConst and Immutable $ ldc2 -release foo.dInput/Output .AlgorithmStructure and Class .TemplateMiscellanous . . . . . . . 19/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 39. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . 20/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 40. D ProgrammingJonathan MERCIER System and Safe CodeIntroductionObjectFunctional .Meta-programming System and Safe CodeParallelism .Ressource ManagementContract Safe functions are functions that are statically checkedSystem and Safe CodeReference and pointer to have no possibility of undefined behavior.GenericsInferenceLoopsFunctionsDebugs Undefined behavior is often used as a vector forVersionsRequirement malicious attacks.EditorsBasicsMy first D programTypesArrays Func­tions are marked with at­tributes: @safe,String and charactersConst and Immutable @system, @trusted .Input/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . 21/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 41. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . 22/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 42. D ProgrammingJonathan MERCIER Reference and pointerIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Pointers exist only to create C interface codeSystem and Safe Code 1 int* a = cFunction( param );Reference and pointerGenerics .InferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypes .ArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . 23/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 43. D ProgrammingJonathan MERCIER Reference and pointerIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Pointers exist only to create C interface codeSystem and Safe Code 1 int* a = cFunction( param );Reference and pointerGenerics .InferenceLoops ref into functionFunctions 1 void foo( ref int[] param ) { …}DebugsVersions .RequirementEditorsBasicsMy first D programTypes .ArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . 23/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 44. D ProgrammingJonathan MERCIER Reference and pointerIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract Pointers exist only to create C interface codeSystem and Safe Code 1 int* a = cFunction( param );Reference and pointerGenerics .InferenceLoops ref into functionFunctions 1 void foo( ref int[] param ) { …}DebugsVersions .RequirementEditors ref into a loopBasics 1 foreach( ref item ; list ){ …} .My first D programTypes .ArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . 23/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 45. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . 24/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 46. D ProgrammingJonathan MERCIER . GenericIntroduction .Object classFunctional 1 class Foo( T ){ …}Meta-programming 2 Foo!int instance = new Foo!(int)( param );Parallelism .Ressource ManagementContractSystem and Safe CodeReference and pointerGenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/Output .AlgorithmStructure and ClassTemplateMiscellanous . . . . .. . . 25/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 47. D ProgrammingJonathan MERCIER . GenericIntroduction .Object classFunctional 1 class Foo( T ){ …}Meta-programming 2 Foo!int instance = new Foo!(int)( param );Parallelism .Ressource ManagementContractSystem and Safe Code structureReference and pointer 1 struct Foo( T ){ …}Generics 2 Foo!int instance = Foo!int( param );Inference .LoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/Output .AlgorithmStructure and ClassTemplateMiscellanous . . . . .. . . 25/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 48. D ProgrammingJonathan MERCIER . GenericIntroduction .Object classFunctional 1 class Foo( T ){ …}Meta-programming 2 Foo!int instance = new Foo!(int)( param );Parallelism .Ressource ManagementContractSystem and Safe Code structureReference and pointer 1 struct Foo( T ){ …}Generics 2 Foo!int instance = Foo!int( param );Inference .LoopsFunctions functionDebugs 1 T foo( T )(T param){ …}Versions 2 int var = foo!int( param );RequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/Output .AlgorithmStructure and ClassTemplateMiscellanous . . . . .. . . 25/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 49. D ProgrammingJonathan MERCIER . GenericIntroduction .Object classFunctional 1 class Foo( T ){ …}Meta-programming 2 Foo!int instance = new Foo!(int)( param );Parallelism .Ressource ManagementContractSystem and Safe Code structureReference and pointer 1 struct Foo( T ){ …}Generics 2 Foo!int instance = Foo!int( param );Inference .LoopsFunctions functionDebugs 1 T foo( T )(T param){ …}Versions 2 int var = foo!int( param );RequirementEditors .Basics macroMy first D program 1 template TFoo( T )( T param ){ immutable T f = param + 3;Types }Arrays 2 int a = TFoo!int( 4 ) ; // return 7 at compile timeString and characters .Const and ImmutableInput/Output .AlgorithmStructure and ClassTemplateMiscellanous . . . . .. . . 25/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 50. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . .. . . . 26/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 51. D ProgrammingJonathan MERCIER InferenceIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract .System and Safe CodeReference and pointer auto for variableGenerics 1 size_t[] list = [ 0, 1, 2, 3, 4];Inference 2 auto item = list[1]; // item type is size_tLoops .FunctionsDebugsVersionsRequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . 27/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 52. D ProgrammingJonathan MERCIER InferenceIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract .System and Safe CodeReference and pointer auto for variableGenerics 1 size_t[] list = [ 0, 1, 2, 3, 4];Inference 2 auto item = list[1]; // item type is size_tLoops .FunctionsDebugsVersions auto for functionRequirement 1 auto foo( int param ){ …}Editors . .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . 27/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 53. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . 28/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 54. D ProgrammingJonathan MERCIER LoopsIntroductionObject .Functional LoopsMeta-programming .Parallelism for loopRessource ManagementContract 1 for( int i = 0; i < 10; i++ ){ …}System and Safe Code .Reference and pointerGenerics while loopInferenceLoops 1 while( isComputing ){ …}Functions .DebugsVersionsRequirement do whileEditors 1 do{ …}while( isComputing ); .BasicsMy first D programTypes foreach loopArrays 1 foreach( size_t i; list ){ …}String and characters 2 foreach( size_t counter, size_t i = 0; list ){ …}Const and Immutable 3 foreach( counter, i; list ){ …}Input/Output .Algorithm .Structure and ClassTemplateMiscellanous . . . . . . . . . 29/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 55. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . 30/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 56. D ProgrammingJonathan MERCIER FunctionsIntroductionObjectFunctionalMeta-programming . FunctionsParallelismRessource Management .Contract classicalSystem and Safe Code 1 void foo( int param ){ …}Reference and pointerGenerics .InferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . 31/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 57. D ProgrammingJonathan MERCIER FunctionsIntroductionObjectFunctionalMeta-programming . FunctionsParallelismRessource Management .Contract classicalSystem and Safe Code 1 void foo( int param ){ …}Reference and pointerGenerics .InferenceLoops with default valuesFunctions 1 void foo( int param1, int param2 = 3 ){ …}Debugs .VersionsRequirementEditorsBasicsMy first D programTypesArraysString and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . 31/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 58. D ProgrammingJonathan MERCIER FunctionsIntroductionObjectFunctionalMeta-programming . FunctionsParallelismRessource Management .Contract classicalSystem and Safe Code 1 void foo( int param ){ …}Reference and pointerGenerics .InferenceLoops with default valuesFunctions 1 void foo( int param1, int param2 = 3 ){ …}Debugs .VersionsRequirementEditors with variadic parameters 1 void foo( int[] params ... ) {Basics 2 foreach( param; params )My first D program 3 …// do somethingTypes 4 }Arrays .String and characters .Const and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . 31/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 59. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . 32/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 60. D ProgrammingJonathan MERCIER DebugsIntroductionObject .Functional DebugsMeta-programming . debug blockParallelismRessource ManagementContract 1 debug( int param ){ …} // ldc2 −d−debug …. .System and Safe CodeReference and pointer .GenericsInference debug lineLoops 1 debug writeln( ”foo” ) ;FunctionsDebugs .VersionsRequirement unitestEditors 1 unitest { 2 assert( doFoo( x ), true );Basics 3 assert( doBar( x ), 3 );My first D program 4 …Types 5 }Arrays .String and charactersConst and Immutable .Input/OutputAlgorithm .Structure and ClassTemplateMiscellanous . . . . . . . . . . 33/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 61. D ProgrammingJonathan MERCIER DebugsIntroductionObject .Functional DebugsMeta-programming . debug blockParallelismRessource ManagementContract 1 debug( int param ){ …}System and Safe CodeReference and pointer .GenericsInference debug lineLoops 1 debug writeln( ”foo” ) ; // ldc2 −d−debug …. .FunctionsDebugs .VersionsRequirement unitestEditors 1 unitest { 2 assert( doFoo( x ), true );Basics 3 assert( doBar( x ), 3 );My first D program 4 …Types 5 }Arrays .String and charactersConst and Immutable .Input/OutputAlgorithm .Structure and ClassTemplateMiscellanous . . . . . .. . . . 34/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 62. D ProgrammingJonathan MERCIER DebugsIntroductionObject .Functional DebugsMeta-programming . debug blockParallelismRessource ManagementContract 1 debug( int param ){ …}System and Safe CodeReference and pointer .GenericsInference debug lineLoops 1 debug writeln( ”foo” ) ;FunctionsDebugs .VersionsRequirement unitestEditors 1 unitest { // ldc2 −unittest ….. 2 assert( doFoo( x ), true );Basics 3 assert( doBar( x ), 3 );My first D program 4 …Types 5 }Arrays .String and charactersConst and Immutable .Input/OutputAlgorithm .Structure and ClassTemplateMiscellanous . . . . . . . . . . 35/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 63. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . .. . . . . 36/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 64. D ProgrammingJonathan MERCIER VersionsIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code .Reference and pointer VersionsGenerics .Inference version conditional code block to useLoops 1 version( Windows ){ …}Functions 2 else version( linux ){ …}Debugs 3 else { pragma( msg, ”Unknown operating syystem” ); }Versions .RequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . 37/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 65. D ProgrammingJonathan MERCIER VersionsIntroductionObjectFunctional .Meta-programmingParallelism VersionsRessource ManagementContract .System and Safe Code own version identifierReference and pointer 1 version( FullApp ){ …}Generics 2 else version( DemoApp ){ …}Inference 3 else { version = DemoApp ); }LoopsFunctions .DebugsVersionsRequirementEditorsBasicsMy first D programTypesArrays .String and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . 38/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 66. D ProgrammingJonathan MERCIER VersionsIntroductionObjectFunctional .Meta-programmingParallelism VersionsRessource ManagementContract .System and Safe Code own version identifierReference and pointer 1 version( FullApp ){ …}Generics 2 else version( DemoApp ){ …}Inference 3 else { version = DemoApp ); }LoopsFunctions .DebugsVersions from command line give wich version to compileRequirementEditors Code 4: TerminalBasicsMy first D program $ ldc2 -d-version="FullApp" myApp.dTypes .Arrays .String and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . 38/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 67. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . 39/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 68. D ProgrammingJonathan MERCIER Before beginning…IntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code .Reference and pointer ToolsGenerics .Inference Compiler: ldcLoopsFunctionsDebugs Standard library: phobosVersions GUI library: gtkd .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . 40/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 69. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . 41/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 70. D ProgrammingJonathan MERCIER EditorsIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract ToolsSystem and Safe Code .Reference and pointerGenerics GeanyInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . 42/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 71. D ProgrammingJonathan MERCIER EditorsIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract ToolsSystem and Safe Code .Reference and pointerGenerics GeanyInferenceLoops MonoDevelop with Mono-DFunctionsDebugsVersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . 42/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 72. D ProgrammingJonathan MERCIER EditorsIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract ToolsSystem and Safe Code .Reference and pointerGenerics GeanyInferenceLoops MonoDevelop with Mono-D Eclipse with DDT - D Development ToolsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . 42/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 73. D ProgrammingJonathan MERCIER EditorsIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract ToolsSystem and Safe Code .Reference and pointerGenerics GeanyInferenceLoops MonoDevelop with Mono-D Eclipse with DDT - D Development ToolsFunctionsDebugsVersionsRequirement Vim + syntasticEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . 42/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 74. D ProgrammingJonathan MERCIER EditorsIntroductionObjectFunctionalMeta-programmingParallelismRessource Management .Contract ToolsSystem and Safe Code .Reference and pointerGenerics GeanyInferenceLoops MonoDevelop with Mono-D Eclipse with DDT - D Development ToolsFunctionsDebugsVersionsRequirement Vim + syntasticEditorsBasics Emacs + d-mode (GitHub)My first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . 42/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 75. D ProgrammingJonathan MERCIER EditorsIntroduction . Online tools: D pasteObjectFunctional .Meta-programming http://dpaste.dzfl.pl/newParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplate .Miscellanous . . . . . . .. . . . . 43/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 76. D ProgrammingJonathan MERCIER InstallationIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenericsInference Code 5: TerminalLoopsFunctions # yum install ldc-phobos-devel gtkd-develDebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . .. . . . . 44/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 77. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . 45/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 78. D ProgrammingJonathan MERCIER My first D programIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer Code 6: hello.dGenerics 1 module hello; .Inference 2 import std.stdio;Loops 3Functions 4 void main () {Debugs 5 writeln( ”Hello world” ); 6 } .VersionsRequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . .. . . . . . 46/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 79. D ProgrammingJonathan MERCIER My first D programIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer Code 7: hello.dGenerics 1 module hello;Inference 2 import std.stdio; .Loops 3Functions 4 void main () {Debugs 5 writeln( ”Hello world” ); 6 } .VersionsRequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 47/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 80. D ProgrammingJonathan MERCIER My first D programIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer Code 8: hello.dGenerics 1 module hello;Inference 2 import std.stdio: writeln; .Loops 3Functions 4 void main () {Debugs 5 writeln( ”Hello world” ); 6 } .VersionsRequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 48/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 81. D ProgrammingJonathan MERCIER My first D programIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer Code 9: hello.dGenerics 1 module hello;Inference 2 import std.stdio: writeln;Loops 3Functions 4 void main () { .Debugs 5 writeln( ”Hello world” ); 6 } .VersionsRequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 49/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 82. D ProgrammingJonathan MERCIER My first D programIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer Code 10: hello.dGenerics 1 module hello;Inference 2 import std.stdio: writeln;Loops 3Functions 4 void main () {Debugs 5 writeln( ”Hello world” ); . 6 } .VersionsRequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 50/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 83. D ProgrammingJonathan MERCIERIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract Code 11: TerminalSystem and Safe CodeReference and pointer $ ldc2 hello.dGenericsInference $ ./helloLoopsFunctions Hello worldDebugs .VersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 51/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 84. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . . . 52/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 85. D ProgrammingJonathan MERCIER TypesIntroductionObject Type bits Minimum MaximumFunctional void Not available Not available Not availableMeta-programming byte 8 -128 127Parallelism short 16 -32768 32767Ressource Management int 32 -2147483648 2147483647Contract long 64 -9223372036854775808 9223372036854775807System and Safe Code ubyte 8 0 255Reference and pointer ushort 16 0 65535Generics uint 32 0 4294967296Inference ulong 64 0 18446744073709551615Loops float 32 1.18e-38 3.40e+38Functions double 64 2.23e-308 1.80e+308DebugsVersions ifloat 32 1.18e-38 3.40e+38Requirement idouble 64 2.23e-308 1.80e+308Editors cfloat 32 1.18e-38 3.40e+38Basics cdouble 64 2.23e-308 1.80e+308My first D program real 128 3.36e-4932 1.19e+4932Types ireal 128 3.36e-4932 1.19e+4932Arrays creal 28 3.36e-4932 1.19e+4932String and characters char utf-8: 8 0 255Const and Immutable wchar utf-16: 16 0 65535Input/Output dchar utf-32: 32 0 4294967293Algorithm bool 8 false trueStructure and ClassTemplateMiscellanous . . . . . . . .. . . . . . 53/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 86. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . . . 54/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 87. D ProgrammingJonathan MERCIER Static arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[3] a1 = [ 0, 1, 2 ]; .Inference 2 int[3][3] a2 = [ [ 0, 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];Loops 3 a1.length;Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 55/122 .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 88. D ProgrammingJonathan MERCIER Static arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[3] a1 = [ 0, 1, 2 ];Inference 2 int[3][3] a2 = [ [ 0, 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; .Loops 3 a1.length;Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . .. . . . . . 56/122 . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 89. D ProgrammingJonathan MERCIER Static arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[3] a1 = [ 0, 1, 2 ];Inference 2 int[3][3] a2 = [ [ 0, 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];Loops 3 a1.length; // return array size .Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 57/122 . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 90. D ProgrammingJonathan MERCIER Dynamic arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a1 = [ 0, 1, 2 ]; .Generics 2 a1.length;Inference 3 a1.length = a1.length + 2;Loops 4 a1.length += 2;FunctionsDebugs .Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 58/122 . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 91. D ProgrammingJonathan MERCIER Dynamic arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a1 = [ 0, 1, 2 ];Generics 2 a1.length; // return array size .Inference 3 a1.length = a1.length + 2;Loops 4 a1.length += 2;FunctionsDebugs .Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 59/122 . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 92. D ProgrammingJonathan MERCIER Dynamic arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a1 = [ 0, 1, 2 ];Generics 2 a1.length;Inference 3 a1.length = a1.length + 2; // resize array .Loops 4 a1.length += 2;FunctionsDebugs .Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 60/122 . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 93. D ProgrammingJonathan MERCIER Dynamic arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a1 = [ 0, 1, 2 ];Generics 2 a1.length;Inference 3 a1.length = a1.length + 2;Loops 4 a1.length += 2; // not allowed .FunctionsDebugs .Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 61/122 . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 94. D ProgrammingJonathan MERCIER Matrix arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenericsInference 1 int [][] a1 = new int[][](2,5); // [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]Loops 2 int [][] a2 = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];Functions .DebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . .. . . . . 62/122 . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 95. D ProgrammingJonathan MERCIER ArraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a1 = [ 0, 1, 2 ]; .Generics 2 a1[0];Inference 3 a1[0..2];Loops 4 a1[0..$];FunctionsDebugs .Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . .. . . . . 63/122 . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 96. D ProgrammingJonathan MERCIER ArraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a1 = [ 0, 1, 2 ];Generics 2 a1[0]; // return 0 .Inference 3 a1[0..2];Loops 4 a1[0..$];FunctionsDebugs .Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 64/122 . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 97. D ProgrammingJonathan MERCIER ArraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a1 = [ 0, 1, 2 ];Generics 2 a1[0];Inference 3 a1[0..2]; // return [0, 1] .Loops 4 a1[0..$];FunctionsDebugs .Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 65/122 . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 98. D ProgrammingJonathan MERCIER ArraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a1 = [ 0, 1, 2 ];Generics 2 a1[0];Inference 3 a1[0..2];Loops 4 a1[0..$]; // return [0, 1, 2] .FunctionsDebugs .Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 66/122 . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 99. D ProgrammingJonathan MERCIER ArraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a = [ 0, 1, 2 ];Generics 2 int[] b = a; // ’b’ point to ’a’ (reference) .Inference 3 int* b_ptr = b.ptr;Loops 4 int[] c = a[ 0 .. 2 ];Functions 5 int[] d = a[ 0 .. 2 ].dup;Debugs . .VersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 67/122 . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 100. D ProgrammingJonathan MERCIER ArraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a = [ 0, 1, 2 ];Generics 2 int[] b = a;Inference 3 int* b_ptr = b.ptr; // return pointer to given array .Loops 4 int[] c = a[ 0 .. 2 ];Functions 5 int[] d = a[ 0 .. 2 ].dup;Debugs . .VersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 68/122 . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 101. D ProgrammingJonathan MERCIER ArraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a = [ 0, 1, 2 ];Generics 2 int[] b = a;Inference 3 int* b_ptr = b.ptr;Loops 4 int[] c = a[ 0 .. 2 ]; // is a reference .Functions 5 int[] d = a[ 0 .. 2 ].dup;Debugs . .VersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 69/122 . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 102. D ProgrammingJonathan MERCIER ArraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer 1 int[] a = [ 0, 1, 2 ];Generics 2 int[] b = a;Inference 3 int* b_ptr = b.ptr;Loops 4 int[] c = a[ 0 .. 2 ];Functions 5 int[] d = a[ 0 .. 2 ].dup; // is a copy .Debugs . .VersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 70/122 . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 103. D ProgrammingJonathan MERCIER VectorsIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[] a1 = new int[](2); // [0,0]. .Inference 2 a1[] = 1;Loops 3 a1[]+= 2;Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . .. . . . 71/122 . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 104. D ProgrammingJonathan MERCIER VectorsIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[] a1 = new int[](2);Inference 2 a1[] = 1; // [1,1]. .Loops 3 a1[]+= 2;Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . .. . . . 72/122 . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 105. D ProgrammingJonathan MERCIER VectorsIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[] a1 = new int[](2);Inference 2 a1[] = 1;Loops 3 a1[]+= 2; // [3,3] .Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . .. . . . 73/122 . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 106. D ProgrammingJonathan MERCIER Associative arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[string] dict; .Inference 2 dict[”D”] = 1;Loops 3 ”D” in dict;Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 74/122 . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 107. D ProgrammingJonathan MERCIER Associative arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[string] dict;Inference 2 dict[”D”] = 1; .Loops 3 ”D” in dict;Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 75/122 . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 108. D ProgrammingJonathan MERCIER Associative arraysIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 int[string] dict;Inference 2 dict[”D”] = 1;Loops 3 ”D” in dict; // true .Functions .DebugsVersions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 76/122 . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 109. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . . . 77/122 . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 110. D ProgrammingJonathan MERCIER String and charactersIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics 1 string words = ”With double quote, αβγδϵ”; // UTF−8Inference 2 string words2= words ~ ”, and concatenation”; // concatLoops 3 char letter= ’a’; // simple quoteFunctionsDebugs .VersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 78/122 . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 111. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . . . 79/122 . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 112. D ProgrammingJonathan MERCIER Const and ImmutableIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code .Reference and pointer Const and ImmutableGenerics .Inference im­mutable data: that can­not change.LoopsFunctionsDebugs const data: can­not be changedVersions by the current const ref­er­ence to that data.RequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 80/122 . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 113. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . .. . . 81/122 . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 114. D ProgrammingJonathan MERCIER Input/OutputIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer Code 12: Read a fileGenerics 1 import std.stdio: open, writeln;Inference 2 …Loops 3 File f = open( ”/path/to/myFile”, ”r” );Functions 4 scope(exit) f.close;Debugs 5 foreach( number, line; f )Versions 6 writeln( number, line );Requirement 7 …Editors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . .. . . 82/122 . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 115. D ProgrammingJonathan MERCIER Input/OutputIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics Code 13: Write a fileInference 1 import std.stdio: open, writeln; 2 …Loops 3 File f = open( ”/path/to/myFile”, ”w” );Functions 4 scope(exit) f.close;Debugs 5 writeln( ”something” );Versions 6 …RequirementEditors .BasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 83/122 . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 116. D ProgrammingJonathan MERCIER Input/OutputIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 14: Capture keyboardReference and pointer 1 import std.stdio: open, writeln;Generics 2 …Inference 3 char[] name;Loops 4 size_t age;Functions 5 write( ”Enter your name : ” );Debugs 6 readf( ”%s” ~ newline, &name );Versions 7 write( ”How old are you : ” );Requirement 8 readf( ”%u” ~ newline, &age );Editors 9 …Basics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 84/122 . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 117. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . . . 85/122 . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 118. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 15: SearchingReference and pointer 1 import std.algorihm: count, countUntil, startsWith, endsWith,Generics canFind;Inference 2 …Loops 3 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; .Functions 4 list .count( 1 ); 5 list .countUntil( 2 );Debugs 6 list .startsWith( 0 );Versions 7 list .endsWith( 9 );Requirement 8 list .canFind( 2 );Editors .BasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 86/122 . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 119. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 16: SearchingReference and pointer 1 import std.algorihm: count, countUntil, startsWith, endsWith,Generics canFind;Inference 2 …Loops 3 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Functions 4 list .count( 1 ); // result => 2 . 5 list .countUntil( 2 );Debugs 6 list .startsWith( 0 );Versions 7 list .endsWith( 9 );Requirement 8 list .canFind( 2 );Editors .BasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 87/122 . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 120. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 17: SearchingReference and pointer 1 import std.algorihm: count, countUntil, startsWith, endsWith,Generics canFind;Inference 2 …Loops 3 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Functions 4 list .count( 1 ); 5 list .countUntil( 2 ); // result => 3 .Debugs 6 list .startsWith( 0 );Versions 7 list .endsWith( 9 );Requirement 8 list .canFind( 2 );Editors .BasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 88/122 . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 121. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 18: SearchingReference and pointer 1 import std.algorihm: count, countUntil, startsWith, endsWith,Generics canFind;Inference 2 …Loops 3 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Functions 4 list .count( 1 ); 5 list .countUntil( 2 );Debugs 6 list .startsWith( 0 ); // result => true .Versions 7 list .endsWith( 9 );Requirement 8 list .canFind( 2 );Editors .BasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 89/122 . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 122. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 19: SearchingReference and pointer 1 import std.algorihm: count, countUntil, startsWith, endsWith,Generics canFind;Inference 2 …Loops 3 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Functions 4 list .count( 1 ); 5 list .countUntil( 2 );Debugs 6 list .startsWith( 0 );Versions 7 list .endsWith( 9 ); // result => true .Requirement 8 list .canFind( 2 );Editors .BasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . .. . 90/122 . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 123. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 20: SearchingReference and pointer 1 import std.algorihm: count, countUntil, startsWith, endsWith,Generics canFind;Inference 2 …Loops 3 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Functions 4 list .count( 1 ); 5 list .countUntil( 2 );Debugs 6 list .startsWith( 0 );Versions 7 list .endsWith( 9 );Requirement 8 list .canFind( 2 ); // result => true .Editors .BasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . .. . 91/122 . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 124. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics Code 21: ComparisonInference 1 import std.algorihm: min, max;Loops 2 …Functions 3 min( 9, 12); // result => 9Debugs 4 max( 9, 12); // result => 12VersionsRequirement .EditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . .. . 92/122 . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 125. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 22: IterationReference and pointer 1 import std.algorihm: filter, uniq, map, reduce;Generics 2 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; .Inference 3 list . filter !( a => a > 6 );Loops 4 list .uniq( );Functions 5 list .map!( a => a + 2 );Debugs 6 0.reduce!( (a,b) => a + b )( list );Versions 7 list .reduce!( min, max )( );RequirementEditors .Basics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 93/122 . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 126. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 23: IterationReference and pointer 1 import std.algorihm: filter, uniq, map, reduce;Generics 2 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Inference 3 list . filter !( a => a > 6 ); // result => [ 7, 8, 9 ] .Loops 4 list .uniq( );Functions 5 list .map!( a => a + 2 );Debugs 6 0.reduce!( (a,b) => a + b )( list );Versions 7 list .reduce!( min, max )( );RequirementEditors .Basics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 94/122 . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 127. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 24: IterationReference and pointer 1 import std.algorihm: filter, uniq, map, reduce;Generics 2 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Inference 3 list . filter !( a => a > 6 );Loops 4 list .uniq( ); // [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] .Functions 5 list .map!( a => a + 2 );Debugs 6 0.reduce!( (a,b) => a + b )( list );Versions 7 list .reduce!( min, max )( );RequirementEditors .Basics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 95/122 . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 128. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 25: IterationReference and pointer 1 import std.algorihm: filter, uniq, map, reduce;Generics 2 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Inference 3 list . filter !( a => a > 6 );Loops 4 list .uniq( );Functions 5 list .map!( a => a + 2 ); // [ 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11 ] .Debugs 6 0.reduce!( (a,b) => a + b )( list );Versions 7 list .reduce!( min, max )( );RequirementEditors .Basics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 96/122 . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 129. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 26: IterationReference and pointer 1 import std.algorihm: filter, uniq, map, reduce;Generics 2 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Inference 3 list . filter !( a => a > 6 );Loops 4 list .uniq( );Functions 5 list .map!( a => a + 2 );Debugs 6 0.reduce!( (a,b) => a + b )( list ); // sum all elements => 49 .Versions 7 list .reduce!( min, max )( );RequirementEditors .Basics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 97/122 . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 130. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 27: IterationReference and pointer 1 import std.algorihm: filter, uniq, map, reduce;Generics 2 int[] list = [ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];Inference 3 list . filter !( a => a > 6 );Loops 4 list .uniq( );Functions 5 list .map!( a => a + 2 );Debugs 6 0.reduce!( (a,b) => a + b )( list );Versions 7 list .reduce!( min, max )( ); // compute in one pass min an max .Requirement 8 // min: 0 max: 9Editors .Basics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 98/122 . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 131. D ProgrammingJonathan MERCIER AlgorithmIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 28: SortingReference and pointer 1 import std.stdio;Generics 2 import std.algorithm;Inference 3 import std.array;Loops 4Functions 5 void main( ){ 6 immutable int[] a = [4, 6, 1, 2];Debugs 7 immutable int[] b = cast(immutable) a.dupVersions 8 .sort!( (x,y) => x < y )Requirement 9 .array;Editors 10 writeln( b ); // [ 1, 2, 4, 6 ]Basics 11 }My first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . .. 99/122 . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 132. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . .. 100/122 . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 133. D ProgrammingJonathan MERCIER StructureIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics Code 29: Classic implementationInference 1 struct MyStruct{Loops 2 int field1;Functions 3 float fiel2;Debugs 4 string field3;Versions 5 }Requirement .EditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . .. 101/122 . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 134. D ProgrammingJonathan MERCIER StructureIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract Code 30: With constructor and modifierSystem and Safe Code 1 struct MyStruct{Reference and pointer 2 private:Generics 3 int _field1;Inference 4 float _fiel2;Loops 5 string _field3;Functions 6Debugs 7 public: 8 this( int f1, float f2, string f3 ){Versions 9 _field1 = f1;Requirement 10 _field2 = f2;Editors 11 _field3 = f3;Basics 12 } 13 }My first D programTypes .ArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 102/122 . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 135. D ProgrammingJonathan MERCIER StructureIntroductionObjectFunctional Code 31: With method and propertyMeta-programming 1 struct MyStruct{Parallelism 2 private:Ressource Management 3 int _field1;Contract 4 float _field2;System and Safe Code 5 string _field3;Reference and pointer 6 public: 7 this( int f1, float f2, string f3 ){Generics 8 _field1 = f1;Inference 9 _field2 = f2;Loops 10 _field3 = f3;Functions 11 }Debugs 12 this( MyStruct s ){Versions 13 _field1 = s.field1;Requirement 14 _field2 = s.field2;Editors 15 _field3 = s.field3; 16 }Basics 17 @property int field1( ) const { return _field1; }My first D program 18 @property void field1( int f1 ){ _field1 = f1; }Types 19 @property float field2( ) const { return _field2; }Arrays 20 @property void field2( float f2 ){ _field2 = f2; }String and characters 21 @property string field3( ) const { return _field3; }Const and Immutable 22 @property void field3( string f3 ){ _field3 = f3; }Input/Output 23 MyStruct dup() const{ return MyStruct( this ); }Algorithm 24 }Structure and Class .TemplateMiscellanous . . . . . . . . . . . . . . 103/122 . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 136. D ProgrammingJonathan MERCIER ClassIntroductionObject Code 32: PolymorphismFunctional 1 import std.string: format;Meta-programming 2Parallelism 3 Interface IPersonnage{Ressource Management 4 string name();Contract 5 int health();System and Safe Code 6 int mana(); 7 }Reference and pointer 8Generics 9 class BowMan: IPersonnage{Inference 10 private:Loops 11 string _name;Functions 12 int _health;Debugs 13 int _mana;Versions 14 public:Requirement 15 this( string n, int h, int m ){Editors 16 _name = n; 17 _health = h;Basics 18 _mana = m;My first D program 19 }Types 20 string name() const { return _name; }Arrays 21 int health() const { return _health; }String and characters 22 int mana() const { return _mana; }Const and Immutable 23 override string toString() const{Input/Output 24 return ”name: %s point: %d mana: %d”.format(_name, _health,Algorithm _mana);Structure and Class 25 }Template 26 }Miscellanous . . . . . . . . . . . . . . . 104/122 . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 137. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . . . 105/122 . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 138. D ProgrammingJonathan MERCIER TemplateIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenericsInference Code 33: Function templateLoops 1 auto addition(T,U)( T a, U b){Functions 2 return a + b;Debugs 3 }Versions .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . . 106/122 . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 139. D ProgrammingJonathan MERCIER TemplateIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract Code 34: Struct templateSystem and Safe Code 1 struct TStruct(T) {Reference and pointer 2 private:Generics 3 T _f1;Inference 4 public:Loops 5 this ( T f1 ){Functions 6 _f1 = f1;Debugs 7 }Versions 8 }Requirement 9 void main(){Editors 10 TStruct!string t1 = TStruct!(string)( ”test” ); 11 auto t2 = TStruct!int( 5 );Basics 12 }My first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 107/122 . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 140. D ProgrammingJonathan MERCIER TemplateIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe Code Code 35: Class templateReference and pointer 1 class TClass(T) {Generics 2 private:Inference 3 T _f1;Loops 4 public:Functions 5 this ( T f1 ){Debugs 6 _f1 = f1;Versions 7 }Requirement 8 }Editors 9 auto c1 = new TClass!int( 2 );Basics .My first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 108/122 . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 141. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . . . 109/122 . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 142. D ProgrammingJonathan MERCIER MiscellanousIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenericsInference 1 int β = 5; // variable name can use UTF−8 charLoops 2 int i = 1_000_000; // easy to read numberFunctions .DebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 110/122 .. . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 143. D ProgrammingJonathan MERCIER Plan .. 1 IntroductionIntroduction ObjectObject FunctionalFunctional Meta-programmingMeta-programming ParallelismParallelism Ressource ManagementRessource Management Contract System and Safe CodeContract Reference and pointerSystem and Safe Code GenericsReference and pointer InferenceGenerics LoopsInference FunctionsLoops DebugsFunctions VersionsDebugs RequirementVersions EditorsRequirement . 2 BasicsEditors My first D program TypesBasics ArraysMy first D program String and charactersTypes Const and ImmutableArrays Input/OutputString and characters AlgorithmConst and Immutable Structure and ClassInput/Output TemplateAlgorithm MiscellanousStructure and Class Let start it! . 3 GTK DTemplate . 4 Thanks ToMiscellanous . . . . . . . . . . . . . 111/122 .. . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 144. D ProgrammingJonathan MERCIER What Are You Waiting For?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .ContractSystem and Safe Code Web site: dlang.orgReference and pointerGenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 112/122 . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 145. D ProgrammingJonathan MERCIER What Are You Waiting For?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .ContractSystem and Safe Code Web site: dlang.orgReference and pointerGenerics Community: forum.dlang.orgInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 112/122 . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 146. D ProgrammingJonathan MERCIER What Are You Waiting For?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .ContractSystem and Safe Code Web site: dlang.orgReference and pointerGenerics Community: forum.dlang.orgInferenceLoops Contribute:FunctionsDebugs www.github.com/D-Programming-LanguageVersionsRequirementEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 112/122 . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 147. D ProgrammingJonathan MERCIER What Are You Waiting For?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .ContractSystem and Safe Code Web site: dlang.orgReference and pointerGenerics Community: forum.dlang.orgInferenceLoops Contribute:FunctionsDebugs www.github.com/D-Programming-LanguageVersionsRequirement irc on freenode #dEditorsBasicsMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 112/122 . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 148. D ProgrammingJonathan MERCIER What Are You Waiting For?IntroductionObjectFunctionalMeta-programmingParallelismRessource Management .ContractSystem and Safe Code Web site: dlang.orgReference and pointerGenerics Community: forum.dlang.orgInferenceLoops Contribute:FunctionsDebugs www.github.com/D-Programming-LanguageVersionsRequirement irc on freenode #dEditorsBasics french speaker on jabber d-fr@chat.jabberfr.orgMy first D program .TypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 112/122 . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 149. D ProgrammingJonathan MERCIER GTK DIntroductionObjectFunctionalMeta-programming Code 36: First graphical applicationParallelism 1 module myFirstGUI;Ressource Management 2Contract 3 import gtk.MainWindow;System and Safe Code 4 import gtk.Label;Reference and pointer 5 import gtk.Main;Generics 6Inference 7 class myFirstGUI: MainWindow{Loops 8 this(){Functions 9 super(”GtkD”); 10 setBorderWidth(10);Debugs 11 add(new Label(”Hello World”));Versions 12 showAll();Requirement 13 }Editors 14 }Basics 15 16 void main(string[] args){My first D program 17 Main.init(args);Types 18 new HelloWorld();Arrays 19 Main.run();String and characters 20Const and Immutable 21 }Input/OutputAlgorithm .Structure and ClassTemplateMiscellanous . . . . . . . . . . . . . 113/122 . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 150. D ProgrammingJonathan MERCIER GTK DIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContract Code 37: TerminalSystem and Safe CodeReference and pointerGenerics $ ldc2 -L-lgtkd -L-ldl myFirstGUI.dInference $ ./myFistGUILoopsFunctions .DebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 114/122 . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 151. D ProgrammingJonathan MERCIER GTK DIntroductionObject Code 38: First graphical applicationFunctional 1 module myFirstGUI;Meta-programming 2Parallelism 3 import gtk.MainWindow;Ressource Management 4 import gtk.Label;Contract 5 import gtk.Main;System and Safe Code 6Reference and pointer 7 pragma(lib, ”gtkd”); .Generics 8Inference 9 class myFirstGUI: MainWindow{Loops 10 this(){Functions 11 super(”GtkD”);Debugs 12 setBorderWidth(10);Versions 13 add(new Label(”Hello World”));Requirement 14 showAll();Editors 15 } 16 }Basics 17My first D program 18 void main(string[] args){Types 19 Main.init(args);Arrays 20 new myFirstGUI();String and characters 21 Main.run();Const and Immutable 22Input/Output 23 }Algorithm .Structure and ClassTemplate .Miscellanous . . . . . . . . . . . . . 115/122 . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 152. D ProgrammingJonathan MERCIER GTK DIntroductionObject Code 39: First graphical applicationFunctional 1 module myFirstGUI;Meta-programming 2Parallelism 3 import gtk.MainWindow;Ressource Management 4 import gtk.Label;Contract 5 import gtk.Main;System and Safe Code 6Reference and pointer 7 pragma(lib, ”gtkd”);Generics 8Inference 9 class myFirstGUI: MainWindow{ .Loops 10 this(){Functions 11 super(”GtkD”);Debugs 12 setBorderWidth(10);Versions 13 add(new Label(”Hello World”));Requirement 14 showAll();Editors 15 } 16 }Basics 17My first D program 18 void main(string[] args){Types 19 Main.init(args);Arrays 20 new myFirstGUI();String and characters 21 Main.run();Const and Immutable 22Input/Output 23 }Algorithm .Structure and ClassTemplate .Miscellanous . . . . . . . . . . . . . 116/122 . ... . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 153. D ProgrammingJonathan MERCIER GTK DIntroductionObject Code 40: First graphical applicationFunctional 1 module myFirstGUI;Meta-programming 2Parallelism 3 import gtk.MainWindow;Ressource Management 4 import gtk.Label;Contract 5 import gtk.Main;System and Safe Code 6Reference and pointer 7 pragma(lib, ”gtkd”);Generics 8Inference 9 class myFirstGUI: MainWindow{Loops 10 this(){Functions 11 super(”GtkD”);Debugs 12 setBorderWidth(10);Versions 13 add(new Label(”Hello World”));Requirement 14 showAll();Editors 15 } 16 }Basics 17My first D program 18 void main(string[] args){ .Types 19 Main.init(args);Arrays 20 new myFirstGUI();String and characters 21 Main.run();Const and Immutable 22Input/Output 23 }Algorithm .Structure and ClassTemplate .Miscellanous . . . . . . . . . . . . . 117/122 . . . . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 154. D ProgrammingJonathan MERCIER First graphical ApplicationIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics Code 41: TerminalInferenceLoops $ ldc2 -L-ldl myFirstGUI.dFunctionsDebugs $ ./myFistGUIVersionsRequirement .EditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 118/122 . .. . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 155. D ProgrammingJonathan MERCIER GTK DIntroductionObject Code 42: First graphical applicationFunctional 1 module myFirstGUI;Meta-programming 2Parallelism 3 import gtk.MainWindow;Ressource Management 4 import gtk.Label;Contract 5 import gtk.Main;System and Safe Code 6Reference and pointer 7 pragma(lib, ”gtkd”);Generics 8 version( Linux ) pragma(lib, ”dl”); .Inference 9Loops 10 class myFirstGUI: MainWindow{Functions 11 this(){ 12 super(”GtkD”);Debugs 13 setBorderWidth(10);Versions 14 add(new Label(”Hello World”));Requirement 15 showAll();Editors 16 }Basics 17 } 18My first D program 19 void main(string[] args){Types 20 Main.init(args);Arrays 21 new myFirstGUI();String and characters 22 Main.run();Const and Immutable 23Input/Output 24 }AlgorithmStructure and Class .Template .Miscellanous . . . . . . . . . . . . . 119/122 . . .. . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 156. D ProgrammingJonathan MERCIER First graphical ApplicationIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointerGenerics Code 43: TerminalInferenceLoops $ ldc2 myFirstGUI.dFunctionsDebugs $ ./myFistGUIVersionsRequirement .EditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 120/122 . . .. . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 157. D ProgrammingJonathan MERCIER ContactIntroductionObjectFunctionalMeta-programmingParallelismRessource ManagementContractSystem and Safe CodeReference and pointer .Generics Comments, suggestions or bug reports ?Inference .LoopsFunctions Please send a mail at:DebugsVersions bioinfornatics@fedoraproject.org .RequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 121/122 . . .. . . . . . . . . . . . .Let start it! D Programming . . . . Back . . . . . Forward .GTK D
  • 158. D ProgrammingJonathan MERCIER Thanks toIntroduction .Object To your attentionFunctionalMeta-programming French fedora communityParallelismRessource ManagementContract D communitySystem and Safe CodeReference and pointer Mohamed El MorabityGenericsInferenceLoopsFunctionsDebugsVersionsRequirementEditorsBasicsMy first D programTypesArraysString and charactersConst and ImmutableInput/OutputAlgorithmStructure and ClassTemplateMiscellanous . . . . . . . . . . . . . 122/122 . . . . . . . . . . . . . . .Let start it!GTK D . D Programming . . . . Back .

×