They don't all become worthless after 3 years or so, though the ones that don't tend to be the ones you aren't going to want to sell.
Some categories of programming books whose utility and/or interest needn't drop much years after they were written: Algorithms books (Knuth, Cormen/Leiserson/Rivest/Stein). Books on fundamentals and high-level principles (SICP, Code Complete, Pragmatic Programmer, Design Patterns). Books whose tool-specific content relates to tools that aren't changing much (Paradigms of AI Programming, Thinking Forth) or at least that have a large enough stable-enough core (Effective C++).
(Note: "hasn't lost much value" isn't quite the same thing as "has a great deal of value". Some of those books are better than others.)
Some categories of programming books whose utility and/or interest needn't drop much years after they were written: Algorithms books (Knuth, Cormen/Leiserson/Rivest/Stein). Books on fundamentals and high-level principles (SICP, Code Complete, Pragmatic Programmer, Design Patterns). Books whose tool-specific content relates to tools that aren't changing much (Paradigms of AI Programming, Thinking Forth) or at least that have a large enough stable-enough core (Effective C++).
(Note: "hasn't lost much value" isn't quite the same thing as "has a great deal of value". Some of those books are better than others.)