Resolving a contradiction in the proof of expected value of Binomial distribution I've seen this proof in a text. I have an issue with it and wanted to check its validity. 
Let $X\sim B(n,p)$, we seek the expectation. We let $q=1-p$
\begin{equation}
E(X)=\sum_{j=0}^{n} j {n\choose j} p^{j}q^{n-j}=p\partial_{p}\sum_{j=0}^{n}  {n\choose j} p^{j}q^{n-j}=\underline{p\partial_{p} (p+q)^{n}} \quad\text{(Binomial Theorem)}
\\ =pn(p+q)^{n-1}.
\end{equation}
Now plugging in $p+q=1$ gives the required result. However at the underlined step ($p\partial_{p} (p+q)^{n}$), plugging in $p+q=1$ gives $0$. 
I'm aware of a couple of other ways to show this result so I am really just interested in whether this proof is valid. I'm not convinced that specifying a specific stage when we can plug in values constitutes a valid proof.
Thanks.
 A: You define a function 
$F(p,q)$. You eventually want to compute
$$
F(p,1-p)
$$
and in order to get to that, you compute $F(p,q)$ for every $(p,q)$ and 
then plug $q=1-p$.
As you use differentiation technique, plug first and then differentiate yields a different result.
A: There are a few common notations in mathematics where an object is used as a function, but it hides a declaration of an assumption.
One example is the line integral, consider (A0), the proposition $X = \oint_{\omega} y\,dz$ .  This is actually two propositions, one hiding in the other:
$$X = \int_\omega y\,dz \tag{A1}$$
$$\omega \text{ is a closed manifold } \tag{A2}$$
Suppose you were to assume (A0), derive some results, and then later add the assumption (A3) that $\omega$ is no longer a closer manifold.  Your results would be vacuous, since even though (A2) was never explicitly stated, it contradicts (A3).
...
Partial derivatives are another example of a function that hides an assumption.  The assumption (a0) that $x = \frac{\partial y} {\partial z}$ is actually two (or more) propositions:
$$x = \frac {dy}{dz} \tag{a1}$$
$$0 = \frac {d\text{ you have to guess these variables} } {dz} \tag{a2}$$
In your example, the formula $\frac{\partial \text{ stuff}}{\partial p}$ is hiding the assumption that $\frac{d q}{d p} = 0$.  The further addtion of $p + q = 1$, and thus $\frac{dp}{dq} = 1$ makes the final result vacuous, as you observed by the fact that you can get two different answers--  if you take what he wrote literally.
This is one of those situations where a pedantic person has to be told "read what I meant, not what I wrote".  The common practice of writing mathematics to be easily read rather than absolutely pedantically perfect is what makes the study tolerable, although it makes things like peer review very long painful processes of repeatedly asking "what did you really mean here?".
The author meant for you to infer that there is a way the derivation could be done which is correct.  Effectively, first you derive (d3):
Consider a functions 
  $$F_n(x,y) = \sum_{j=0}^{n} j {n\choose j} x^{j}y^{n-j} \tag{d1}$$
  $$G_n(x,y) = \sum_{j=0}^{n} {n\choose j} x^{j}y^{n-j} \tag{d2}$$
  $$x \frac{dG_n}{dx} = F_n \tag{d3}$$
Then you apply (d3) to the case of the binomial expectation.  (d3) is derived  just as a statement about functions, so $x$ and $y$ have no meaning outside of  (d3) and thus the additional assumption $p + q = 1$ has nothing to contradict.  Actually writing things out that way is tedious though, so except for the few people who are interested in formal logic a blind eye tends to be turned.
