digitalmars.D - Is it true scope declarations are being removed?
- Sean Eskapp (6/6) Jan 21 2011 Someone mentioned to me that scope declarations, e.g.
- Trass3r (2/2) Jan 23 2011 Sadly true.
- Andrej Mitrovic (2/2) Jan 23 2011 I don't understand it either. AFAIK they are being removed because
- bearophile (4/6) Jan 23 2011 I have hated see typedef and scoped classes go (I have even missed delet...
- Kagamin (2/3) Jan 24 2011 Having plenty of time, algol must be perfect now.
- Trass3r (4/6) Jan 23 2011 I have the same feeling.
- so (3/6) Jan 23 2011 If the library solution is as good as the original, it is a big plus.
- Steven Schveighoffer (7/13) Jan 24 2011 In fact the library solution will be better, because it's an expression,...
- Andrej Mitrovic (7/11) Jan 24 2011 That is pretty cool. What I worried about is that a library solution
- Steven Schveighoffer (4/18) Jan 24 2011 That wasn't done by the compiler anyways.
- Andrej Mitrovic (2/4) Jan 24 2011 Yeah I've noticed that. Lazy DMD compiler! :)
- Jonathan M Davis (8/14) Jan 24 2011 Much of anything that requires code flow analysis doesn't tend to happen...
- Jonathan M Davis (14/22) Jan 23 2011 std.typecons.scoped is the replacement for the builtin scope declaration...
- Trass3r (1/2) Jan 24 2011 Pointers are inherently unsafe as well ;)
- Jonathan M Davis (8/11) Jan 24 2011 Well, you can't take those out of the core language and put them in the ...
- bearophile (36/37) Jan 24 2011 Right. You need (lot of) work to implement it, in a system language it c...
Someone mentioned to me that scope declarations, e.g. scope class A{} or scope A myNewObject; are being removed from the language. Is this true? If so, how will RAII-type classes be implemented?
Jan 21 2011
Sadly true. They intend to replace it with a library based solution, I don't know why.
Jan 23 2011
I don't understand it either. AFAIK they are being removed because they're unsafe, and are being replaced by an unsafe library solution.
Jan 23 2011
Andrej Mitrovic:I don't understand it either. AFAIK they are being removed because they're unsafe, and are being replaced by an unsafe library solution.I have hated see typedef and scoped classes go (I have even missed delete), but you need a bit of faith in the future and in Andrei & Walter. Andrei is not evil, and he's smart. D2 language is a very young language, and when a built-in feature looks not perfect, it's better to remove it now. If you remove it, you will have plenty of time in future to add it back, add something better implementation of it, or to find a better and very different solution, or even to add a more general language feature that allows you to implement the original half-broken feature in library code. While if something badly designed is left in the language, then you are struck with it forever, or almost forever. Generally in language it's 10-100 times simpler to add a new feature than to remove it :-) Better to start with a not complete D2 language, a language with holes waiting to be filled, that with a language with unfixable warts that you may "fix" just adding another better feature and pretending the old one doesn't exist any more (example: nullptr of C++0x). Bye, bearophile
Jan 23 2011
bearophile Wrote:If you remove it, you will have plenty of time in future to add it back, add something better implementation of it, or to find a better and very different solution, or even to add a more general language feature that allows you to implement the original half-broken feature in library code.Having plenty of time, algol must be perfect now.
Jan 24 2011
I don't understand it either. AFAIK they are being removed because they're unsafe, and are being replaced by an unsafe library solution.I have the same feeling. While I do understand why typedef is poorly designed (http://d.puremagic.com/issues/show_bug.cgi?id=5467) I can't imagine how a library-based scope is any better than before.
Jan 23 2011
On Mon, 24 Jan 2011 00:11:48 +0200, Trass3r <un known.com> wrote:Sadly true. They intend to replace it with a library based solution, I don't know why.If the library solution is as good as the original, it is a big plus. If only we could do the same for everything!
Jan 23 2011
On Sun, 23 Jan 2011 19:03:19 -0500, so <so so.do> wrote:On Mon, 24 Jan 2011 00:11:48 +0200, Trass3r <un known.com> wrote:In fact the library solution will be better, because it's an expression, not a storage class. This means, you can "scope" a class inside another statement instead of having to declare/initialize it separately. It solves a bug I filed: http://d.puremagic.com/issues/show_bug.cgi?id=2070 -SteveSadly true. They intend to replace it with a library based solution, I don't know why.If the library solution is as good as the original, it is a big plus. If only we could do the same for everything!
Jan 24 2011
On 1/24/11, Steven Schveighoffer <schveiguy yahoo.com> wrote:This means, you can "scope" a class inside another statement instead of having to declare/initialize it separately. It solves a bug I filed: http://d.puremagic.com/issues/show_bug.cgi?id=2070 -SteveThat is pretty cool. What I worried about is that a library solution could mean loosing help from the compiler itself. E.g. if the compiler sees a scoped variable it can do some checks to see that you're not escaping a reference by accident, inadvertently assigning it to a global, or some other sanity checks. I guess these things might be doable in a library but I don't know to what extent.
Jan 24 2011
On Mon, 24 Jan 2011 09:41:30 -0500, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:On 1/24/11, Steven Schveighoffer <schveiguy yahoo.com> wrote:That wasn't done by the compiler anyways. -SteveThis means, you can "scope" a class inside another statement instead of having to declare/initialize it separately. It solves a bug I filed: http://d.puremagic.com/issues/show_bug.cgi?id=2070 -SteveThat is pretty cool. What I worried about is that a library solution could mean loosing help from the compiler itself. E.g. if the compiler sees a scoped variable it can do some checks to see that you're not escaping a reference by accident, inadvertently assigning it to a global, or some other sanity checks. I guess these things might be doable in a library but I don't know to what extent.
Jan 24 2011
On 1/24/11, Steven Schveighoffer <schveiguy yahoo.com> wrote:That wasn't done by the compiler anyways. -SteveYeah I've noticed that. Lazy DMD compiler! :)
Jan 24 2011
On Monday 24 January 2011 07:49:44 Andrej Mitrovic wrote:On 1/24/11, Steven Schveighoffer <schveiguy yahoo.com> wrote:Much of anything that requires code flow analysis doesn't tend to happen. And it's so easy to get around it in many cases (such as passing a pointer to a function which then returns that pointer) that it wouldn't ultimately help all that much anyway (though having _some_ is still better than nothing). The fact that such things can't be reliably verified at compile time is exactly why scoped classes are unsafe in the first place. - Jonathan M DavisThat wasn't done by the compiler anyways. -SteveYeah I've noticed that. Lazy DMD compiler! :)
Jan 24 2011
On Friday 21 January 2011 06:10:26 Sean Eskapp wrote:Someone mentioned to me that scope declarations, e.g. scope class A{} or scope A myNewObject; are being removed from the language. Is this true? If so, how will RAII-type classes be implemented?std.typecons.scoped is the replacement for the builtin scope declaration. scope declarations are going away because they're inherently unsafe. Why they are then being put into the library, I'm not quite sure, other than the fact that D doesn't _stop_ you from doing unsafe stuff, it just seriously discourages it. I suppose that the big problem with having it in the language itself that the library solution doesn't quite have is that having it in the language kind of implies that it's okay and reasonable to do, which it isn't. It makes sense in specific circumstances, where you're know what all of the code involved is doing and can be sure that no reference to the scoped class will escape. And even then, why didn't you just make it a struct in the first place? There _are_ uses for scoped classes, but they're really not supposed to be the norm. They're unsafe, and you're begging for bugs if you use them heavily. - Jonathan M Davis
Jan 23 2011
scope declarations are going away because they're inherently unsafe.Pointers are inherently unsafe as well ;)
Jan 24 2011
On Monday 24 January 2011 00:37:40 Trass3r wrote:Well, you can't take those out of the core language and put them in the standard library. And there _are_ cases where pointers are perfectly safe. It's pointer arithmetic and taking the addresso of a local variable which is unsafe. Those are going to be restricted to SafeD. Andrei decided that scope was too unsafe to have in the language (and presumably Walter agreed) and it _can_ be put into the standard library. If you have a problem with it, take it up with him. - Jonathan M Davisscope declarations are going away because they're inherently unsafe.Pointers are inherently unsafe as well ;)
Jan 24 2011
Jonathan M Davis:Much of anything that requires code flow analysis doesn't tend to happen.Right. You need (lot of) work to implement it, in a system language it can't be fully accurate, and it may slow down compilation a little (Scala compiler is powerful, but I don't think it's very fast). But from using C lints I've seen that catching simple cases is better than catching none of them, and in SafeD the code is less wild so probably a higher percentage of cases can be caught. Currently DMD catches only very simple errors: class Foo {} Foo foo() { scope Foo f = new Foo; return f; // test.d(4): Error: escaping reference to scope local f } Foo bar() { scope Foo f = new Foo; Foo f2 = f; return f2; // no error here } void main() {} Something similar happens with this little C program compiled with -Wall with GCC: int *foo() { int a[5]; return a; } int *bar() { int a[5]; int *p = a; return p; } int main() { return 0; } GCC warns only about the first function: test.c: In function 'foo': test.c:3:5: warning: function returns address of local variable But a good C lint catches them both, statically (and the checking is very fast): test.c 3 Warning 604: Returning address of auto variable 'a' test.c 8 Warning 674: Returning address of auto through variable 'p' Bye, bearophile
Jan 24 2011