assert() vs. enforce(), invariant() vs. ... ?
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Aug 30 14:43:28 PDT 2013
On Fri, Aug 30, 2013 at 02:11:32PM -0700, Andrei Alexandrescu wrote:
> On 8/30/13 11:20 AM, Namespace wrote:
> >>Typedef was useful not for poking around new type with same
> >>properties - new name of existing type, but for non-trivial default
> >>value:
> >>
> >>typedef int myint = 1;
> >>
> >>void main()
> >>{
> >> myint my;
> >> assert(my is 1);
> >>}
> >>
> >>Alias does not provide this feature, so D hadn't become better with
> >>this depreciation (actually the opposite). Nor it had with delete
> >>operator depreciation for the replacement of destroy, which like in
> >>case with typedef, does not cover full old feature functionality
> >>(and functionality what destroy() does provide is useless in many
> >>cases). I consider both depreciations as mistakes.
> >
> >Thanks for explanation. I agree that the deprecation of typedef and
> >delete is/was a mistake, and IMO the deprecation of scope and the
> >library fix scoped is the same mistake.
>
> * typedef: it was so ill defined, bringing it any closer to sanity
> would've broken someone's code.
Hmm. Is default values the only use case for typedefs? If so, we can
already do it without:
struct myint {
int _impl = 1;
alias _impl this;
}
myint x;
assert(x==1);
Works on git HEAD.
> * delete: a festering dung of unsafety straight in the middle of the
> language. If there's enough argument that the functionality of delete
> is actually desirable we can always add a function for that.
Well, there's destroy, but last I heard, destroy has some pretty nasty
issues on its own... (Not that I'd know anything about it, though,
haven't needed to use it. Fortunately.)
> * scope: cute and dangerous in equal proportions - great for a movie
> character, terrible for language design.
[...]
What's so terrible about it?
And what other solution(s) are there? I only just found out about the
library 'scoped' today, and apparently it isn't having a good time
either.
T
--
PNP = Plug 'N' Pray
More information about the Digitalmars-d
mailing list