digitalmars.D - A paper about traps and programming stress
- F (7/7) Mar 15 2010 Hello everybody,
- bearophile (82/83) Mar 15 2010 In some of those cases D gives tools to solve the problem, but to use th...
- bearophile (4/5) Mar 15 2010 I have added this:
- Walter Bright (2/14) Mar 16 2010 This is a potentially serious problem. Needs a bugzilla entry.
- bearophile (4/5) Mar 16 2010 Glad to see that the answers I've written for that article aren't useles...
- Walter Bright (2/5) Mar 16 2010 http://d.puremagic.com/issues/show_bug.cgi?id=3977
- Steven Schveighoffer (5/12) Mar 16 2010 Gah, I knew I'd be too late :) Took me a while to find it.
- Walter Bright (2/19) Mar 16 2010 It seems this bug keeps getting rediscovered!
- Andrei Alexandrescu (3/23) Mar 16 2010 Got my vote. Really needs to be fixed, otherwise we're no better than Ja...
- Steven Schveighoffer (10/34) Mar 16 2010 Java does a runtime check to ensure you are not saving the wrong type to...
- Steven Schveighoffer (11/29) Mar 16 2010 It's not really an easy problem to solve. With const, it sort of works,...
- Steven Schveighoffer (7/34) Mar 16 2010 A perfect example of this is sort. Sort can be compiled once for object...
- bearophile (7/10) Mar 16 2010 I am ignorant about this topic, so I keep muzzle almost shut.
- Jason House (2/14) Mar 17 2010 That's definitely related. The new covariant ienumerable is essentially ...
- Walter Bright (27/30) Mar 15 2010 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . __...
- Bane (2/35) Mar 15 2010 Could there be more geekiest thing than ASCII art of star wars character...
- Bernard Helyer (3/4) Mar 17 2010 You have no idea. Stay out of the dark recesses of the internet, I
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
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
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
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
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
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
On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright <newshound1 digitalmars.com> wrote:bearophile wrote: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 -SteveGlad 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
Steven Schveighoffer wrote:On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright <newshound1 digitalmars.com> wrote:It seems this bug keeps getting rediscovered!bearophile wrote: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=2095Glad 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
On 03/16/2010 04:27 PM, Walter Bright wrote:Steven Schveighoffer wrote:Got my vote. Really needs to be fixed, otherwise we're no better than Java. AndreiOn Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright <newshound1 digitalmars.com> wrote:It seems this bug keeps getting rediscovered!bearophile wrote: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=2095Glad 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
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: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. -SteveSteven Schveighoffer wrote:Got my vote. Really needs to be fixed, otherwise we're no better than Java.On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright <newshound1 digitalmars.com> wrote:It seems this bug keeps getting rediscovered!bearophile wrote: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=2095Glad 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
On Tue, 16 Mar 2010 17:27:26 -0400, Walter Bright <newshound1 digitalmars.com> wrote:Steven Schveighoffer wrote: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. -SteveOn Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright <newshound1 digitalmars.com> wrote:It seems this bug keeps getting rediscovered!bearophile wrote: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=2095Glad 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
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: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). -SteveSteven Schveighoffer wrote: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.On Tue, 16 Mar 2010 17:18:39 -0400, Walter Bright <newshound1 digitalmars.com> wrote:It seems this bug keeps getting rediscovered!bearophile wrote: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=2095Glad 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
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
bearophile Wrote:Steven Schveighoffer: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.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 17 2010
F wrote:Hello everybody, I found the folowing paper that discusses some lesser known Java programming traps.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . _________ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ./ Its a trap! . . . . . . . . . . . . . . . . _,,,--~~~~~~~~--,_ . . . . ._________/ . . . . . . . . . . . . . . ,- : : : :::: :::: :: : : : : :Ί -, . . /. . . . . . . . . . . . . . . . . . . . . . .,- :: : : :::: :::: :::: :::: : : :o : -, . . . . . . . . . . . . . . . . . . . . . ,- :: ::: :: : : :: :::: :::: :: : : : : :O -, . . . . . . . . . . . . . . . . . . .,- : :: :: :: :: :: : : : : : , : : :Ί :::: :::: ::; . . . . . . . . . . . . . . . . .,- / / : :: :: :: :: : : :::: :::-, ;; ;; ;; ;; ;; ;; ; . . . . . . . . . . . . . . . . /,-, :: : : : : : : : : :: :: :: : -, ;; ;; ;; ;; ;; ;;| . . . . . . . . . . . . . . /,,- :: :: :: :: :: :: :: : ::_,-~~,_-, ;; ;; ;; ;; | . . . . . . . . . . . . _/ :, :/ :: :: :: : : :: :: _,-/ : ,-;-~-, ;; ;; ;;, . . . . . . . . . . . ,- / : : : : : : ,- : : :,-- :|| /,----__, ;; ;,- . . . . . . . . . . . . ) : : : :--,,--,,,,,,― :: ::--,,_-,,― :- :-, . . . . . . . . . . . . . .) : : : : : : ,, : ~~~~ :: :: :: :― :: ,- :,/ . . . . . . . . . . . . . .,/ /|\| | :/ / : : : : : : : ,-, :: :: :: :: ::,-- :,- . . . . . . . . . . . . .\|\ |/ / / :: :_--,, : , | ); :: :: :: :,- : ,- : : : , . . . . . . . . . . ./― :| | : |/ :: ::----, :/ :|/ :: :: ,- : :,- : : : : : : -,,_ . . . . . . ..| : : :/ -(, :: :: :: ~,,,,, :: ,- : :,- : : : : : : : : :,-\ . . . . . ,- : : : | : : ) : : :―~-,: : ,-- : :,- : : : : : : : : : ,- :―-,_ . ./ : : : : :-, :: | :: :: :: _,,-― : ,-- : : : : : : : : : : : / : : : : : : :-, / : : : : : -, :―― : : _,,-~ : : : : : : : : : : : : : :| : : : : : : : : : : : : : : : :―~~~~~~ : : : : : : : : : : : : : : : : : : | : : : : : : : : : (Someone had to do it!)
Mar 15 2010
Walter Bright Wrote:F wrote:Could there be more geekiest thing than ASCII art of star wars character?Hello everybody, I found the folowing paper that discusses some lesser known Java programming traps.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . _________ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ./ Its a trap! . . . . . . . . . . . . . . . . _,,,--~~~~~~~~--,_ . . . . ._________/ . . . . . . . . . . . . . . ,- : : : :::: :::: :: : : : : :Ί -, . . /. . . . . . . . . . . . . . . . . . . . . . .,- :: : : :::: :::: :::: :::: : : :o : -, . . . . . . . . . . . . . . . . . . . . . ,- :: ::: :: : : :: :::: :::: :: : : : : :O -, . . . . . . . . . . . . . . . . . . .,- : :: :: :: :: :: : : : : : , : : :Ί :::: :::: ::; . . . . . . . . . . . . . . . . .,- / / : :: :: :: :: : : :::: :::-, ;; ;; ;; ;; ;; ;; ; . . . . . . . . . . . . . . . . /,-, :: : : : : : : : : :: :: :: : -, ;; ;; ;; ;; ;; ;;| . . . . . . . . . . . . . . /,,- :: :: :: :: :: :: :: : ::_,-~~,_-, ;; ;; ;; ;; | . . . . . . . . . . . . _/ :, :/ :: :: :: : : :: :: _,-/ : ,-;-~-, ;; ;; ;;, . . . . . . . . . . . ,- / : : : : : : ,- : : :,-- :|| /,----__, ;; ;,- . . . . . . . . . . . . ) : : : :--,,--,,,,,,― :: ::--,,_-,,― :- :-, . . . . . . . . . . . . . .) : : : : : : ,, : ~~~~ :: :: :: :― :: ,- :,/ . . . . . . . . . . . . . .,/ /|\| | :/ / : : : : : : : ,-, :: :: :: :: ::,-- :,- . . . . . . . . . . . . .\|\ |/ / / :: :_--,, : , | ); :: :: :: :,- : ,- : : : , . . . . . . . . . . ./― :| | : |/ :: ::----, :/ :|/ :: :: ,- : :,- : : : : : : -,,_ . . . . . . ..| : : :/ -(, :: :: :: ~,,,,, :: ,- : :,- : : : : : : : : :,-\ . . . . . ,- : : : | : : ) : : :―~-,: : ,-- : :,- : : : : : : : : : ,- :―-,_ . ./ : : : : :-, :: | :: :: :: _,,-― : ,-- : : : : : : : : : : : / : : : : : : :-, / : : : : : -, :―― : : _,,-~ : : : : : : : : : : : : : :| : : : : : : : : : : : : : : : :―~~~~~~ : : : : : : : : : : : : : : : : : : | : : : : : : : : : (Someone had to do it!)
Mar 15 2010
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