shared switch

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Oct 8 08:26:53 UTC 2023


On Sunday, October 8, 2023 12:27:20 AM MDT Imperatorn via Digitalmars-d wrote:
> I'm trying to explore what to do to get the maximum safety
> features for D.
>
> Not only safety, but also "logical safety"
>
> Like, @safe pure etc. Seems I should use nosharedaccess also then
> and probably dip1000, although we won't use pointers at all if
> possible.

Just be aware that when you're using -preview switches, you're typically
using features that are still changing as bugs (and sometimes even how the
feature works) get ironed out. So, there is a much higher risk of your code
breaking when using such switches, and depending on what happens with bugs
with and changes to those features, the changes that they force you to make
to your code may or may not actually be required in the long run.

As for those specific switches, issues with shared should be very rare in
your code, because it's almost certainly the case that very little of your
code should be using shared. So, while it may be worthwhile to see what the
compiler says when enabling the related switch, for most programs, it
shouldn't matter one way or the other - and when it does, it will typically
be a for a very small part of the program.

DIP 1000 is a thornier issue, because what they do with it seems to keep
changing, and dealing with it when stuff gets marked with scope (either
explicitly by you or implicitly be the compiler) can get annoying _really_
fast. Depending on what your code is doing, it could help you find issues,
or it could just be forcing you to mark a bunch of stuff with scope to shut
the compiler up about stuff that you're doing which is just fine. So,
enabling it might be valuable, or it could be almost purely irritating. That
being said, if you're not doing much with taking the address of local
variables or slicing static arrays and the like, there really isn't going to
be much for DIP 1000 to catch.

So, use the switches if you think that they'll benefit you, but be aware
that they're not yet standard D, and how stable they are can vary. So,
depending on what you're doing, they could easily cause more trouble than
they're worth - or they could catch issues for you and save you time and
trouble. It's hard to know which ahead of time.

- Jonathan M Davis





More information about the Digitalmars-d mailing list