I decided I'll resign by the end of the year and I'm thinking if it's better to tell my boss about it now or to tell him when the resignation date is close.
If I tell him now is good because I give them enough time to look for a replacement but is bad because I'll be in a weird limbo for three months.
If I tell him days before leaving they'll have less time to look for a replacement but I'll avoid being in a employee/non employee limbo.
What do you think?
For example, by policy, some companies would require your boss to advise HR and terminate your network/building access as soon as you give notice. In that case, your early notice either leaves your boss violating policy, or leaves you unemployed with two weeks pay in lieu of notice (of them terminating you). If in doubt, and if you have that close relationship, you may want to discuss your departure on a general and hypothetical basis first before discussing specifics.
Still try to avoid surprising your boss, as much as you can. For example, you could try to take on more maintenance and documentation work, and fewer new projects. A good manager may get the hint, and will appreciate the consideration in retrospect even if not. There's also a small but non-zero chance that a bad manager would turn this into a reason to fire you, so judge the tradeoff against that long-term relationship carefully.