"Code Sandwiches"
Nick Sabalausky
a at a.a
Wed Mar 9 13:30:27 PST 2011
"dsimcha" <dsimcha at yahoo.com> wrote in message
news:il8nlh$10c1$1 at digitalmars.com...
> == Quote from bearophile (bearophileHUGS at lycos.com)'s article
>> One of the things the paper says about D scope guards is: "Scope guards
>> do not
> provide encapsulation".
>
> (Rolls eyes.) I feel like this is a "standard" criticism of language
> features
> that's code for "I don't like this feature". IIRC they said the same
> thing about
> delegates in Java. Without even reading the paper, there are two reasons
> why this
> is an idiotic thing to say:
>
> 1. D also provides struct destructors, which are a more encapsulated way
> of
> accomplishing the same thing. Scope guards are intended for one-off use
> cases
> where declaring a type, etc. is just extra overhead and accomplishes
> nothing.
>
> 2. Encapsulation is only a means, not an end in itself. Sometimes people
> lose
> sight of this. The end goal is to write correct, efficient, readable,
> maintainable programs. If increasing encapsulation hurts these goals
> instead of
> helping them (as excessive encapsulation as practiced by
> obsessive-compulsive
> people does), then it's a Bad Thing.
Section 5.2 makes it clear that's not what he's trying to say.
Although, the second-last sentence of that section is "But [D's scope
guards] remain statements, not functions or classes, and thus do not form
reusable sandwich encapsulations." Frankly, though, that's true. Of course,
they can be used as part of a mechanism for creating a reusable "code
sandwich", but by themselves they're not an encapsulation and not intended
to be. And he never actually says that that's a bad thing. And if there's
any subtext inferring it's a bad thing, then as far as I can tell it's small
enough it may as well not even exist.
That said, I wouldn't put much stock in the average academic paper anyway.
(Although, from what little I read, this one doesn't seem quite as bad as
some. It's actually readable by programmers, which is a nice change from the
usual. And I didn't notice any blatantly stupid comments either. It doesn't
seem to make much of a point, but it does still seem to have value in
discussing the concept of "code sandwiches" and enumerating various
approaches to them.)
But why is it that academic authors have a chronic inability to release any
form of text without first cramming it into a goddamn PDF of all things?
This is one example of why I despise Adobe's predominance: PDF is fucking
useless for anything but printing, and no one seems to know it. Isn't it
about time the ivory tower learned about Mosaic? The web is more than a
PDF-distribution tool...Really! It is! Welcome to the mid-90's. Sheesh.
More information about the Digitalmars-d
mailing list