There seems to be some consensus about defining \dif like this:
\newcommand{\dif}{\mathop{}\!\mathrm{d}}
Should I \mathrm the d in my integrals?, What is the difference of \mathop, \operatorname and \DeclareMathOperator?, new command for the dx of intergral., Should I \mathrm the d in my integrals?
This looks fine in
\int f(x) \dif x
but not so much in
\int \dif x f(x)
What is the best alternative (or extension) when using the latter notation?
Here's an MWE which nicely shows the difference -- the second line is even shorter than the first:
\documentclass{article}
\newcommand{\dif}{\mathop{}\!\mathrm{d}}
\begin{document}
$\int f(x) \dif x$
$\int \dif x f(x)$
\end{document}

Would
\newcommand{\dif}[1]{\mathop{}\!\mathrm{d}#1\mathop{}}
be a good solution? It certainly looks better.
#1is usually a ordinary math atom (variable), then there will always a thin space between#1and\mathop{}. In may situations this space is wrong, e.g. when a closing bracket follows. At the end of a centered equation the centering is then off by a half thin space. Therefore I would at least remove that space:#1\!\mathop{}. A thin space remains, if another ordinary atom (f) or another operator\intfollows. – Heiko Oberdiek May 22 '15 at 16:47