Ultimately there's no way to prevent sharing, because at some point you have to put trust in someone, and trust can always be violated.
Take eBook DRM (the "code to prevent sharing" you speak of). It tries to prevent the eBook file from being read on other systems and/or devices, however at the same time, the eBook formats are either open source, or have been reverse-engineered. So whilst Amazon will prevent you from opening DRM protected content on your Kindle, you could simply download a eBook reader that ignores DRM and open the eBook there.
By all means, add DRM if you think it's worth it, but unless you have evidence that you are losing income from your book being shared, it's probably not worth the bother.
Take eBook DRM (the "code to prevent sharing" you speak of). It tries to prevent the eBook file from being read on other systems and/or devices, however at the same time, the eBook formats are either open source, or have been reverse-engineered. So whilst Amazon will prevent you from opening DRM protected content on your Kindle, you could simply download a eBook reader that ignores DRM and open the eBook there.
By all means, add DRM if you think it's worth it, but unless you have evidence that you are losing income from your book being shared, it's probably not worth the bother.