I disagree, if OP was following too closely the collision would have happened. Instead OP had to take evasive action to avoid collision because driver in front did something unexpected.
I look forward to the day that self-driving cards are mandatory. Driving is one of the most excruciating things I endure in daily life and only because of the huge number of people on the roads exhibiting random and completely irrational behavior. If there is absolutely no rational reason to stop your car in the midst of moving traffic, then why do it?