www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - A paper about traps and programming stress

reply F <x y.com> writes:
Hello everybody,

 I found the folowing paper that discusses some lesser known Java programming
traps.

 http://www.cs.colostate.edu/~rta/publications/Computer00.pdf

 (Alexander, Bieman, Viega - "Coping with Java programming stress")

 I don't do a lot of programming, however the paper hits some hot spots
concerning Java. I submit the paper to your attention as a way to contribute to
D.

 If a more experienced programmer (than me) would like to verify the robustness
of D with respect to the issues presented in the paper...

 Thank you for your attention.
Mar 15 2010
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
F:

would like to verify the robustness of D with respect to the issues presented
in the paper...<
In some of those cases D gives tools to solve the problem, but to use those tools the programmer must already know about those problems. -------------------- Illusory protection: D classes of the same package can't access each other protected members. But in a D module even private attributes can be accessed by everyone else in the same module. The compiler here doesn't even try to give warnings. This can lead to bugs. A superprivate or module property can help here :o) This D characteristic of allowing free access in a module is bad for newbies because this langage sloppiness does not help learn the meaning and usefulness of the public/ protected/ private attributes. -------------------- Constructor confusion: In D this prints: 3 3 import std.stdio: writeln; import std.math: PI; class Super { this() { printThree(); } void printThree() { writeln("three"); } } class Test : Super { int indiana = cast(int)PI; // That is, pi=3 in Indiana. override void printThree() { writeln(indiana); } } void main() { auto t = new Test; t.printThree(); } -------------------- Initialization follies: in D I think D Scope Guard Statement as scope(exit) can help here. -------------------- Inheritance without specialization: in D there are class mixin that can be useful to use aggregation instead of inheritance (but they are a low-level feature that can cause other problems). Some templates can be used to inject other functionality in class templates. The disable can be used to hide inherited members: class Foo { void method() {} } class Bar : Foo { disable override void method() {} } void main() { auto b = new Bar; b.method(); } It raises a compilation error like: test.d(9): Error: function test.Bar.method is not callable Even if something like this can be better: test.d(9): Error: function test.Bar.method is not callable, annotated with disable. -------------------- Container limitations: D has templates that were designed to solve this problem. In the meantime part of this problem has being solved for Java too, this article if from year 2000. -------------------- Not-so-final parameters: the D const system is transitive, this solves the problem with method/function arguments. const can be used to state that a nonstatic method doesn't change the object state: class Foo { int x; const void bar() { x++; } } void main() {} -------------------- Initialization diffusion: D classes don't have instance initialization blocks. But both modules and classes can have multiple static this, so they can suffer the same diffusion problem: int a, b; static this() { a = 10; } class Foo { static this() { Foo.x = 10; } static int x, y; static this() { Foo.y = 20; } } static this() { b = 10; } void main() {} Allowing only one static this() in a module/class can help. I don't think a class/module can necessitate more than one static this, so this can become a bug report. Others here can give their opinion on this. -------------------- Other worries: No separate class-specification: I don't agree this is a problem. (dmd can generate 'header' files, but they are for performance purposes). No support for assertions: D has asserts and Contract programming. Phobos2 has enforce. Array type-checking failures: this D version of the program doen't fail at runtime: class A {} class B : A {} void proc(A[] x, A y) { x[0] = y; } void main() { B[] anArrayOfB = new B[5]; A a = new A(); proc(anArrayOfB, a); } -------------------- bye, bearophile
Mar 15 2010
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
 Allowing only one static this() in a module/class can help. I don't think a
class/module can necessitate more than one static this, so this can become a
bug report. Others here can give their opinion on this.
I have added this: http://d.puremagic.com/issues/show_bug.cgi?id=3965 bye, bearophile
Mar 15 2010
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
bearophile wrote:
 Array type-checking failures: this D version of the program doen't fail at
runtime:
 
 class A {}
 class B : A {}
 void proc(A[] x, A y) {
     x[0] = y;
 }
 void main() {
     B[] anArrayOfB = new B[5];
     A a = new A();
     proc(anArrayOfB, a);
 }
This is a potentially serious problem. Needs a bugzilla entry.
Mar 16 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Walter Bright:
 This is a potentially serious problem. Needs a bugzilla entry.
Glad to see that the answers I've written for that article aren't useless. But someone else has to file this bug because I am am not expert enough to write it. Bye, bearophile
Mar 16 2010
parent reply Walter Bright <newshound1 digitalmars.com> writes:
bearophile wrote:
 Glad to see that the answers I've written for that article aren't useless.
 But someone else has to file this bug because I am am not expert enough to
 write it.
http://d.puremagic.com/issues/show_bug.cgi?id=3977
Mar 16 2010
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright  
<newshound1 digitalmars.com> wrote:

 bearophile wrote:
 Glad to see that the answers I've written for that article aren't  
 useless.
 But someone else has to file this bug because I am am not expert enough  
 to
 write it.
http://d.puremagic.com/issues/show_bug.cgi?id=3977
Gah, I knew I'd be too late :) Took me a while to find it. Marked as a duplicate of http://d.puremagic.com/issues/show_bug.cgi?id=2095 -Steve
Mar 16 2010
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Steven Schveighoffer wrote:
 On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright 
 <newshound1 digitalmars.com> wrote:
 
 bearophile wrote:
 Glad to see that the answers I've written for that article aren't 
 useless.
 But someone else has to file this bug because I am am not expert 
 enough to
 write it.
http://d.puremagic.com/issues/show_bug.cgi?id=3977
Gah, I knew I'd be too late :) Took me a while to find it. Marked as a duplicate of http://d.puremagic.com/issues/show_bug.cgi?id=2095
It seems this bug keeps getting rediscovered!
Mar 16 2010
next sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 03/16/2010 04:27 PM, Walter Bright wrote:
 Steven Schveighoffer wrote:
 On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright
 <newshound1 digitalmars.com> wrote:

 bearophile wrote:
 Glad to see that the answers I've written for that article aren't
 useless.
 But someone else has to file this bug because I am am not expert
 enough to
 write it.
http://d.puremagic.com/issues/show_bug.cgi?id=3977
Gah, I knew I'd be too late :) Took me a while to find it. Marked as a duplicate of http://d.puremagic.com/issues/show_bug.cgi?id=2095
It seems this bug keeps getting rediscovered!
Got my vote. Really needs to be fixed, otherwise we're no better than Java. Andrei
Mar 16 2010
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 16 Mar 2010 17:33:03 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail erdani.org> wrote:

 On 03/16/2010 04:27 PM, Walter Bright wrote:
 Steven Schveighoffer wrote:
 On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright
 <newshound1 digitalmars.com> wrote:

 bearophile wrote:
 Glad to see that the answers I've written for that article aren't
 useless.
 But someone else has to file this bug because I am am not expert
 enough to
 write it.
http://d.puremagic.com/issues/show_bug.cgi?id=3977
Gah, I knew I'd be too late :) Took me a while to find it. Marked as a duplicate of http://d.puremagic.com/issues/show_bug.cgi?id=2095
It seems this bug keeps getting rediscovered!
Got my vote. Really needs to be fixed, otherwise we're no better than Java.
Java does a runtime check to ensure you are not saving the wrong type to the array. It's not the best system, but it's is definitely the most flexible safe solution. The proposed solution for D is less flexible, because it forces you to treat the objects themselves as const, and not modify the contents of the array at all. So it's really a judgement call on which is better depending on whether you value flexibility or performance. -Steve
Mar 16 2010
prev sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 16 Mar 2010 17:27:26 -0400, Walter Bright  
<newshound1 digitalmars.com> wrote:

 Steven Schveighoffer wrote:
 On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright  
 <newshound1 digitalmars.com> wrote:

 bearophile wrote:
 Glad to see that the answers I've written for that article aren't  
 useless.
 But someone else has to file this bug because I am am not expert  
 enough to
 write it.
http://d.puremagic.com/issues/show_bug.cgi?id=3977
Gah, I knew I'd be too late :) Took me a while to find it. Marked as a duplicate of http://d.puremagic.com/issues/show_bug.cgi?id=2095
It seems this bug keeps getting rediscovered!
It's not really an easy problem to solve. With const, it sort of works, but now all the objects are treated as const, whereas the thing you really want to treat as const is the class references and array (head-const). Imagine if you wanted to call a mutable method on each of the array objects as defined by the base-class. Such an operation is not invalid. I feel like we will eventually need to correctly solve these types of problems. I think it could already be done using alias this for custom types, but the builtins would need to be treated specially. -Steve
Mar 16 2010
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 16 Mar 2010 17:37:45 -0400, Steven Schveighoffer  
<schveiguy yahoo.com> wrote:

 On Tue, 16 Mar 2010 17:27:26 -0400, Walter Bright  
 <newshound1 digitalmars.com> wrote:

 Steven Schveighoffer wrote:
 On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright  
 <newshound1 digitalmars.com> wrote:

 bearophile wrote:
 Glad to see that the answers I've written for that article aren't  
 useless.
 But someone else has to file this bug because I am am not expert  
 enough to
 write it.
http://d.puremagic.com/issues/show_bug.cgi?id=3977
Gah, I knew I'd be too late :) Took me a while to find it. Marked as a duplicate of http://d.puremagic.com/issues/show_bug.cgi?id=2095
It seems this bug keeps getting rediscovered!
It's not really an easy problem to solve. With const, it sort of works, but now all the objects are treated as const, whereas the thing you really want to treat as const is the class references and array (head-const). Imagine if you wanted to call a mutable method on each of the array objects as defined by the base-class. Such an operation is not invalid.
A perfect example of this is sort. Sort can be compiled once for objects, but you would not be able to pass an array of derived objects into the same sort routine, because it would turn them into const objects (non-swappable). -Steve
Mar 16 2010
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Steven Schveighoffer:
 I feel like we will eventually need to correctly solve these types of  
 problems.  I think it could already be done using alias this for custom  
 types, but the builtins would need to be treated specially.
I am ignorant about this topic, so I keep muzzle almost shut. See part titled "Variance" here: http://www.codeproject.com/KB/cs/CSharp4Features.aspx Bye, bearophile
Mar 16 2010
parent Jason House <jason.james.house gmail.com> writes:
bearophile Wrote:

 Steven Schveighoffer:
 I feel like we will eventually need to correctly solve these types of  
 problems.  I think it could already be done using alias this for custom  
 types, but the builtins would need to be treated specially.
I am ignorant about this topic, so I keep muzzle almost shut. See part titled "Variance" here: http://www.codeproject.com/KB/cs/CSharp4Features.aspx Bye, bearophile
That's definitely related. The new covariant ienumerable is essentially the same as head const. There is no appending or rebinding of elements, but you can still get references to mutable data out. I never remember the meanings of C++ iterator types / D range types, so I'll stop short of a range-based example.
Mar 17 2010
prev sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
F wrote:
 Hello everybody,
 
  I found the folowing paper that discusses some lesser known Java programming
traps.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . _________ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ./ It’s a trap! . . . . . . . . . . . . . . . . _,,,--~~~~~~~~--,_ . . . . ._________/ . . . . . . . . . . . . . . ,-‘ : : : :::: :::: :: : : : : :Ί ‘-, . . /. . . . . . . . . . . . . . . . . . . . . . .,-‘ :: : : :::: :::: :::: :::: : : :o : ‘-, . . . . . . . . . . . . . . . . . . . . . ,-‘ :: ::: :: : : :: :::: :::: :: : : : : :O ‘-, . . . . . . . . . . . . . . . . . . .,-‘ : :: :: :: :: :: : : : : : , : : :Ί :::: :::: ::’; . . . . . . . . . . . . . . . . .,-‘ / / : :: :: :: :: : : :::: :::-, ;; ;; ;; ;; ;; ;; ; . . . . . . . . . . . . . . . . /,-‘,’ :: : : : : : : : : :: :: :: : ‘-, ;; ;; ;; ;; ;; ;;| . . . . . . . . . . . . . . /,’,-‘ :: :: :: :: :: :: :: : ::_,-~~,_’-, ;; ;; ;; ;; | . . . . . . . . . . . . _/ :,’ :/ :: :: :: : : :: :: _,-‘/ : ,-‘;’-‘’’’’~-, ;; ;; ;;,’ . . . . . . . . . . . ,-‘ / : : : : : : ,-‘’’ : : :,--‘’ :|| /,-‘-‘--‘’’__,’’’ ;; ;,-‘ . . . . . . . . . . . . ‘ ) : : : :’’’’--,,--,,,,,,― :: ::--,,_’’-,,’’’― :’- :’-, . . . . . . . . . . . . . .) : : : : : : ,, : ‘’’’~~~~’ :: :: :: :’’’’’― :: ,-‘ :,/ . . . . . . . . . . . . . .,/ /|\| | :/ / : : : : : : : ,’-, :: :: :: :: ::,--‘’ :,-‘ . . . . . . . . . . . . .\’|\ |/ ‘/ / :: :_--,, : , | )’; :: :: :: :,-‘’ : ,-‘ : : : , . . . . . . . . . . ./― :| | : |/ :: ::----, :/ :|/ :: :: ,-‘’ : :,-‘ : : : : : : ‘’-,,_ . . . . . . ..| : : :/ ‘’-(, :: :: :: ‘’’’’~,,,,,’’ :: ,-‘’ : :,-‘ : : : : : : : : :,-‘’’\ . . . . . ,-‘ : : : | : : ‘’) : : :―’’’’~-,: : ,--‘’’ : :,-‘’ : : : : : : : : : ,-‘ :―’’’’’-,_ . ./ : : : : :’-, :: | :: :: :: _,,-‘’’’― : ,--‘’ : : : : : : : : : : : / : : : : : : :’’-, / : : : : : -, :―’’’’’’’’’’’― : : _,,-~’’ : : : : : : : : : : : : : :| : : : : : : : : : : : : : : : :―’’~~~~~~’’’ : : : : : : : : : : : : : : : : : : | : : : : : : : : : (Someone had to do it!)
Mar 15 2010
parent reply Bane <branimir.milosavljevic gmail.com> writes:
Walter Bright Wrote:

 F wrote:
 Hello everybody,
 
  I found the folowing paper that discusses some lesser known Java programming
traps.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . _________ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ./ It’s a trap! . . . . . . . . . . . . . . . . _,,,--~~~~~~~~--,_ . . . . ._________/ . . . . . . . . . . . . . . ,-‘ : : : :::: :::: :: : : : : :Ί ‘-, . . /. . . . . . . . . . . . . . . . . . . . . . .,-‘ :: : : :::: :::: :::: :::: : : :o : ‘-, . . . . . . . . . . . . . . . . . . . . . ,-‘ :: ::: :: : : :: :::: :::: :: : : : : :O ‘-, . . . . . . . . . . . . . . . . . . .,-‘ : :: :: :: :: :: : : : : : , : : :Ί :::: :::: ::’; . . . . . . . . . . . . . . . . .,-‘ / / : :: :: :: :: : : :::: :::-, ;; ;; ;; ;; ;; ;; ; . . . . . . . . . . . . . . . . /,-‘,’ :: : : : : : : : : :: :: :: : ‘-, ;; ;; ;; ;; ;; ;;| . . . . . . . . . . . . . . /,’,-‘ :: :: :: :: :: :: :: : ::_,-~~,_’-, ;; ;; ;; ;; | . . . . . . . . . . . . _/ :,’ :/ :: :: :: : : :: :: _,-‘/ : ,-‘;’-‘’’’’~-, ;; ;; ;;,’ . . . . . . . . . . . ,-‘ / : : : : : : ,-‘’’ : : :,--‘’ :|| /,-‘-‘--‘’’__,’’’ ;; ;,-‘ . . . . . . . . . . . . ‘ ) : : : :’’’’--,,--,,,,,,― :: ::--,,_’’-,,’’’― :’- :’-, . . . . . . . . . . . . . .) : : : : : : ,, : ‘’’’~~~~’ :: :: :: :’’’’’― :: ,-‘ :,/ . . . . . . . . . . . . . .,/ /|\| | :/ / : : : : : : : ,’-, :: :: :: :: ::,--‘’ :,-‘ . . . . . . . . . . . . .\’|\ |/ ‘/ / :: :_--,, : , | )’; :: :: :: :,-‘’ : ,-‘ : : : , . . . . . . . . . . ./― :| | : |/ :: ::----, :/ :|/ :: :: ,-‘’ : :,-‘ : : : : : : ‘’-,,_ . . . . . . ..| : : :/ ‘’-(, :: :: :: ‘’’’’~,,,,,’’ :: ,-‘’ : :,-‘ : : : : : : : : :,-‘’’\ . . . . . ,-‘ : : : | : : ‘’) : : :―’’’’~-,: : ,--‘’’ : :,-‘’ : : : : : : : : : ,-‘ :―’’’’’-,_ . ./ : : : : :’-, :: | :: :: :: _,,-‘’’’― : ,--‘’ : : : : : : : : : : : / : : : : : : :’’-, / : : : : : -, :―’’’’’’’’’’’― : : _,,-~’’ : : : : : : : : : : : : : :| : : : : : : : : : : : : : : : :―’’~~~~~~’’’ : : : : : : : : : : : : : : : : : : | : : : : : : : : : (Someone had to do it!)
Could there be more geekiest thing than ASCII art of star wars character?
Mar 15 2010
parent Bernard Helyer <b.helyer gmail.com> writes:
On 16/03/10 09:15, Bane wrote:
 Could there be more geekiest thing than ASCII art of star wars character?
You have no idea. Stay out of the dark recesses of the internet, I implore you!
Mar 17 2010