Q:

に越したことはない Wondering about the に

I am having troubles figuring out what the use of the に in に越したことはない is.
I searched for almost an hour on internet but didn't find anything that could possibly answer my question.
Because we put it directly after the 連体形 of a verb, it must be an old use of に that remains common today but I can't find exactly what it's meaning is.
I thought it was the に that we use when we say like 
私には妹がいる。: There is a sister to me.
So for exemple :
食べるに越したことはない。 would mean : there is no thing that is beyond to [eat]
But i'm not sure at all whether my guess is right or not.
Somebody help me please, thanks

A:

I think this grammar is a remnant of classical Japanese, where nominalizer こと was unnecessary and the dictionary form by itself functioned as a noun. You can find this usage today mainly in proverbs:

逃げるが勝ち = 逃げることが勝ち
聞くは一時の恥、知らぬは一生の恥 = 聞くことは一時の恥、知らないことは一生の恥
袖振り合うも他生の縁 = 袖(が)振り合うことも他生の縁(だ)

As you can see, the following particle can be anything. So 食べるに越したことはない is 食べることに越したことはない, and means "There is nothing that is better than eating", or less literally, "Nothing is as good as eating".

Here X + に + 越す obviously means "to be better than X", "to surpass X". However, in modern Japanese, 越す is not used in this way, because it's a transitive verb. デジタル大辞泉 treats Xに越したことはない as a special idiomatic usage.

５ （「…にこしたことはない」のように打消しの表現を伴って）…するのがいちばんよい。「早いに―・したことはない」

Unfortunately, an online dictionary of old Japanese (学研古語辞典) doesn't explain Xに越す at all. So I don't know how common Xに越す was in archaic Japanese. That being said, the particle に is still commonly used for marking something that is compared with the subject. There are expressions such as "～に匹敵する", "～に並ぶ", "～に及ぶ", "～に似る", and so on, all of which are very common today. So I guess に in Xに越す can be understood along the lines of these expressions.

