Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 05, 2013 D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Dear All, I searched internet also I searched this forum for D Language gotchas. In this forum, I found a thread which is from 2005 and I do not know latest updates on that. My question is that - "Are there known programming gotchas of D language ?" If will be grateful if I get some pointers. Regards, Sumit |
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sumit Adhikari | On Tuesday, 5 November 2013 at 02:59:55 UTC, Sumit Adhikari wrote: > > > Dear All, > > I searched internet also I searched this forum for D Language gotchas. In this forum, I found a thread which is from 2005 and I do not know latest updates on that. > > My question is that - "Are there known programming gotchas of D language ?" > We have probably enough to create an OuOfMemooryError in your browser. > If will be grateful if I get some pointers. > GC.alloc will give you plenty :D Seriously, you gotta limit somehow the scope of that question. |
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sumit Adhikari | On Tuesday, 5 November 2013 at 02:59:55 UTC, Sumit Adhikari wrote: > I searched internet also I searched this forum for D Language gotchas. In this forum, I found a thread which is from 2005 and I do not know latest updates on that. > > My question is that - "Are there known programming gotchas of D language ?" > > If will be grateful if I get some pointers. There are various gotchas due to bugs in the frontend, but they get fixed (slowly). You can browse the bug tracker. Some "gotchas" are just assumptions people have coming from other programming languages (slices behavior, floating point, etc). My pragmatic tutorial [0] tries to guide you around those. Some aspects of D are bad in hindsight, but will not be fixed in the near future due to backwards compatability. For example, @safe and pure should probably have been the defaults instead of extra annotations. [0] http://qznc.github.io/d-tut/ |
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sumit Adhikari | I think, all languages have more gotchas than features, because features are designed for certain scenarios, so they are likely to not play as well in other scenarios, probably more numerous. |
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sumit Adhikari | On Tuesday, 5 November 2013 at 02:59:55 UTC, Sumit Adhikari wrote:
>
>
> Dear All,
>
> I searched internet also I searched this forum for D Language gotchas. In this forum, I found a thread which is from 2005 and I do not know latest updates on that.
>
> My question is that - "Are there known programming gotchas of D language ?"
>
> If will be grateful if I get some pointers.
>
> Regards, Sumit
One gotcha relates to enums. Writing `enum a = [0, 1, 2]` is a really bad idea, because everywhere you use a, it constructs a new array at runtime. The [0, 1, 2] is "pasted in", and you'll have a bunch of allocations you didn't expect. This doesn't just happen with arrays, but that's the most common case. What *is* okay is using string enums, as strings are a bit special due to being immutable.
|
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On 2013-11-05 12:16, Meta wrote: > One gotcha relates to enums. Writing `enum a = [0, 1, 2]` is a really > bad idea, because everywhere you use a, it constructs a new array at > runtime. The [0, 1, 2] is "pasted in", and you'll have a bunch of > allocations you didn't expect. This doesn't just happen with arrays, but > that's the most common case. What *is* okay is using string enums, as > strings are a bit special due to being immutable. Isn't the problem rather that [0, 1, 2] allocates in the first place, regardless if an enum is used or not. -- /Jacob Carlborg |
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg |
One big gotcha of this forum is that when I reply I will have to reply only one person and hence I cannot thank everybody using one mail!
Indeed I am happy that I have some pointers and I thank everybody for participation. My need was to create a qualitative analysis document for the case of one out of three languages - D, C++ and something-else.
I will investigate more and come back to you people if I am stuck.
Regards, Sumit
On Tuesday, 5 November 2013 at 12:27:55 UTC, Jacob Carlborg wrote:
> On 2013-11-05 12:16, Meta wrote:
>
>> One gotcha relates to enums. Writing `enum a = [0, 1, 2]` is a really
>> bad idea, because everywhere you use a, it constructs a new array at
>> runtime. The [0, 1, 2] is "pasted in", and you'll have a bunch of
>> allocations you didn't expect. This doesn't just happen with arrays, but
>> that's the most common case. What *is* okay is using string enums, as
>> strings are a bit special due to being immutable.
>
> Isn't the problem rather that [0, 1, 2] allocates in the first place, regardless if an enum is used or not.
|
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Tuesday, 5 November 2013 at 12:27:55 UTC, Jacob Carlborg wrote:
> On 2013-11-05 12:16, Meta wrote:
>
>> One gotcha relates to enums. Writing `enum a = [0, 1, 2]` is a really
>> bad idea, because everywhere you use a, it constructs a new array at
>> runtime. The [0, 1, 2] is "pasted in", and you'll have a bunch of
>> allocations you didn't expect. This doesn't just happen with arrays, but
>> that's the most common case. What *is* okay is using string enums, as
>> strings are a bit special due to being immutable.
>
> Isn't the problem rather that [0, 1, 2] allocates in the first place, regardless if an enum is used or not.
It's a combination of [0, 1, 2] allocating and enum a = [0, 1, 2] not doing what you think it does (defining a variable instead of just copying and pasting).
|
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sumit Adhikari | On Tuesday, 5 November 2013 at 13:07:26 UTC, Sumit Adhikari wrote: > Indeed I am happy that I have some pointers and I thank everybody for participation. My need was to create a qualitative analysis document for the case of one out of three languages - D, C++ and something-else. You can search for bearophile's enhancement requests in bugzilla. They are often aimed at improving D design with respect to C legacy, which D has a little. One example is http://d.puremagic.com/issues/show_bug.cgi?id=4077 |
November 05, 2013 Re: D Language Gotchas | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | Kagamin: > One example is http://d.puremagic.com/issues/show_bug.cgi?id=4077 Some better examples: http://d.puremagic.com/issues/show_bug.cgi?id=5409 http://d.puremagic.com/issues/show_bug.cgi?id=3827 http://d.puremagic.com/issues/show_bug.cgi?id=8757 ... Bye, bearophile |
Copyright © 1999-2021 by the D Language Foundation