|
the D programming language |
ImLeftFooted
Member #3,935
October 2003
|
I'm a bit late (so this might have been answered) but I'll push my luck anyway. Quote: Does C++ have an equivalent for this? void templateFunc(T) (T value) { static if (value.typeof.stringof == "int") // sorry if there's a better way to express this { writefln("Hello!"); } } templateFunc(1000); // prints Hello templateFunc("Hi"); // nothing
Yes but its quite ugly and only works for classes. Theoretically you really don't need it for functions because of function overloading. Quote: (Obviously, you could overload the function in C++, but my example is trivial on purpose.) Can you do that with the preprocessor and templates in C++? I'll make some example code (not tested and probably doesn't compile). Obviously just doing overloaded functions is preferred here, but we're trying to show what templates can do.
|
Billybob
Member #3,136
January 2003
|
ML and relpatseht, thanks for looking that up. Nice to know it has multi-threaded capability as well. Maybe I'll try to build a game with it some time in the future.
|
Thomas Fjellstrom
Member #476
June 2000
|
If it wasn't for wanting to use Qt in a few apps, I would so jump to D asap. -- |
MiquelFire
Member #3,110
January 2003
|
I'm with Thomas. Matter of fact, I just made a first release of a QT app I was working on. Has some features to go before a 1.0 release however. --- |
nonnus29
Member #2,606
August 2002
|
Yeah, I'm thinking of switching my compiler to D now... Thanks alot ML Walter Bright presentation: http://video.google.com/videoplay?docid=-7073020265668105471 |
Myrdos
Member #1,772
December 2001
|
The two show stoppers for me are speed and library support. My understanding is that C++ tries to go as high level as possible without sacrificing speed. That is to say, a well-written C++ program should be 99% as fast as a C program. Can D get the speed without the ugly syntax? It takes quite a bit of skill to use C++ well, and a mediocre programmer is going to pooch it. The hideous things my eyes have seen, modifying other people's programs. To me, a simpler language equals more robust code, because it takes less thinking to make good design decisions. In fact, Bjarne Stroustrup seems to agree with ML. Quote: "Within C++, there is a much smaller and cleaner language struggling to get out". Yes, that quote can be found on page 207 of The Design and Evolution of C++. And no, that smaller and cleaner language is not Java or C#. The quote occurs in a section entitled "Beyond Files and Syntax". I was pointing out that the C++ semantics is much cleaner than its syntax. If D can give me the semantics and speed of C++ with cleaner style, I'd consider switching. [EDIT] Erm, the Digital Mars compiler is proprietary, that will slow adoption in the Linux realm. Plus, it only supports 32-bit systems. The GDC compiler is version 0.23 alpha, and only has one developer. I guess I'll give D a few years to mature. __________________________________________________ |
HoHo
Member #4,534
April 2004
|
Quote: If it wasn't for wanting to use Qt in a few apps, I would so jump to D asap. Exactly the same here. I've been playing with QT for a few months now and I must say there is no other GUI toolkit as good that I've seen so far. I've also been reading a bit about D and it looks rather nice. Too bad those two things can't work together. Of cource the compiler being a bit too new doesn't help too much either. __________ |
Matthew Leverton
Supreme Loser
January 1999
|
Walter Bright's official D compiler is post version 1.0 and quite stable. I think it's about 10 years in the making. He has even a longer history with developing compilers, as the author of Zortech/Symantec C++. In fact, most languages have been the works of a single individual. The Java and .NET stuff are pretty much exceptions to that. His compiler already performs basically as good as C++ (sometimes better, sometimes worse - depends on the benchmark), so I really don't think it's a good reason to avoid the language altogether. I really suggest that curious people read the D overview, as it's quite informative and honest. Oh, and Python fans might want to look at pyd. It lets you run compiled D modules from within Python. |
Kitty Cat
Member #2,815
October 2002
|
I'll wait 'til it can interface C++ code. My current work has been around COM stuff (*shudders*), and C++ makes implementing interfaces very slick. Without C++, I'd have to do it the C way, which is just ugly. And am I the only one that doesn't like languages trying to hide pointers? I don't even like using non-const references because it gets confusing to know which variable changes would persist out of the function and which won't.. -- |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: And am I the only one that doesn't like languages trying to hide pointers? I hate half ass-ed languages. Either its hidden all the time, or never. Either its completely high level, or as low level a high level language can get (ie: C). I find C++ tries to be too much, and fails miserably. Heh, along with the C++ operation, C++ evaluates to C, making it a no-op as far as the useable return result is concerned. It tries to be more, but didn't quite make it -- |
CGamesPlay
Member #2,559
July 2002
|
My new language, ++C, won't have that problem. -- Ryan Patterson - <http://cgamesplay.com/> |
Sevalecan
Member #4,686
June 2004
|
Quote: And am I the only one that doesn't like languages trying to hide pointers? I don't even like using non-const references because it gets confusing to know which variable changes would persist out of the function and which won't.. No, I'm with you. TeamTerradactyl: SevalecanDragon: I should shoot you for even CONSIDERING coding like that, but I was ROFLing too hard to stand up. I love it! |
bamccaig
Member #7,536
July 2006
|
KittyCat said: And am I the only one that doesn't like languages trying to hide pointers? I don't even like using non-const references because it gets confusing to know which variable changes would persist out of the function and which won't..
Sevalecan Dragon said: No, I'm with you. Me too... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Samuel Henderson
Member #3,757
August 2003
|
KittyCat said: And am I the only one that doesn't like languages trying to hide pointers? I don't even like using non-const references because it gets confusing to know which variable changes would persist out of the function and which won't..
Sevalecan Dragon said: No, I'm with you.
bamccaig said: Me too... Me as well. ================================================= |
Myrdos
Member #1,772
December 2001
|
Quote: His compiler already performs basically as good as C++ (sometimes better, sometimes worse - depends on the benchmark), so I really don't think it's a good reason to avoid the language altogether. Minor problem: I develop Linux software. Using a proprietary compiler will reduce the popularity of my programs. Major problem: My computers are 64 bit. __________________________________________________ |
Matthew Leverton
Supreme Loser
January 1999
|
64-bit support is obviously a valid issue, but it being "proprietary" is just an excuse. Quote: The front end for D is open source, and the source comes with the compiler. The runtime library is completely open source. David Friedman has integrated the D frontend with GCC to create gdc, a completely open source implementation of D. Honestly, I don't care if someone is too stuck up to download a free, open-source compiler because it's not part of their precious GPL commune. Those aren't the type of people likely to buy software anyway, so it's not like your commercial success will be hampered. Quote: And am I the only one that doesn't like languages trying to hide pointers? I don't even like using non-const references because it gets confusing to know which variable changes would persist out of the function and which won't.. I think that is spoken like a true C/C++ fan. I don't mean that in a bad way, but using a certain method for a while makes you start thinking it's the best way. If C++ and D both came out yesterday, I think basically everybody would choose D. However, now that you've used C/C++ for a while, you become partial to it and anything D does differently seems wrong. Personally, I think that D's system is far less confusing than C++'s. It works the way I expect it to, without all the ugly pointer syntax. (In fact, even C++ tries to hide away pointers ... that's what references do.) But D's system wasn't as big of a shock to me, coming from language (like PHP) that automatically handle pointers as well. Obviously if the language does a poor, inconsistent job with replacing pointers, then it's something to be concerned about. Edit: An example to show how D handles it:
That would print "1 Hello, World Foo". If I wanted the code to "work," I'd have to explicitly use the ref keyword, similar to C++'s & symbol. However, dynamic arrays and objects are always pointers. That behavior is constant, so you never "don't know." For instance:
The above would output "Test", because all objects are pointers. If you really wanted to pass a copy of an object you have to explicitly do so on either end using the 'dup' property. changeFoo(z.dup, "Test"); // wouldn't change z
|
Billybob
Member #3,136
January 2003
|
Quote:
Quote: And am I the only one that doesn't like languages trying to hide pointers? I don't even like using non-const references because it gets confusing to know which variable changes would persist out of the function and which won't.. Yes, I'm against you. Fixed.
|
bamccaig
Member #7,536
July 2006
|
Matthew Leverton said:
char[] y = "Hello, World"; Foo z = new Foo("Foo");
Matthew Leverton said:
setNullInt(x); setNullString(y); setNullObj(z);
Matthew Leverton said: That would print "1 Hello, World Foo".
Matthew Leverton said: However, dynamic arrays and objects are always pointers. That behavior is constant, so you never "don't know." I think I'm confused... To be honest, the only thing I really have against D is the name... If I'm gonna start using it the language needs to be renamed... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Thomas Fjellstrom
Member #476
June 2000
|
Pointers work the same in D as in C, its passed in by value, so any setting of the pointer in the function sets a local one, but if you dereference the pointer (foo[1] = bar), you then set the contents. -- |
Myrdos
Member #1,772
December 2001
|
ML said: Honestly, I don't care if someone is too stuck up to download a free, open-source compiler because it's not part of their precious GPL commune. Digital Mars license said: The Software is copyrighted and comes with a single user license, and may not be redistributed. What I meant was that Linux distributions won't be able to package the D compiler and include it in their repository. Therefore, they won't package any software written with D. Compiling software from source in binary-package distributions can be hit or miss because of missing dependencies. For example, if Allegro were written in D, the average user wouldn't be able to install it in Ubuntu*. You'd have to make a list of all the dependencies and tweaks for every Linux distribution separately. However, this issue only affects Linux users. Windows and Mac folk can get the executable.
__________________________________________________ |
bamccaig
Member #7,536
July 2006
|
Thomas Fjellstrom said: Pointers work the same in D as in C, its passed in by value, so any setting of the pointer in the function sets a local one, but if you dereference the pointer (foo[1] = bar), you then set the contents. I see... For a language with no actual pointer syntax I would think it would be pass by reference and not address. That sounds less than clean for strings (char[]) then... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: I see... That sounds less than clean for strings (char[]) then... Reading the docs would help you from looking like a fool, but because I know you won't, here you go: string[] = someotherstring; -- |
bamccaig
Member #7,536
July 2006
|
As I said earlier, I don't have time to learn about D right now. That's what a thread like this is for. For those that are reading up on it to update the rest of us who are busy with other things. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Kitty Cat
Member #2,815
October 2002
|
Quote: If I wanted the code to "work," I'd have to explicitly use the ref keyword, similar to C++'s & symbol.
And as I mention, using non-const &/references makes it confusing too, since there's no indication in the function that you're doing "more permanent" changes. With a proper pointer you'd have to do Quote: However, dynamic arrays and objects are always pointers. That behavior is constant, so you never "don't know." For instance: If you have a large-ish function where you can't easilly check the variable's declaration, it's easy to miss or not know. Having to be explicit about dereferencing makes it easier to see that you're modifying memory from elsewhere. -- |
Matthew Leverton
Supreme Loser
January 1999
|
Quote: For a language with no actual pointer syntax It does have pointers, it's just that you don't really ever need to use it. For instance:
That prints "2, 42" as you would expect. Remember that it can interface directly with C, so it has to let you do stuff like that. Quote: Having to be explicit about dereferencing makes it easier... I disagree, but at some level, it's just personal taste. I'd rather know I always have to do object.bar; I can very easily look at the function "prototype" to determine what's going to happen. |
|
|