www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Case study on ranges and lazy evaluation

reply "Matt Kline" <matt bitbashing.io> writes:
With the general push to make more of Phobos use lazily evaluated 
ranges, Walter's DConf talk, and even C++ moving towards ranges 
(https://www.youtube.com/watch?v=uXBcwcF3ln4), I wrote a small 
article with a case study examining their merits.

http://bitbashing.io/be-lazy-use-ranges.html

The target audience is largely those unfamiliar with ranges (and 
to a certain extent, D), but I welcome any and all feedback.
Jul 20 2015
next sibling parent "extrawurst" <stephan extrawurst.org> writes:
On Monday, 20 July 2015 at 17:26:31 UTC, Matt Kline wrote:
 With the general push to make more of Phobos use lazily 
 evaluated ranges, Walter's DConf talk, and even C++ moving 
 towards ranges (https://www.youtube.com/watch?v=uXBcwcF3ln4), I 
 wrote a small article with a case study examining their merits.

 http://bitbashing.io/be-lazy-use-ranges.html

 The target audience is largely those unfamiliar with ranges 
 (and to a certain extent, D), but I welcome any and all 
 feedback.
https://www.reddit.com/r/programming/comments/3dyr79/be_lazy_use_ranges/
Jul 20 2015
prev sibling next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
Quick, what does this loop in this function do?

void PanelBar::RepositionExpandedPanels(Panel* fixed_panel)


I'm willing to guess it repositions the expanded panels.... named 
functions are the best abstraction.
Jul 20 2015
next sibling parent "Matt Kline" <matt bitbashing.io> writes:
On Monday, 20 July 2015 at 18:17:18 UTC, Adam D. Ruppe wrote:
 Quick, what does this loop in this function do?

 void PanelBar::RepositionExpandedPanels(Panel* fixed_panel)


 I'm willing to guess it repositions the expanded panels.... 
 named functions are the best abstraction.
Well, yes, but crap code with a good name is still crap code. If you look at the _how_, it rapidly falls away to insanity. Sean Parent's talk discusses how he was able to turn this function, which was over 100 lines of nasty loops, into two std::algorithm calls.
Jul 20 2015
prev sibling parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 20 July 2015 at 18:17:18 UTC, Adam D. Ruppe wrote:
 Quick, what does this loop in this function do?

 void PanelBar::RepositionExpandedPanels(Panel* fixed_panel)


 I'm willing to guess it repositions the expanded panels.... 
 named functions are the best abstraction.
That's great for an API user, but it's not as massively impactful for actually getting the code right, changing the code, finding the bugs in the code, etc... where you need to actually need to understand the logic.
Jul 20 2015
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 20 July 2015 at 19:44:01 UTC, John Colvin wrote:
 On Monday, 20 July 2015 at 18:17:18 UTC, Adam D. Ruppe wrote:
 Quick, what does this loop in this function do?

 void PanelBar::RepositionExpandedPanels(Panel* fixed_panel)


 I'm willing to guess it repositions the expanded panels.... 
 named functions are the best abstraction.
That's great for an API user, but it's not as massively impactful for actually getting the code right, changing the code, finding the bugs in the code, etc... where you need to actually need to understand the logic.
P.s. which is not to say that sensibly breaking code in to functions with good names doesn't help with the above, but just that it doesn't cover all of the same problems that e.g. ranges/algorithms try to address.
Jul 20 2015
prev sibling next sibling parent "Joakim" <dlang joakim.fea.st> writes:
On Monday, 20 July 2015 at 17:26:31 UTC, Matt Kline wrote:
 With the general push to make more of Phobos use lazily 
 evaluated ranges, Walter's DConf talk, and even C++ moving 
 towards ranges (https://www.youtube.com/watch?v=uXBcwcF3ln4), I 
 wrote a small article with a case study examining their merits.

 http://bitbashing.io/be-lazy-use-ranges.html

 The target audience is largely those unfamiliar with ranges 
 (and to a certain extent, D), but I welcome any and all 
 feedback.
Nice, well-written piece, says something about reddit that it's not popular on there.
Jul 20 2015
prev sibling parent reply "Kagamin" <spam here.lot> writes:
On Monday, 20 July 2015 at 17:26:31 UTC, Matt Kline wrote:
 http://bitbashing.io/be-lazy-use-ranges.html
You assign off_t to size_t, won't compile on 32-bit system. You're safe to use simple `long` for file sizes and offsets.
Jul 21 2015
parent "Matt Kline" <matt bitbashing.io> writes:
On Tuesday, 21 July 2015 at 14:34:25 UTC, Kagamin wrote:
 You assign off_t to size_t, won't compile on 32-bit system. 
 You're safe to use simple `long` for file sizes and offsets.
Nice catch! I'll clean that up after work.
Jul 21 2015