March 12, 2015 Re: moving from c++ to D is easy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ayush | On 03/12/2015 06:01 AM, ayush wrote: > Is D a lot like c++ ? I came to D from C++. I remember the following being notable differences: - In D, classes have reference semantics. I quickly realized that this is not an issue because so many of my C++ types were hand-reference-typified :p by this idiom, almost everywhere: class C { /* ... */ }; typedef boost::shared_ptr<C> CPtr; void foo(CPtr c); - Garbage collector took longer to get used to. There are some issues with the spec or implementation that some objects may never be destructed (or is it finalized?). Other than issues like that, everything in D feels like a fresh air. > I am currently midway through learning c++ If you are a mortal like myself, you may find out years later that you are still at the midway point. Happened to me several times when I was learning C++. :) > and I also want to learn D . So should i focus on one or learn > both together? Economically, C++ may make more sense. But if you are learning just for yourself, perhaps for fun, then I recommend D. > Will I find learning D easy if I already know c++ ? I think so. Ali |
March 12, 2015 Re: moving from c++ to D is easy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote:
>If you are a mortal like myself, you may find out years later that you are still at the midway point. Happened to me several times when I was learning C++. :)
О, yeah.
|
March 12, 2015 Re: moving from c++ to D is easy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote:
> On 03/12/2015 06:01 AM, ayush wrote:
>
> > Is D a lot like c++ ?
>
> I came to D from C++. I remember the following being notable differences:
>
> - In D, classes have reference semantics. I quickly realized that this is not an issue because so many of my C++ types were hand-reference-typified :p by this idiom, almost everywhere:
>
> class C { /* ... */ };
> typedef boost::shared_ptr<C> CPtr;
> void foo(CPtr c);
This is a common mistake. In 99 percent of cases you want to use a std::unique_ptr. std::shared_ptr is rarely common and often an indication of an error in design. In general, there is exactly one owner only.
But I think you know that already. :)
|
March 12, 2015 Re: moving from c++ to D is easy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On 03/12/2015 01:19 PM, Namespace wrote: > On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote: >> On 03/12/2015 06:01 AM, ayush wrote: >> >> > Is D a lot like c++ ? >> >> I came to D from C++. I remember the following being notable differences: >> >> - In D, classes have reference semantics. I quickly realized that this >> is not an issue because so many of my C++ types were >> hand-reference-typified :p by this idiom, almost everywhere: >> >> class C { /* ... */ }; >> typedef boost::shared_ptr<C> CPtr; >> void foo(CPtr c); > > This is a common mistake. In 99 percent of cases you want to use a > std::unique_ptr. Agreed. Here is an excerpt from a comment from one of our header files: "We could not use boost::unique_ptr because the version of the Boost library that we currently use does not include it." > std::shared_ptr is rarely common and often an indication of an > error in design. In general, there is exactly one owner only. Of course. We had definitions like the following as well, where the C objects are stored in: typedef vector<CPtr> MyCs; > But I think you know that already. :) I think so. :) Maybe we should pass weak_ptrs around instead of shared_ptr. Anyway... That's old code and this is a D newsgroup. Ali |
March 12, 2015 Re: moving from c++ to D is easy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Thursday, 12 March 2015 at 21:41:07 UTC, Ali Çehreli wrote: > On 03/12/2015 01:19 PM, Namespace wrote: > > > On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote: > >> On 03/12/2015 06:01 AM, ayush wrote: > >> > >> > Is D a lot like c++ ? > >> > >> I came to D from C++. I remember the following being notable > differences: > >> > >> - In D, classes have reference semantics. I quickly realized > that this > >> is not an issue because so many of my C++ types were > >> hand-reference-typified :p by this idiom, almost everywhere: > >> > >> class C { /* ... */ }; > >> typedef boost::shared_ptr<C> CPtr; > >> void foo(CPtr c); > > > > This is a common mistake. In 99 percent of cases you want to > use a > > std::unique_ptr. > > Agreed. Here is an excerpt from a comment from one of our header files: > > "We could not use boost::unique_ptr because the version of the Boost library that we currently use does not include it." > > > std::shared_ptr is rarely common and often an indication of an > > error in design. In general, there is exactly one owner only. > > Of course. We had definitions like the following as well, where the C objects are stored in: > > typedef vector<CPtr> MyCs; > > > But I think you know that already. :) > > I think so. :) Maybe we should pass weak_ptrs around instead of shared_ptr. You could also pass raw pointers around. Since they have no owner it's fine. Or references. > Anyway... That's old code and this is a D newsgroup. > > Ali Agreed. |
Copyright © 1999-2021 by the D Language Foundation