The choice of whether to write binary hydrides with the hydrogen first or second depends on whether that hydrogen is considered acidic, with water marking the delineation point.
By convention, if a binary hydride is more acidic than water, then they are written in the form $\ce{H}_{\text{n}}\ce{X}$. If a binary hydride is less acidic than water, they are written as $\ce{YH}_{\text{n}}$. It so happens that this changeover neatly divides the periodic table. Binary hydrides from groups 16 and 17 (VIA and VIIA) are written with the hydrogen atoms first: $\ce{H2O,~H2S,~H2Se,~H2Te,~HF,~HCl,~HBr,~HI}$.
Binary hydrides from groups 1 (IA) through 15 (VIA) are all written with the hydrogen atoms last, regardless of whether the hydride is ionic $(\ce{LiH,~NaH,~KH,~CaH2})$ or molecular $(\ce{BH3,~CH4,~SiH4,~NH3,~PH3})$.
This notation is in keeping with that for more complex compounds. If the compound is an acid, the acidic hydrogen atoms are put at the from of the formula, while nonacidic hydrogen atoms are placed in the main part of the formula. For example, the hydrogen atoms in phosphoric acid $(\ce{H3PO4})$ are considered acidic and the hydrogen atoms in octane $(\ce{C8H18})$ are not. Acetic acid $(\ce{HC2H3O2})$ has one hydrogen atom that is considered acidic and three that are not, this the formula $\ce{HC2H3O2}$ is considered more helpful than $\ce{C2H4O2}$, although both are "correct" by different sets of rules.