Consider a fixed, positive Point charge $q1$, kept at the origin. Another (positive) charge, $q2$, is being brought from $\infty$ to the point $(r,0)$, by an external agent slowly. We wish to calculate the work done by the external agent (and thus derive the "potential" of the point charge $q1$, being defined as $w_{ext}/q2$ (or as $-w_{electric}/q2$)). Suppose we consider a position $(x,0)$:
- The magnitude of force is going to be $kq1q2/x^2$. We will thus have, $\vec{F}=\dfrac{-kq1q2}{x^2}\hat{i}$.
- When we displace it from a position $(x,0)$ to $(x-dx,0)$, the displacement vector$(\vec{ds})$ will be $(x-dx)\hat{i}-x\hat(i)=-dx\hat{i}$.
- Using $dw$=$\vec{F}.\vec{ds}$, we will get $dw=\dfrac{kq1q2}{x^2}dx$. Upon integrating from $\infty$ (initial position) to $r$ (final position), we get : $$w_{ext}=-\dfrac{kq1q2}{r}$$ and thus $$V(r)= w_{ext}/q2 =-\dfrac{kq1}{r}$$ which is completely absurd. I tried to be as rigorous as possible with the definitions, vectors etc and yet a -ve sign has crept in somewhere.
The only issue seems to be with the treatment of $dx$. Although , I took $dx$ to be the magnitude of displacement, and accounted for the direction by using $-\hat{i}$.A possible argument seems to be "$x$ decreases, so $dx$ is a negative quantity. So the "magnitude" should be $-dx$. My two concerns:
- What is then, the issue with displacement=$\vec{r_{final}} - \vec{r_{initial}}$ that simply yields $-dx\hat{i}$?
- Simply "putting" a - sign before $dx$ after claiming "$dx$ is negative" seems to be arbitrary. There should be an argument (like I presented in the previous bullet point) that will produce the - sign for the magnitude, and thus making the vector $(-dx)(-\hat{i})$.
The main essence of this problem seems to be rigorously defining what $dx$ actually represents, for a quantity $x$.
I believe the entire thing can be summarized by one question:
What is wrong in writing displacement=$\vec{r_{final}} - \vec{r_{initial}}$ that simply yields $-dx\hat{i}$? If I had $(x+dx)$ instead of $(x-dx)$,then the derivation would be correct. But why is this the Case?

Consider the interval $[r,\infty)\subseteq\mathbb{R}$, the external force $$F_{ext}:[r,\infty)\rightarrow\mathbb{R}^3,\quad F_{ext}(x)=-\frac{kq1q2}{x^2}\hat{i}$$
and the given curve
$$s:[r,\infty)\rightarrow\mathbb{R}^3,\quad s(x)=x\hat{i}$$ along the work shall be calculated.
You can calculate the external work by choosing the right integration direction, i.e. integration from $\infty$ to $r$:
$$ \begin{align} W_{ext}=\int_\infty^r F_{ext}\cdot ds \end{align}$$
Alternatively you can calculate the external work by letting the so called displacement vector $ds$ point into the other direction and "just take the sum of that", i.e. integrate from $r$ to $\infty$ along $(-ds)$:
$$ \begin{align} W_{ext}=\int_r^\infty F_{ext}\cdot (-ds) \end{align} $$
Actually, it is the same, since
$$\int_\infty^r F_{ext}\cdot ds=-\int_r^\infty F_{ext}\cdot ds=\int_r^\infty F_{ext}\cdot (-ds)$$
If you do both, you will integrate from $r$ to $\infty$ again instead of $\infty$ to $r$. You will have reversed the integration direction and the direction of the displacement vector.
Note that you cannot change the given curve $s$, because this would be an integration along a different curve. However you can change the direction of integration by changing the direction of the displacement vector $ds$. For that, see the later discussion.
Finally it holds
$$ \begin{align} W_{ext}=-\int^\infty_r F_{ext}\cdot ds &=-\int_r^\infty\cos(\pi)\frac{kq1q2}{x^2}dx\\ &=kq1q2\int_r^\infty\frac{1}{x^2}dx\\ &=kq_1q_2\Big(-x^{-1}\Big|_{x=r}^{x=\infty}\Big)\\ &=kq_1q_2\frac{1}{r} \end{align}$$
Concerning the problem with the negative displacement vector:
This is the case, because you are thinking about a different curve then. A curve that is starting at $\infty\hat{i}$ and ending in $r\hat{i}$. Then its parametrisation is a little inconvenient to write down, but it is possible to change the direction of the curve: Let $R>r>0$. Define
$$s:[r,R]\rightarrow\mathbb{R}^3,\quad s(x)= (R+r-x)\hat{i}$$
Now this curve starts in $R\hat{i}$ and ends in $r\hat{i}$, i.e. "walks" in the right direction, such that
$$ds=-dx\hat{i}$$
Then, since the curve has already the right starting and endpoints, you will calculate the work along this(!) curve:
$$W_{ext}=\lim_{R\rightarrow \infty}\int_r^R F_{ext}(x)\cdot ds=\lim_{R\rightarrow \infty} \int_r^R \cos(0)\frac{kq1q2}{x^2}dx=\int_{r}^\infty\frac{kq1q2}{x^2}dx=kq_1q_2\frac{1}{r}$$
So it is not only important to know the curve itself (the set in $\mathbb{R}^3$, that is the curve), but also its orientation (the direction it is "walking" / its start and endpoints) if you want to integrate something along a curve. ($ds$ will always point from start to endpoint.)
But it's just easier to think of a fixed curve and just swap start and endpoints of the integral, if you want to integrate into the other direction.