The main difference is that using
\afterassignment you can preserve the assignment syntax.
So in your counter example any number of tokens following
\dosomething would be expanded until a sequence of non expandable tokens making a
<number> are scanned. The second version forces a macro-argument syntax where the number has to be given as a single token or brace group. Which is preferable depends on what you are trying to do.
Another example from the latex sources
\protected@edef takes the syntax of
\edef with delimited arguments etc and restores the meaning of
\protect after the
\edef. So you can do
It would be rather less convenient to do that without using
Another, perhaps better, example again based on usage in the latex base, the following plain TeX file
This is setting
\dimen0 to a user-specified length where the argument may omit the units (defaulting to
pt) or give explicit units, or be a TeX dimen register or primitive such as
\vsize. By using
\afterassignment the primitive assignment may or may not use tokens after
pt\relax will be used if the argument is a
<number> but not if it is already a dimension. Because
\removetonil is inserted immediately after the assignment it can clear away any unused tokens.