Domain: digitalmars.com
Stories and comments across the archive that link to digitalmars.com.
Comments · 230
-
D language
Not directly related to your problem, but just FYI...
http://www.digitalmars.com/d/index.html - D language, free, memory-managed and compiles to native code. Perhaps worth checking out. -
Re:two points
"Finally, there is a motion to include garbage collection in the C++ language. "
Call me old-fashioned, but I hope that's one that they will throw in the garbage. Call it something else if you're going to have garbage collection as an integral part. As a set of libraries, or as a compiler-time switch, fine - but not as part of the core. That's not C++, that's D.
-
portable c++-like language with GC
VMs exist because no one dared to a make a C++ like language that guarantees source-code level compatibility in all platforms and has garbage collection.
See http://digitalmars.com/d
and http://dgcc.sf.net/ -
Re:It needs serious language support
Don't forget the D programming language.
Although rudimentary it does support a limited design-by-contract right in its C-like language. -
Re:Memory
Your list is considerably different than mine would have been. However, I am shifting over to D (Digital Mars D, http://www.digitalmars.com/d/index.html ) as something that fits more closely with what I think C++ should have developed into.
-
Re:It looks like a nice language, but
D fixes this with mixins and interfaces. C/C++ try-catch-throw stuff is lacking several important features. Such as Finaly, and some other nifty features D has. Check http://www.digitalmars.com/d/exception-safe.html
-
Re:Missing the point>> A good language strives to find a few constructs that solve multiple problems.
> D does this.
It does not. Look at it the author's own language comparison and tell me that D doesn't take the kitchen sink approach. The author does not ascribe to the "small number of flexible constructs" philosophy, and he is obviously proud of that.
> You are looking past the dozens of examples where D has cleaned up problems that have been plaguing programmers for years to grasp at a chance to make a piece of code as messy as possible. Maybe you are comfortable working with C/C++ and don't want to deal with another language.
Cleaned up? Not only has D failed to address C++'s complexity, it adds a whole new dimension of pain. Let's consider this piece of code:
someFunction(x, y++);
What can we say about it as C, C++, and D code?
- In C, x and y cannot be modified by someFunction, and y will be increased by 1. We know exactly what values x and y will have afterwards.
- In C++, x may be modified by someFunction (if it takes a reference type), but y cannot be otherwise modified and will be increased by 1. We at least know what value y will have.
- In D, x may be modified by someFunction if it takes an inout type, and y may be increased by 1, 2, 3, 4, or more, or by nothing at all, if someFunction takes a lazy type. We no longer know what value either of those variables has.
See how (needlessly) featureful D is? It is the most confusing and the messiest of the three. This is not a good language.
-
D LOC, bugs vs. C++
When you're writing in EditPlus, it's no easier to write and manage 1m lines of code in D than it is in C++
Although it may be that 1m lines of D code can do more than 1m lines of C++ code:
http://www.digitalmars.com/d/lisp-java-d.html
"For C++, the shortest development time was 3 hours and the shortest program had 107 lines of code."
The D implementation "took me 1 hour and 15 minutes, from reading the statement to finishing the program. The program was just 55 lines long"
Of course, that is just one example, but I think it reveals something about the D language - it was designed to have clearer syntax and to be harder to write common bugs than C++ code.
YMMV. -
Re:Do we really need another D infomercial?
OK, I'm quite willing to be proved wrong here (not least because that would mean that D is a better language IMHO) but I'm going by the way I read the pages of your own web site.
There are two comparison operators to overload, opEquals and opCmp. That's how you do it.
I could understand defining the < and == operators and then inferring the rest, but your opCmp appears to be a <=> concept, indicating less than, equal to or greater than. In that case, if a type supports only strict inequalities but not the concept of equality, how can you implement it as a combination of those operators? If neither a < b nor b < a nor a == b, then how does one represent this?
I'm also curious about how you suppress the implicit equality test for structures, if the contents are not logically equality-comparable according to the program design. Is this any neater than the nasty C++ idioms for suppressing compiler-supplied constructors and assignment operators?
You can declare a class as being a scope class
... and it will automatically and always be RAII.Your own web site's RAII example seems to use the scope keyword twice, once for the class definition and once where it is instantiated. If you can't accidentally write something like the following:
File f = new File();
in D, then I suggest that it would be in your interests to rewrite your explanatory text a little to make this clear.
It also isn't possible to call a member function without the vptr being set up, so the alleged horrible loophole doesn't exist.
So can one constructor call another before initialising all the data members of a class to satisfy the class's invariant conditions, or can't it? If it can, how does any constructor know what's been initialised already and what hasn't when it's called? If it can't, what's the advantage of chaining constructors together like this?
-
Alternative Intro Site for Info - WikiIf you're having some response problems from http://www.digitalmars.com/d/ as it skirts the edge of slashdotting, I found a wiki via dsource.org:
Enjoy!
-
Re:Currently learning D
The compiler generates header files from source files with the -H option. It can decide what code is necessary and what code isn't.
As for mixins, you can get the full scoop and some simple examples in the language spec, specifically the portion on Mixins. -
Re:Lazy Questions
1. Must be able to disable garbage collection and manage allocation explicitly
Yes, using std.gc.enable()/disable(): http://digitalmars.com/d/phobos/std_gc.html. You can still use malloc and friends, even while GC is active.
2. Must be able to allocate classes on the stack
Yes, using the scope keyword: http://www.digitalmars.com/d/memory.html#raii
3. Must minimize use of exceptions in the standard library (in other words, exceptions must only be used for exceptional cases)
Exceptions are common in the standard library. All the ones I have seen seem only for exceptional cases. Define exceptional?
-
Re:Lazy Questions
1. Must be able to disable garbage collection and manage allocation explicitly
Yes, using std.gc.enable()/disable(): http://digitalmars.com/d/phobos/std_gc.html. You can still use malloc and friends, even while GC is active.
2. Must be able to allocate classes on the stack
Yes, using the scope keyword: http://www.digitalmars.com/d/memory.html#raii
3. Must minimize use of exceptions in the standard library (in other words, exceptions must only be used for exceptional cases)
Exceptions are common in the standard library. All the ones I have seen seem only for exceptional cases. Define exceptional?
-
Re:Lazy Questions
These may satisfy your curiosity:
1. You can disable GC entirely, on a per class or per instance basis.
2. Yes, stack classes are easy.
3. I haven't used Phobos in great detail yet, but I haven't encountered anything like Java's exception library.
Hope this helps,
KG -
Re:Do we really need another D infomercial?
some of my reasons for considering d are:
-d is the first powerful language i could learn.
-after i learned d i could learn c usage as well, but not before.
-i've done a text processing program in d in a matter of minutes (well, probably 1h+, whatever) compared to 2-3 nights without sleep (and the corresponding days) in c. it is true that the latter was a 3d OBJ importer, but only i know how hard and messy it was.
-i don't have to fight against pointers anymore;
-i don't like c++, nor java (though i love curly brackets :P).
i think you might give d a try, also check these differences, if you didn't already:
http://digitalmars.com/d/cpptod.html
http://digitalmars.com/d/ctod.html
the readability and logic gives speed to developing.
thanx -
Re:Do we really need another D infomercial?
some of my reasons for considering d are:
-d is the first powerful language i could learn.
-after i learned d i could learn c usage as well, but not before.
-i've done a text processing program in d in a matter of minutes (well, probably 1h+, whatever) compared to 2-3 nights without sleep (and the corresponding days) in c. it is true that the latter was a 3d OBJ importer, but only i know how hard and messy it was.
-i don't have to fight against pointers anymore;
-i don't like c++, nor java (though i love curly brackets :P).
i think you might give d a try, also check these differences, if you didn't already:
http://digitalmars.com/d/cpptod.html
http://digitalmars.com/d/ctod.html
the readability and logic gives speed to developing.
thanx -
Re:Weird writeup:
> >* versioning (no preprocessor madness)
>
> I'm guessing he meant variants here, the preprocessor is often
> used for variants, rarely for versioning.
I does look like variants to me, but appears to be called versioning - check this:
http://www.digitalmars.com/d/version.html -
Re:D is surprisingly good.
from http://digitalmars.com/d/interfaceToC.html
D does not provide an interface to C++. Since D, however, interfaces directly to C, it can interface directly to C++ code if it is declared as having C linkage.
D class objects are incompatible with C++ class objects. -
Re:What interpreters are available?
DigitalMars has an implementation that's available for download in D and C++ flavors.
http://www.digitalmars.com/dscript/index.html
It is licence-encumbered for commercial purposes, but otherwise, it's pretty good for general hacking. -
I love the autopointerage & hate the scope issWould be nice to have everything my way, the sheer built in extensibility of the language is in my opinion nothing short of beautiful, and something other languages could do well to imitate (check out D, for example).
allow me to elaborate, suppose you want to know if the version of the language on your platform supports an intrinsic array push function, and if not, attatch your own:if( !Array.push )
firstly the reference to
Array.prototype.push = function( item ){ ... } .push in the if has no brackets, so it becomes a pointer to the function within the intrinsic Array class. you can then create a function and assign it to that pointer. Sheer magic and gorgeously intuitive.
sticking with arrays you can grow and shrink them with little to zero fuss:function array_push( arr , item )
magically the array is one index longer. you can just set arr.length and it will append or delete indexes for you.
arr[arr.length] = item;
you can also use this to assign functions to other object's handlers, most notibly eventssomeObject.onclick = myFunction
But this has brought up the thing that really really needs fixing, suppose i want that onclick function to pass some info to myFunction when i call it i have to do thissomeObject.onclick = function(){ myFunction( this.someAttribute ) }
so instead i've created a function inline to hold my custom function, firstly it's not immediatley obvious to what object the "this" applies. if i'm running this code in a class does the this mean the class or someObject, one hopes it means the someObject.
next is the scope issue i've talked about suppose i'm dynamically creating objects on the fly and want the callback to reflect the id thusfor( i=0 ; i<10 ; i++ )
every single object will pass the value of 10 to myFunction, because after the function has finished the instance of i in memory that was used is still sat there and every myFunction has been given a pointer to it, not the value it was when it was initialised!
{
someObject[i] = new SomeObject();
someObject[i].onclick = function(){ myFunction( i ) }
}
so some oversights still exist, if only there were ways you could explicitly state "pointer to" or "value of" like in, oh, every other language including visual basic -
Re:Stroustrup is the problem
-
Re:Stroustrup is the problem
-
CSuperDuperDoublePlus was renamed D.
-
Array problem fixed
(I'm writing this as someone with over ten years of experience in C++, doing everything from protocol stacks to game physics engines to real-time programming. And after ten years, I'm fed up with the mess. This should have been fixed years ago.)
The problem with arrays has been fixed in the D programming language, http://www.digitalmars.com/d/, which is a reengineering of C++. -
Re:C++ will soon kick its ass.
I'll believe this after I see an implementation.
OTOH, have you checked out Digital Mars D? ( http://www.digitalmars.com/d/index.html ) It offers many of the featurs you are claiming for the new C++, and a useable version is available NOW.
I'm not a great fan of either Java or C++ or C. (I dislike both pointers and restrictive licenses.) That said, the great strength of all three languages is in their libraries. It's essentially impossible for any individual or moderately sized company to put out a new language, because of the lack of libraries. The general solution is to enable the calling of C libraries, but this isn't usually an easy matter.
If the new C++ spec is as different as you are implying, then I would expect that it will be YEARS before it has a respectible number of implementations. (I am NOT impressed with the "elegance" of the STL...quite the contrary. OTOH, my interest is not as much in make - every - CPU - cycle - count effenciency as in power of expression and flexibility. Object persistance is as important to me as any other single feature.)
That said, wxWidgets does look rather nice, and it seems a good fit for many user interface tasks. Also probably much faster than Swing (I haven't times it, but when I did time Swing it was SLOW!!!).
How does the new C++ handle splitting processes off to run on a different processor? This could be quite important in the coming decades, and I know of NO current language that handles this well. A Dataflow language would appear to be the optimum, but Prograf appears to have died, and the other such languages I've encountered were special purpose. Io handles this by running the separate processes as separate tasks, and communicating via IP ports, I'm not sure how much intrinsic overhead this has, but it might be significant, and is certainly clumsy at the moment. This should be automatically instigated by a co-routine call or some such. That way it could be optimized when hardware allowed it.
I suspect that you've not encountered many new languae releases...if you had you would be a bit less optimistic that they will live up to all the hype. -
Can we get rid of C please?
The well known memory leak issue, which causes the Firefox browser to consume ever increasing amounts of RAM, eventually leading to sluggish performance and crashes, has been carried over into yet another generation. This is despite an enormous amount of public commentary and user requests for resolution prior to release of a new version of Firefox
For how long major applications like Firefox will have memory leaks? can we please stop using C altogether and use a decent garbage-collected language like D (there are other languages around, but D is as close to C as possible)...
-
Re:What, no Haskell?
Haskell is nice indeed. I have read about it, but not used it yet.
They also missed D, which I hope will became more popular. -
Re:Probably Sourceforge?
Yeah, Sourforge sucks.
Not only it's full of flaws, but the interface is awful.
Trac is the way to go.
We need more large-scale sites offering Trac hosting.
The game I'm currently working on, QonkD, is hosted at a site that uses Trac, and I'm very happy with it.
(Note that they accept only projects in the D programming language, and their site is a bit slow, probably cause it's small and lack resources.) -
Re:C++0x
Can anyone give me a solid reason to stick with C++ and not just switch to the DigitalMars D language? Honestly, C++ is a mess, and it's only getting messier with the committee grafting new ideas on top of the current poorly-designed mess. On the other hand, D is a pristine platform that already includes the stuff C++0x is going to provide years in the future, interacts beautifully with existing C/C++, and provides comparable performance.
-
Re:How about D
I second that.
I have heard of D before, but now I went for a closer look, and just fell in love with it.
I'm currently writing a Qonk clone in D, it's very elegant and comfortable to work with.
The major problem is that it can't bind with C++ libraries (plain C works ok, my game even uses SDL, and I already tested a small OpenGL program too.)
See an overview of D, and read about it's contract implementation. -
Re:How about D
I second that.
I have heard of D before, but now I went for a closer look, and just fell in love with it.
I'm currently writing a Qonk clone in D, it's very elegant and comfortable to work with.
The major problem is that it can't bind with C++ libraries (plain C works ok, my game even uses SDL, and I already tested a small OpenGL program too.)
See an overview of D, and read about it's contract implementation. -
Design by Contract already implemented
in Digital Mars C++. See contracts.
-
Several options
There are several options. You can simply use macros as many people do. It's clunky and tends to have issues with inheritance and documentation, but it gets the job done. Alternatively you can try the digital mars c++ compiler which supports design by contract, or if your co-workers are willing to stretch a little bit you can try the D programming language from digital mars which is very similar to C++ but offers native contracts as well as a host of other nice features. Otherwise you can go the proprietary route and get C2 which is a C++ code generator that uses comment annotations to manage contracts and is a little slicker than the macro approach.
-
Several options
There are several options. You can simply use macros as many people do. It's clunky and tends to have issues with inheritance and documentation, but it gets the job done. Alternatively you can try the digital mars c++ compiler which supports design by contract, or if your co-workers are willing to stretch a little bit you can try the D programming language from digital mars which is very similar to C++ but offers native contracts as well as a host of other nice features. Otherwise you can go the proprietary route and get C2 which is a C++ code generator that uses comment annotations to manage contracts and is a little slicker than the macro approach.
-
How about D
The D programming language seems to support the idea of design by contract as a standard. From the litle I know about D, the language is close enough to C++ that a switch would be easy.
-
Digital Mars C++
While it is a non-trivial thing to switch C++ compilers, Digital Mars C++ is a free (as in beer) compiler that has DBC built in as a language extension. Here is the link to the relevant documentation. http://www.digitalmars.com/ctg/contract.html One thing I think it nifty is the __invariant contract keyword. While __in and __out can be duplicated easily with #ifdefs, __invariant really has to be supported at the language level. I believe DMC++ also handles contract inheritance for class hierarchies (although I have not played with this personally).
-
Re:Java vs. Mono now
Check out http://digitalmars.com/d, it's a C#/Java/C++ like language that is compiled to native code. The official compiler runs on Windows and Linux, but it's not open source. The frontend is, however. There is also the GNU D Compiler, which runs on a few more platforms and is 100% Free. It's a really nice language, you'll like it.
-
Re:Take a look at D if you can
The thing about garbage collection is that 80% of the time you don't need it, but the other 20% of the time not having it can really be a pain in the ass.
I think I'd say it somewhat differently: Few programs need MANUAL memory management at all, and those that do need it rarely need it in more than a few spots. However, in those few spots where you need it, it can be critically important. When you use it, though, you DRAMATICALLY increase the likelihood of nasty, hard to reproduce bugs, security holes, etc. So, the natural approach is to make automatic memory management the default. Probably the biggest problem with C is the fact that so many things are done by raw memory manipulation (strings, arrays, etc.) and ALL memory handling/management is manual.
The fact that C ALLOWS you to do everything by raw, manual memory manipulation is the source of its power, but you wouldn't HAVE to do everything manually in order to get that power. You only need the ABILITY to do everything that way, which is the D approach. The default is D's first class strings, first class arrays, automatic memory mgt for everything, but anything can be taken over and done manually with ease when the programmer feels like doing so.
And digitalmars.com is back up again, so check out this feature comparison table: http://www.digitalmars.com/d/comparison.html -
JAVA SUCKS
ok, java sucks, (it compiles to VM code, not native code). this is the same reason why C# sucks C++ is by far my fav language. also, out of all the new programming languages, the only one that is any good is D, see why at http://digitalmars.com/d/comparison.html
-
Re:The problem: our native-code languages are bad
Have you looked at D?
http://www.digitalmars.com/d/index.html
Compiles native as fast as C, but has all the safety and convenience features of Java/Python - garbage collected, bounds-checked, etc. -
Re:Not quite the end yet
You mistyped the URL. Here's a working one: http://www.digitalmars.com/d
-
Re:So does this mean?
Code like that is always going to slip through occasionally. At least C has strong type checking, after all in higher level languages like Python the variable geteuid wouldn't have even had to exist for the 1st expression to be valid.
C is a low level language and it's application to system programming is very well understood. High level languages aren't really suited for systems programming since they obscure so much of the underlying processes, even though they may lend themselves to more elegant solutions. Eventually a language like D: http://www.digitalmars.com/d/overview.html/ that tries to take the best of both worlds may take over for C, but that isn't happening any time soon.In the end, only careful devs, with the help of thorough test coverage and code audits, will consistently produce the most bug-free code
-
D programming language
If you want contract programming, but prefer C++ style syntax to Eiffel style, try the D programming language.
http://www.digitalmars.com/d/ -
Re:Let's not get off track.
That new language is D
-
Re:A better competetionImagine a world where 98% of software is written Java for portability.
At one point, not that long ago, I agreed 100% with this thinking. I was still drinking the "Java will have C performance" Koolaid from Sun.
I'm now of the opinion that the "managed" languages are a short-term abberation, unless they adopt an ANDF type "freeze" approach. That is where the bytecodes are pre-compiled once into machine code, just like a traditional compiler. I'm also not happy with where Java is at as a language after 10 years of evolution. No operator overloading, feh.
Lately I've been looking at D and Dylan for some projects. Both are quite advanced compared to Java, just as portable, and from what I've seen so far both outperform it in many areas. Game and HPC programmers could really use a better language than FORTRAN/C/C++, and Java will never be it, IMO. D seems the more pragmatic of the two, while Dylan looks "better" from a pure language perspective.
If the new processor performance metric (as touted by Intel) is "performance per watt", someone should take a hard look at Java and
.Net performance compared with the top compiled languages. Dylan or D would work fine as "server side" web development languages. -
Re:What else can I use? (for games at least)
Have a good look at D. No seriously!
http://www.digitalmars.com/d/index.html -
Re:Question from a Newbie
Funny you should that, I read this: D just 5 minutes ago.
-
Re:Dynamic typing
You have to realize that, for the vast majority of programmers, that the structure is necessary. Those programmers working in dynamically-typed languages fail; they produce spaghetti. Sure, you *can* maintain structure in a dynamically typed language such as Smalltalk or Ruby. But programming is a constant struggle to keep the code from descending into chaos.
What gets me though, is that people will make these sorts of comments all the time, and yet when you suggest that it's quite easy to take the same idea just a little further it all of a sudden becomes completely unpalatable and "too much work". Never mind that that's the same argument the dynamic type people use against static types. Never mind that for the extra work of contracts or specifying a little more than just type signatures you can get static checking gains and improvements in maintainability on par with what you get from using static types over dynamic types.
If you really believe that specifying static types really does help reduce bugs and improve maintainability (and it certainly can) then check out the options for doing a little better again.
Jedidiah. -
Re:The D Programming Language
I have been using D for a few weeks now, and I am amazed at how productive and fun it is to use compared to C++. It has the flexibility of C#/Java and the performance of C/C++.
I've been working in C/C++ for more than 10 years now, and the language's been getting so complex and it's libraries so full of template hacks, that it's no longer fun to work with.
Java, on the other side, has a cleaner syntax, but it's memory footprint and general bloat make it impossible to use in any place except big server applications. Even the best results when writing GUI applications (those that use SWT) are not responsive enough compared to those written in C/C++.
There are very interesting D projects at dsource.org, including Mango, DDL, DWT, Build and others.
You should evaluate the language and judge it on its technical merits. If you're a C++ programmer looking for greener pastures, I'm sure you'll fall in love with the language immediately. -
The D Programming Language
Check out the D programming language, http://www.digitalmars.com/d/, which is a refactoring of C++ to keep the performance benefits but make it much easier to program in.