www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - =?UTF-8?B?RCBmZWF0dXJlcw==?=

reply =?UTF-8?B?UmlzaGF0IEdhbGl1bGlu?= <rishatgaliulin mail.ru> writes:
SSdtIG5ld2JpZSB0byBELCBidXQgSSd2ZSBiZWVuIHdvbmRlcmVkIGJ5IGl0cyBmZWF0dXJlcy4K
CkkgaGF2ZSBzb21lIHF1ZXN0aW9ucyBhYm91dCBEMiBhbmQgaXRzIHN0YW5kYXJkIGxpYnJhcnkg
OgoxKSBXaHkgaXMgIk9iamVjdC5mYWN0b3J5KHN0cmluZyBjbGFzc25hbWUpIiBub3QgYWxsb3dp
bmcgdG8gY3JlYXRlIG9iamVjdHMgd2l0aG91dCBkZWZhdWx0IGNvbnN0cnVjdG9yLCBmb3IgZXhh
bXBsZToKICAgICB1Ynl0ZVtdIGFycmF5ID0gbmV3IHVieXRlWzEwXTsKICAgICBNeUNsYXNzIG15
ID0gT2JqZWN0LmZhY3RvcnkoIk15Q2xhc3MiLCAgYXJyYXkpOwoyKSBXaHkgRCBub3QgdXNpbmcg
ZnVuY3Rpb25zIGV4Y2VwdGlvbnMgc3BlY2lmaWNhdGlvbiBsaXN0IGxpa2UgSmF2YT8gSWYgdGhp
cyBwcm9tb3RlcyBiYWQgcHJvZ3JhbW1pbmcgc3R5bGUgdG8gbmV3YmllcywgbWF5IGJlIGJldHRl
ciBhdCBsZWFzdCB0byBjcmVhdGUgY29tcGlsYXRpb24gd2FybmluZ3M/CgpXaXRoIGJlc3QgcmVn
YXJkcywgUmlzaGF0IEdhbGl1bGluLg==
Sep 20 2011
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 20 Sep 2011 15:58:06 -0400, Rishat Galiulin  
<rishatgaliulin mail.ru> wrote:

 I'm newbie to D, but I've been wondered by its features.
Welcome!
 I have some questions about D2 and its standard library :
 1) Why is "Object.factory(string classname)" not allowing to create  
 objects without default constructor, for example:
      ubyte[] array = new ubyte[10];
      MyClass my = Object.factory("MyClass",  array);
D does not have a very large run time reflection capability. Object.factory and the TypeInfo system is pretty much it. The theory is that with vastly superior compile-time reflection, the need for runtime reflection is either obviated or can be built using compile-time reflection. I think in fact an older library (flectioned) was built using this theory, but I've never used it, and it probably needs some dusting.
 2) Why D not using functions exceptions specification list like Java? If  
 this promotes bad programming style to newbies, may be better at least  
 to create compilation warnings?
Not sure what the question is, D does not support exception specification because exception specifications are too cumbersome to be useful. However, it does support saying that a function does *not* throw exceptions via the nothrow attribute. -Steve
Sep 20 2011
parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Tuesday, September 20, 2011 14:02 Steven Schveighoffer wrote:
 On Tue, 20 Sep 2011 15:58:06 -0400, Rishat Galiulin
 2) Why D not using functions exceptions specification list like Java? If
 this promotes bad programming style to newbies, may be better at least
 to create compilation warnings?
Not sure what the question is, D does not support exception specification because exception specifications are too cumbersome to be useful. However, it does support saying that a function does *not* throw exceptions via the nothrow attribute.
Checked exceptions have generally been determined to have been a bad idea. They _seem_ like a good idea at first and do provide a number of benefits, but there are ultimately a number of problems with them. Java is the only language weren't a good idea and don't have them. This interview with one of the http://www.artima.com/intv/handcuffs.html Ultimately, it means that documentation needs to be clear about what exceptions something is expected to throw, and it does mean that it can be harder to make sure that your code is prepared for every exception type that it should be without catching Exception, but it still works quite well. Ideally, we'd have something that would statically verify that all of the appropriate exception types have been handled, but as far as I know, no one has really come up with a way to do that which doesn't have the problems that checked exceptions do. - Jonathan M Davis
Sep 20 2011
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 9/20/2011 2:28 PM, Jonathan M Davis wrote:
 On Tue, 20 Sep 2011 15:58:06 -0400, Rishat Galiulin
 2) Why D not using functions exceptions specification list like Java?
Checked exceptions have generally been determined to have been a bad idea.
Bruce Eckel's article about it convinced me. http://www.mindview.net/Etc/Discussions/CheckedExceptions
Sep 20 2011
parent "Marco Leise" <Marco.Leise gmx.de> writes:
Am 21.09.2011, 01:20 Uhr, schrieb Walter Bright  
<newshound2 digitalmars.com>:

 On 9/20/2011 2:28 PM, Jonathan M Davis wrote:
 On Tue, 20 Sep 2011 15:58:06 -0400, Rishat Galiulin
 2) Why D not using functions exceptions specification list like Java?
Checked exceptions have generally been determined to have been a bad idea.
Bruce Eckel's article about it convinced me. http://www.mindview.net/Etc/Discussions/CheckedExceptions
I don't find this article all that convincing. The symptom is that people begin to write stub exception handlers and 'swallow' the exception. And this is seen as proof of a failed concept. I wrote exception stubs myself in the past. Mainly because I had to compile the program first to see the error, then write the proper exception handler or write a throw clause. That is cumbersome and you tend to just write a stub at the lowest level in your code, because it is less typing. Checked exceptions have the purpose to inform the program of invalid conditions in areas outside the immediate control of the program. In a released program you should take care of those one way or another, because it is likely that a host name cannot be resolved, or a file cannot be read (down to the fact that the disk has bad sectors). So you are made aware of this and must solve the problem in one of three ways, depending on the code structure: - add a throws clause to let the next higher level handle it - catch and handle it right there - do both - wrap the exception (if it happened in the subprocess of something bigger) It is a bit of a motivation to write actual error handlers, that you can easily forget otherwise. One of the reasons Java is popular is because of the great tools support. I am a big fan of Eclipse and if you have a look at the situation there you notice 1. try {...} catch (SomeKindOfException e) {} will mark the empty braces and print a warning about an undocumented empty block 2. Uncaught checked exceptions will show up as an error while you are typing 3. For these errors and many others there are 'quick-fixes'. You just press Ctrl+1 and choose a) add throws clause to method b) surround by try-catch 3b will add a stub like this: } catch (ExceptionType e) { e.printStackTrace(); } This means that no Exception actually goes unnoticed anymore as described in the article! It is plain no point today in Java. :) I guess one can say "they hack around the flaws in the language, you need an IDE to even use it properly" or one can say "they learned and found a way to make a good idea just work". For D there is no such IDE and all language features must promote good code when written in programming editors, Java can excuse a lot in that aspect.
Sep 22 2011
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2011-09-20 21:58, Rishat Galiulin wrote:
 I'm newbie to D, but I've been wondered by its features.

 I have some questions about D2 and its standard library :
 1) Why is "Object.factory(string classname)" not allowing to create objects
without default constructor, for example:
       ubyte[] array = new ubyte[10];
       MyClass my = Object.factory("MyClass",  array);
Have a look at: https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L486 It lets you create a new instance from a string regardless of the constructor, but it won't call the constructor. You might be able to use this incomplete function: https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L406
 2) Why D not using functions exceptions specification list like Java? If this
promotes bad programming style to newbies, may be better at least to create
compilation warnings?

 With best regards, Rishat Galiulin.
-- /Jacob Carlborg
Sep 20 2011