0
The D Programming Language Matthew Clark Power, flexibility and safety
What is D? <ul><li>“D is a systems programming language. Its focus is on combining the power and high performance of C and...
...OK... <ul><li>Statically typed
Compiles into machine code (GC built-in if you use it)
Garbage Collection by default... if you want it
Defaults to safety  </li><ul><ul><li>Thread safe memory management (@safe)
Throws exceptions on any error
Type-safe </li></ul></ul><li>Language written for programs to write elegant code </li></ul>
Object oriented <ul><li>But doesn't force you into it
Is object oriented, but no multiple inheritance from classes...
So use interfaces instead (inherit as many as you like)
Object names are references (only new if new, otherwise just another ref)
Object is the “root” of all objects... </li></ul>
Object <ul><li>Since all inherit from Object all have: </li><ul><ul><li>toString[returns a string with the full name of th...
Upcoming SlideShare
Loading in...5
×

The D Programming Language - Why I love it!

1,748

Published on

Why I love D

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,748
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
53
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "The D Programming Language - Why I love it!"

  1. 1. The D Programming Language Matthew Clark Power, flexibility and safety
  2. 2. What is D? <ul><li>“D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. Special attention is given to the needs of quality assurance, documentation, management, portability and reliability.” </li></ul>
  3. 3. ...OK... <ul><li>Statically typed
  4. 4. Compiles into machine code (GC built-in if you use it)
  5. 5. Garbage Collection by default... if you want it
  6. 6. Defaults to safety </li><ul><ul><li>Thread safe memory management (@safe)
  7. 7. Throws exceptions on any error
  8. 8. Type-safe </li></ul></ul><li>Language written for programs to write elegant code </li></ul>
  9. 9. Object oriented <ul><li>But doesn't force you into it
  10. 10. Is object oriented, but no multiple inheritance from classes...
  11. 11. So use interfaces instead (inherit as many as you like)
  12. 12. Object names are references (only new if new, otherwise just another ref)
  13. 13. Object is the “root” of all objects... </li></ul>
  14. 14. Object <ul><li>Since all inherit from Object all have: </li><ul><ul><li>toString[returns a string with the full name of the object type, ie. “test.testClass”]
  15. 15. factory(string T)[returns a new object of the type “T”]
  16. 16. Compare operator </li></ul></ul></ul><ul>Int main(string args[]){ <ul><ul><li>enforce(args.length > 1,&quot;Usage: testFactory [bob] [peter]&quot;);
  17. 17. foreach(command;args[1..$]) {
  18. 18. tester Test = enforce(cast(tester)Object.factory(&quot;testFactory.&quot;~command),command~&quot; is an invalid command&quot;);
  19. 19. Test.print();
  20. 20. }
  21. 21. return 0;
  22. 22. }
  23. 23. https://gist.github.com/1015355 </li></ul></ul></ul>
  24. 24. Slices (or ranges) <ul><li>Replaces iterators
  25. 25. Reduces duplicate code
  26. 26. Dynamic arrays (length can be changed and any point)
  27. 27. All arrays in D are slices
  28. 28. Can read the raw memory pointer at anytime with .ptr (makes working with c-apis like opengl a joy to work with, deal with data in slice and then send into lib with .ptr, get to keep GC that way too!) </li></ul>
  29. 29. Strings <ul><li>Strings are have a lot of built-in goodies
  30. 30. Are slices of chars so all the power of slices(insert, join, repeat, replace, etc) plus
  31. 31. Case manipulation (capwords, capitalize, toupper, tolower, etc.)
  32. 32. Split, strip, format, chop, chomp and cat(~=)
  33. 33. InPattern? IsNumeric? iswhite(space)? Compare? </li></ul>
  34. 34. Templates <ul><li>Easy to use
  35. 35. Flexible - Can contain anything or just make a single function
  36. 36. As containers act almost like namespaces
  37. 37. Template Tfoo(A, B:A*) { class bar{...} enum {…} struct{...} }; Tfoo(int,int*).bar myBar;
  38. 38. C++: template<class T> int func(){ T blah;}
  39. 39. D: int func(T)(){T blah;}
  40. 40. The all powerful to!()() must be noted! </li><ul><ul><li>int one = to!(int)(“1”);
  41. 41. auto nextPage = to!(string)(data[currentPlace..(currentPlace+40)]); </li></ul></ul></ul>
  42. 42. Threads and Fibers <ul><li>Built in support for threads and fibers
  43. 43. Safe unless you choose otherwise
  44. 44. By default data is not shared across threads </li><ul><ul><li>Even static means “only one copy per thread”
  45. 45. Simple add the “shared” attribute if that is what you need </li></ul></ul><li>Makes threads as simple as a spawn(func, param1, param2)
  46. 46. Simple to use asynchronous messaging between threads(to help avoid shared memory) </li></ul>
  47. 47. One liners <ul><li>Modules - Help to organize code (think more powerful namespace)
  48. 48. Type.init – types init themselves to logical defaults
  49. 49. C – style – So it's easier to get used to the syntax
  50. 50. Cross-Platform – compilers for windows, osx, linux and freebsd (open source so can be ported to others!) (if you don't need GC or phobos can compile it to any platform LLVM or GCC support with LDC or GDC) </li></ul>
  51. 51. One liners (c) <ul><li>Alias instead of #define (more powerful ie “alias blah this”)
  52. 52. Delegates elegant way to do callbacks, can point to member-function(int delegate(int) dg)
  53. 53. Based on C – if all else fails and you want that much more control you can just write that part of the code in C with manual memory management and all(removes GC overhead if needed) or link to a C/C++ lib(restrictions!)
  54. 54. Non-templated functions with no parameters don't need ()s ie. MyNumber.getNumber </li></ul>
  55. 55. One liners (c) <ul><li>Unicode – support built in
  56. 56. Unittesting – built in
  57. 57. Mixins – let you generate code at compile time from any string
  58. 58. Phobos – Super powerful std lib(can still use tango if you rather) </li></ul>
  59. 59. Gists <ul><li>Signals/slots, mixin, tuples: https://gist.github.com/1015368
  60. 60. Object.factory, slice w/ foreach loop, enforce: https://gist.github.com/1015355
  61. 61. Simple demo of inheritance: https://gist.github.com/1014930 </li></ul>
  62. 62. Thank you for your time! <ul><li>You can get D and learn more at http://www.digitalmars.com/d/2.0/index.html
  63. 63. You can get code/libs at http://dsource.org/
  64. 64. Recent articles </li><ul><ul><li>Slices: http://www.dsource.org/projects/dcollections/wiki/ArrayArticle
  65. 65. Concurrency, Parallelism and D http://davesdprogramming.wordpress.com/2011/04/07/7/ </li></ul></ul><li>Contact me: </li><ul><ul><li>Twitter: @ryutenchi
  66. 66. Email: mclark4386@gmail.com </li></ul></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×