I agree with Retro, (I usually do, and if I don't I am the one that is generally wrong, but that is another story). The rule of thumb I use if it is shifting OK, I cut the new cables the same length.
I just installed the cables on a new build I am doing (waiting for one more part otherwise I would be riding) and I did something I always do, I cut the housings too long. The rational is I can always cut it shorter. However, I have a drawer full of housings!! I should try and cut them the proper size to start and if it binds I can just throw the housing away and start over. I just don't learn.
Truth is there probably is an ideal length but there seems to be quite a large acceptable variance.