April 22, 2017 Re: Compare boost::hana to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adrian Matoga | On Friday, 21 April 2017 at 19:48:53 UTC, Adrian Matoga wrote:
> On Friday, 21 April 2017 at 12:37:03 UTC, Mike Parker wrote:
>>
>> And I should add (for anyone paying attention), this is exactly the sort of thing I'm looking for more of on the D Blog. Submissions welcome :-)
>
> This, and the generally positive feedback on r and HN are quite motivating. :)
> I have some ideas for more articles but being a non-native English speaker I need a lot of time to make the text look at least understandable, so I usually give up quickly and move on to play with code instead. :)
I'm a native speaker, but I hate writing with a passion, but I found the D community are very forthcoming with suggestions and improvements w.r.t both code and language typos and structure issues.
|
April 23, 2017 Re: Compare boost::hana to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Friday, 21 April 2017 at 13:10:43 UTC, Adam D. Ruppe wrote:
> On Wednesday, 19 April 2017 at 18:02:46 UTC, Adrian Matoga wrote:
>> [2] https://epi.github.io/2017/03/18/less_fun.html
>
> BTW in your D foreach, you could also have done `switch`
>
> void trigger(string event) {
> switch(event) {
> foreach (i, e; events) {
> case e:
> foreach (c; callbacks_[i])
> c();
> return;
> }
> default:
> assert(false, "trying to trigger an unknown event: " ~ event);
> }
> }
>
>
> And the compiler+runtime can optimize that into a binary search when it gets larger automatically.
Doesn't the latest compiler complain with a depreciation that i/e initialization is being skipped?
|
April 23, 2017 Re: Compare boost::hana to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | On 4/23/17 12:22 AM, Jesse Phillips wrote: > On Friday, 21 April 2017 at 13:10:43 UTC, Adam D. Ruppe wrote: >> On Wednesday, 19 April 2017 at 18:02:46 UTC, Adrian Matoga wrote: >>> [2] https://epi.github.io/2017/03/18/less_fun.html >> >> BTW in your D foreach, you could also have done `switch` >> >> void trigger(string event) { >> switch(event) { >> foreach (i, e; events) { >> case e: >> foreach (c; callbacks_[i]) >> c(); >> return; >> } >> default: >> assert(false, "trying to trigger an unknown event: " ~ event); >> } >> } >> >> >> And the compiler+runtime can optimize that into a binary search when >> it gets larger automatically. > > Doesn't the latest compiler complain with a depreciation that i/e > initialization is being skipped? Yep, but it's just a warning. A really annoying warning. https://issues.dlang.org/show_bug.cgi?id=16521 has more details. static foreach + switch can be bad if you ref the elements of the tuple. The "correct" thing to do is: foreach(i, _unused; someTuple) { // use someTuple[i] instead of _unused } You will still get the warning though. -Steve |
April 24, 2017 Re: Compare boost::hana to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Pfau | On Saturday, 22 April 2017 at 07:53:49 UTC, Johannes Pfau wrote:
>
> OT but is there any benefit to identify events with strings? As long as you use compile time only events I'd prefer a syntax as in https://github.com/WebFreak001/EventSystem
>
> (one benefit is that it's 100% IDE autocomplete compatible)
>
> I guess if you want runtime registration of events identifying by name is useful. But then you also somehow have to encode the parameter types to make the whole thing safe...
I agree. Personally, I'd probably also start with something like WebFreak001's ES and only think about how to add run-time dispatch later if I absolutely need it.
|
Copyright © 1999-2021 by the D Language Foundation