First of all, although the code is perfectly valid, it's not typical in the real application. More commonly, there's the separation of responsibilities: the model is defined in one or more source files and gets executed in another file or files. The initialization practically belongs to the latter, because only when the session starts, the memory gets allocated.
Secondly, const is not the only alternative to initialize the variable. Say, for instance, Xavier's initializer requires to have the whole graph structure to compute the number of incoming and outcoming connections and deduce the standard deviation from them. It just won't work if we tried to initialize the variable during the definition.
You can start it like this:
import tensorflow.contrib.eager as tfe
and it will save you from the boilerplate.
If you wish to learn about TensorFlow visit this TensorFlow Tutorial.