Who Needs C++ When                             You Have D and Go?                                    Russel Winder        ...
controversy           noun              dispute, argument, or debate, especially one              concerning a matter abou...
Calculate the sum of the squares of the           numbers between 0 and 100 that are                       divisible by 7....
int sequential_iterative() {                                   auto sum = 0;                                   foreach (i;...
func sequential_iterative() (sum int) {                                    for i := 0; i < 100; i++ {                     ...
int sequential_iterative() {                                   auto sum = 0;                                   for (auto i...
So all native code programming                            languages are the same?Copyright © 2013 Russel Winder           ...
We are, of course, expected                   to be more declarative these days…Copyright © 2013 Russel Winder            ...
Possibly even functional…Copyright © 2013 Russel Winder                               9
reduce!"a + b"(map!"a * a"(filter!"a % 7 == 0"(iota(100))))Copyright © 2013 Russel Winder                                 ...
functools.Inject(func (a, b int) int { return a + b },           functools.Collect(func (i int) int { return i * i },     ...
int sequential_declarative() {   std::vector<int> numbers (100);   std::iota(numbers.begin(), numbers.end(), 1);   std::li...
What about being fluent…Copyright © 2013 Russel Winder                              13
iota(100).filter!"a % 7 == 0"().map!"a * a"().reduce!"a + b"()Copyright © 2013 Russel Winder                              ...
functools.IntSlice(make([]int, 100)).                 Filter(func (i int) bool { return i % 7 == 0 }).                    ...
?Copyright © 2013 Russel Winder       16
Execute it!Copyright © 2013 Russel Winder                 17
Use D                                     Use Go                                   Use Python                             ...
http://www.dlang.org                                 http://www.go-lang.orgCopyright © 2013 Russel Winder                 ...
Who Needs C++ When                             You Have D and Go?                                    Russel Winder        ...
Upcoming SlideShare
Loading in …5
×

Who needs C++ when you have D and Go

2,149 views

Published on

Slides from my ACCU 2013 lightning talk. D is the real winner as the functions work out of the box. The Go code requires lots of extra code. Until std::range exists it is the loser.

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

  • Be the first to like this

No Downloads
Views
Total views
2,149
On SlideShare
0
From Embeds
0
Number of Embeds
174
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Who needs C++ when you have D and Go

  1. 1. Who Needs C++ When You Have D and Go? Russel Winder email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder Web: http://www.russel.org.ukCopyright © 2013 Russel Winder 1
  2. 2. controversy noun dispute, argument, or debate, especially one concerning a matter about which there is strong disagreementCopyright © 2013 Russel Winder 2
  3. 3. Calculate the sum of the squares of the numbers between 0 and 100 that are divisible by 7.Copyright © 2013 Russel Winder 3
  4. 4. int sequential_iterative() { auto sum = 0; foreach (i; 0 .. 100) { if (i % 7 == 0) { sum += i * i; } } return sum; }Copyright © 2013 Russel Winder 4
  5. 5. func sequential_iterative() (sum int) { for i := 0; i < 100; i++ { if (i % 7 == 0) { sum += i * i } } return }Copyright © 2013 Russel Winder 5
  6. 6. int sequential_iterative() { auto sum = 0; for (auto i = 0; i < 100; ++i) { if (i % 7 == 0) { sum += i * i; } } return sum; }Copyright © 2013 Russel Winder 6
  7. 7. So all native code programming languages are the same?Copyright © 2013 Russel Winder 7
  8. 8. We are, of course, expected to be more declarative these days…Copyright © 2013 Russel Winder 8
  9. 9. Possibly even functional…Copyright © 2013 Russel Winder 9
  10. 10. reduce!"a + b"(map!"a * a"(filter!"a % 7 == 0"(iota(100))))Copyright © 2013 Russel Winder 10
  11. 11. functools.Inject(func (a, b int) int { return a + b }, functools.Collect(func (i int) int { return i * i }, functools.Filter(func (i int) bool { return i % 7 == 0 }, make([]int, 100))))Copyright © 2013 Russel Winder 11
  12. 12. int sequential_declarative() { std::vector<int> numbers (100); std::iota(numbers.begin(), numbers.end(), 1); std::list<int> filtered; std::copy_if(numbers.begin(), numbers.end(), std::back_insert_iterator<std::list<int>>(filtered), [=] (int i) { return i % 7 == 0; }); std::vector<int> squares (filtered.size()); std::transform(filtered.begin(), filtered.end(), std::back_insert_iterator<std::vector<int>>(squares), [=] (int i) { return i * i;}); return std::accumulate(squares.begin(), squares.end(), 0, [=] (int i, int j) { return i + j;}); }Copyright © 2013 Russel Winder 12
  13. 13. What about being fluent…Copyright © 2013 Russel Winder 13
  14. 14. iota(100).filter!"a % 7 == 0"().map!"a * a"().reduce!"a + b"()Copyright © 2013 Russel Winder 14
  15. 15. functools.IntSlice(make([]int, 100)). Filter(func (i int) bool { return i % 7 == 0 }). Collect(func (i int) int { return i * i }). Inject(func (a, b int) int { return a + b })Copyright © 2013 Russel Winder 15
  16. 16. ?Copyright © 2013 Russel Winder 16
  17. 17. Execute it!Copyright © 2013 Russel Winder 17
  18. 18. Use D Use Go Use Python Anything but C++Copyright © 2013 Russel Winder 18
  19. 19. http://www.dlang.org http://www.go-lang.orgCopyright © 2013 Russel Winder 19
  20. 20. Who Needs C++ When You Have D and Go? Russel Winder email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder Web: http://www.russel.org.ukCopyright © 2013 Russel Winder 20

×