[Issue 5559] A static down cast in Phobos

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 18 14:32:27 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5559



--- Comment #5 from bearophile_hugs at eml.cc 2012-12-18 14:32:24 PST ---
(In reply to comment #4)

> It's unsafe by default no matter if it's in the library or if you copy-paste it
> from the documentation.

D is a system language so despite things like @safe, D programmers have the
right to use unsafe features, when they want so.

And "unsafety" (and user code bugs) coming from an implementation bug is not
the same thing as "unsafety" (and user code bugs) coming from misuse of an
unsafe feature.

Also, having a common implementation of an unsafe feature, that uses one
standard name, allows people to recognize it, search for the "staticDownCast"
string it in codebases, and remove it if they want.


> There's no amount of unittests that will help you make
> static_cast bug-free and reliable.

I meant unittests on this library code, and not unittests of the user code.


> Remember that not everyone has a C++ background and they don't necessarily
> understand what static_cast is about, they could easily misinterpret this as
> just a faster version of a cast, while it's also unsafe.

See the answer above. D is a system language, and even in a language as Haskell
you sometimes want to use unsafe operations.


> We could add a huge bold docstring reading "this is unsafe", but I'm afraid not
> everyone reads the documentation.

Then rename it "unsafeStaticDownCast", it's long and clearly unsafe.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list