www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is D so powerfull ??

reply BSaidus <bsaidus gmail.com> writes:
Hello!
I've heard about Dlang 2 years ago, and I discovered it about 3 
days.
So
   * I wonder if it is so powerfull as C ?
   * Is it portable (crosse plateform) ?
   * Can I do anything with it ?
Excuse me for for these questionsn i'm a begginer.
   It seems that I begin like it so, reconforte me please !!

Thanks.
Nov 07 2015
next sibling parent reply Daniel Kozak via Digitalmars-d <digitalmars-d puremagic.com> writes:
Dne 7. 11. 2015 13:50 napsal u=C5=BEivatel "BSaidus via Digitalmars-d" <
digitalmars-d puremagic.com>:
 Hello!
 I've heard about Dlang 2 years ago, and I discovered it about 3 days.
 So
   * I wonder if it is so powerfull as C ?
Yes
   * Is it portable (crosse plateform) ?
Yes
   * Can I do anything with it ?
Yes :)
 Excuse me for for these questionsn i'm a begginer.
   It seems that I begin like it so, reconforte me please !!

 Thanks.
Nov 07 2015
parent BSaidus <bsaidus gmail.com> writes:
On Saturday, 7 November 2015 at 13:01:33 UTC, Daniel Kozak wrote:
 Dne 7. 11. 2015 13:50 napsal uživatel "BSaidus via 
 Digitalmars-d" < digitalmars-d puremagic.com>:
 Hello!
 I've heard about Dlang 2 years ago, and I discovered it about 
 3 days.
 So
   * I wonder if it is so powerfull as C ?
Yes
   * Is it portable (crosse plateform) ?
Yes
   * Can I do anything with it ?
Yes :)
 Excuse me for for these questionsn i'm a begginer.
   It seems that I begin like it so, reconforte me please !!

 Thanks.
Waw !! I'm happy for the speed of response, Communauty so active ! THanks !
Nov 07 2015
prev sibling next sibling parent reply ZombineDev <valid_email he.re> writes:
On Saturday, 7 November 2015 at 12:49:18 UTC, BSaidus wrote:
 Hello!
 I've heard about Dlang 2 years ago, and I discovered it about 3 
 days.
 So
   * I wonder if it is so powerfull as C ?
   * Is it portable (crosse plateform) ?
   * Can I do anything with it ?
 Excuse me for for these questionsn i'm a begginer.
   It seems that I begin like it so, reconforte me please !!

 Thanks.
D is very well supported on the major desktop platforms (Windows, Linux, OSX, FreeBSD) and there's currently work in progress to bring D to mobile (iOS and Android). Apart from the reference DMD compiler, there are two other compilers that share the same frontend, but use GCC's and LLVM's backend (GDC and LDC respectively). There is work being done on those compilers to extend D's reach to the support of their C++ counterparts (e.g. embedded ARM, MIPS, etc.). Because D's builtin types have fixed size (unlike the varying size of e.g. C's int and long on various platforms), its ABI is more easier to work with. D's very strong support for conditional compilation makes abstracting platform specific code easier than in C++. You can do in D anything that you can in C, so D is at least as powerful as C is. Actually, the D is much more powerful than C, because the support for this style of programming is only a small part of D. C procedural system programming (pointer arithmetic, void*, function pointers, malloc, realloc, alloca, free, unions, alignment control, static and dynamic linking with C programs and libraries, system calls, etc.) Using these features, some assembly bootstrap and a linker script you can make a bare-bones micro kernel. (reference types), polymorphism, encapsulation, run-time type information, nested/inner classes, anonymous classes, exceptions, GC, etc.) Using these features you can develop any library or C++ style programming (structs (value types), RAII, operator overloading, low-perf cost thin abstractions, const, templates, containers, allocators, smart pointers, similar to STL algorithms, nothrow, nogc, etc) Functional programming (immutability, purity, lambda/anonymous/nested functions, tuples, lazy algorithms, function pipelining with UFCS, etc) http://klickverbot.at/blog/2012/05/purity-in-d/ http://dlang.org/phobos/std_functional.html http://blog.thecybershadow.net/2014/03/21/functional-image-processing-in-d/ http://wiki.dlang.org/Component_programming_with_ranges http://www.mmartins.me/view/2015/09/27/vector-swizzle-in-d Design by contract: http://dlang.org/contracts.html Metaprogramming, Compile-time function execution (CTFE): I don't know if there's a definite tutorial specifically on one D's strongest features, but here's some links to check: dlang.org/phobos/std_traits dlang.org/phobos/std_typecons https://www.youtube.com/watch?v=mCrVYYlFTrA - Desing by introspection https://www.youtube.com/watch?v=SqeOPLB2xAM - Declarative programming in D https://www.youtube.com/watch?v=xpImt14KTdc - Simplifying Code With Compile-Time Reflection If you are looking for a more complete overview of D's features, you can check this feature comparison page: http://dlang.org/comparison.html What standard C does not provide and D does: calling C++ free functions nested in namespaces, creating objects of C++ classes (with single inheritance)
Nov 07 2015
parent reply ZombineDev <valid_email he.re> writes:
On Saturday, 7 November 2015 at 14:25:01 UTC, ZombineDev wrote:
 What standard C does not provide and D does: calling C++ free 
 functions nested in namespaces, creating objects of C++ classes 
 (with single inheritance), ...
... calling virtual and non-virtual methods on C++ classes from D, calling from C++ on D classes, Objective-C support, ... basically you don't have technical reasons not to use D :D You can find more information on interoperability and low-level control here: Interfacing C: http://dlang.org/interfaceToC.html Interfacing C++: http://dlang.org/cpp_interface.html Interfacing Objective-C: http://dlang.org/objc_interface.html D ABI: http://dlang.org/abi.html D inline assembly: http://dlang.org/iasm.html, D vector extentions (SIMD): http://dlang.org/simd.html GDC - GCC specific assembly and intrinsics: http://wiki.dlang.org/GDC/Using_GDC#Extensions LDC - LLVM specific assembly and intrinsics: http://wiki.dlang.org/LDC_inline_assembly_expressions http://wiki.dlang.org/LDC-specific_language_changes
Nov 07 2015
next sibling parent reply Jeremy DeHaan <dehaan.jeremiah gmail.com> writes:
On Saturday, 7 November 2015 at 14:49:05 UTC, ZombineDev wrote:
 On Saturday, 7 November 2015 at 14:25:01 UTC, ZombineDev wrote:
 What standard C does not provide and D does: calling C++ free 
 functions nested in namespaces, creating objects of C++ 
 classes (with single inheritance), ...
... calling virtual and non-virtual methods on C++ classes from D
Actually, you can only call virtual methods on classes. Using non-virtual methods isn't supported.
Nov 07 2015
parent reply ZombineDev <valid_email he.re> writes:
On Saturday, 7 November 2015 at 21:02:26 UTC, Jeremy DeHaan wrote:
 On Saturday, 7 November 2015 at 14:49:05 UTC, ZombineDev wrote:
 On Saturday, 7 November 2015 at 14:25:01 UTC, ZombineDev wrote:
 What standard C does not provide and D does: calling C++ free 
 functions nested in namespaces, creating objects of C++ 
 classes (with single inheritance), ...
... calling virtual and non-virtual methods on C++ classes from D
Actually, you can only call virtual methods on classes. Using non-virtual methods isn't supported.
Why do you think so? See: https://gist.github.com/ZombineDev/19f966273b4a82a5c2f1 Output: $ g++ --version g++ (Ubuntu 4.9.2-10ubuntu13) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ dmd --version DMD64 D Compiler v2.069.0-b2 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright $ ./build.sh $ ./d_class cpp.add(40, 2): 42 cpp.mul(1.5, 2f, 'B') 198 $ ./cpp_main d.add(7, 8): 15 d.mul(3.0, 2.0f, 'A'): 390
Nov 08 2015
parent reply Jeremy DeHaan <dehaan.jeremiah gmail.com> writes:
On Sunday, 8 November 2015 at 23:43:42 UTC, ZombineDev wrote:
 On Saturday, 7 November 2015 at 21:02:26 UTC, Jeremy DeHaan 
 wrote:
 On Saturday, 7 November 2015 at 14:49:05 UTC, ZombineDev wrote:
 On Saturday, 7 November 2015 at 14:25:01 UTC, ZombineDev 
 wrote:
 What standard C does not provide and D does: calling C++ 
 free functions nested in namespaces, creating objects of C++ 
 classes (with single inheritance), ...
... calling virtual and non-virtual methods on C++ classes from D
Actually, you can only call virtual methods on classes. Using non-virtual methods isn't supported.
Why do you think so? See: https://gist.github.com/ZombineDev/19f966273b4a82a5c2f1 Output: $ g++ --version g++ (Ubuntu 4.9.2-10ubuntu13) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ dmd --version DMD64 D Compiler v2.069.0-b2 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright $ ./build.sh $ ./d_class cpp.add(40, 2): 42 cpp.mul(1.5, 2f, 'B') 198 $ ./cpp_main d.add(7, 8): 15 d.mul(3.0, 2.0f, 'A'): 390
Because that's what this page says: http://dlang.org/cpp_interface.html It's about halfway down, but here's the section I am referring to says: Note: non-virtual functions, and static member functions, cannot be accessed. That's awesome if I am wrong, but that is what the C++ interfacing page says. Declaring it as a struct in D code is freaking genius. I wonder if that works across the board with other compilers and OS's though.
Nov 08 2015
parent reply Daniel Murphy <yebbliesnospam gmail.com> writes:
On 9/11/2015 4:05 PM, Jeremy DeHaan wrote:
 Because that's what this page says:
 http://dlang.org/cpp_interface.html
That page is out of date. Virtual and non-virtual member functions, static member functions, and free functions all work since ~2.066. The biggest missing thing is special member functions, ie ctor/dtor/operators.
 Declaring it as a struct in D code is freaking genius. I wonder if
 that works across the board with other compilers and OS's though.
Mixing struct/class will only work properly with ABIs that mangle them the same way, so it's not portable.
Nov 08 2015
parent reply Jeremy DeHaan <dehaan.jeremiah gmail.com> writes:
On Monday, 9 November 2015 at 05:16:50 UTC, Daniel Murphy wrote:
 On 9/11/2015 4:05 PM, Jeremy DeHaan wrote:
 Because that's what this page says:
 http://dlang.org/cpp_interface.html
That page is out of date. Virtual and non-virtual member functions, static member functions, and free functions all work since ~2.066. The biggest missing thing is special member functions, ie ctor/dtor/operators.
 Declaring it as a struct in D code is freaking genius. I
wonder if
 that works across the board with other compilers and OS's
though. Mixing struct/class will only work properly with ABIs that mangle them the same way, so it's not portable.
We should really update that page then. What is the correct way to use C++ class instances in D? Can you by chance give an example?
Nov 08 2015
parent reply Daniel Murphy <yebbliesnospam gmail.com> writes:
On 9/11/2015 4:26 PM, Jeremy DeHaan wrote:
 What is the correct way to use C++ class instances in D? Can you by
 chance give an example?
extern (C++) class X { ... } extern (C++) void func(X x); void main(string[] args) { func(new X()); } etc
Nov 08 2015
parent reply Jeremy DeHaan <dehaan.jeremiah gmail.com> writes:
On Monday, 9 November 2015 at 06:27:22 UTC, Daniel Murphy wrote:
 On 9/11/2015 4:26 PM, Jeremy DeHaan wrote:
 What is the correct way to use C++ class instances in D? Can 
 you by
 chance give an example?
extern (C++) class X { ... } extern (C++) void func(X x); void main(string[] args) { func(new X()); } etc
Didn't you say constructors and destructors are missing? What should one do in those cases?
Nov 08 2015
parent reply Jeremy DeHaan <dehaan.jeremiah gmail.com> writes:
On Monday, 9 November 2015 at 06:51:03 UTC, Jeremy DeHaan wrote:
 On Monday, 9 November 2015 at 06:27:22 UTC, Daniel Murphy wrote:
 On 9/11/2015 4:26 PM, Jeremy DeHaan wrote:
 What is the correct way to use C++ class instances in D? Can 
 you by
 chance give an example?
extern (C++) class X { ... } extern (C++) void func(X x); void main(string[] args) { func(new X()); } etc
Didn't you say constructors and destructors are missing? What should one do in those cases?
Additionally, should we use new in this case? Wouldn't new create a pointer to a C++ class? Or does it work differently for extern(c++) classes?
Nov 08 2015
parent Daniel Murphy <yebbliesnospam gmail.com> writes:
On 9/11/2015 5:54 PM, Jeremy DeHaan wrote:

 Didn't you say constructors and destructors are missing? What should
 one do in those cases?
Constructors and destructors do not match the C++ ABI, but they are still generated, so they can only be called from the language they were written in. So if you write your classes in D you must new and delete (or GC) them from D. You can still create them from C++ (or create C++-written classes from D) if you use a forwarding function: X makeX() { return new X(); }
 Additionally, should we use new in this case? Wouldn't new create a
 pointer to a C++ class? Or does it work differently for extern(c++)
 classes?
New in D will allocate a class instance on the GC heap and return a reference to it, just like when it's used with D classes. These two functions have the same ABI: // D extern(C++) class X {} extern(C++) void func(X x); // C++ class X {} void func(X *x); You can find several examples of C++ interop in dmd's test\runnable\cppa.d
Nov 08 2015
prev sibling parent reply FreeSlave <freeslave93 gmail.com> writes:
On Saturday, 7 November 2015 at 14:49:05 UTC, ZombineDev wrote:
 basically you don't have technical reasons not to use D :D
What about the lack of proper support for dynamic libraries on Windows and OSX? I mean, GC merging is still not implemented, right?
Nov 08 2015
parent reply TheFlyingFiddle <kurtyan student.chalmers.se> writes:
On Sunday, 8 November 2015 at 10:22:44 UTC, FreeSlave wrote:
 On Saturday, 7 November 2015 at 14:49:05 UTC, ZombineDev wrote:
 basically you don't have technical reasons not to use D :D
What about the lack of proper support for dynamic libraries on Windows and OSX? I mean, GC merging is still not implemented, right?
Pretty sure gc merging is done via the gc proxy in dlls/shared libraries. But there are lot's of other problems. Mainly that Phobos cannot be dynamically loaded (or is this fixed?) Last time i tried throwing exceptions did not work either. Also the export problems on windows have not really been fixed (see http://wiki.dlang.org/DIP45). Still I have used DLL's sucessfully for reloading plugins, it can be done but it's really a pain to use as it stands now.
Nov 08 2015
parent David Nadlinger <code klickverbot.at> writes:
On Sunday, 8 November 2015 at 17:51:34 UTC, TheFlyingFiddle wrote:
 Pretty sure gc merging is done via the gc proxy in dlls/shared 
 libraries.
In the case of Linux/FreeBSD shared libraries, there is no merging to be done, as only one copy of the GC exists in the first place (we only support shared libraries when druntime is built as a shared library itself). — David
Nov 08 2015
prev sibling parent Gary Willoughby <dev nomad.so> writes:
On Saturday, 7 November 2015 at 12:49:18 UTC, BSaidus wrote:
 Excuse me for for these questionsn i'm a begginer.
   It seems that I begin like it so, reconforte me please !!

 Thanks.
If you have anymore questions while learning D please visit our dedicated newsgroup/forum for learning: http://forum.dlang.org/group/learn
Nov 07 2015