First off, there is an easier way:
testPoly = x^3 + 3*x^2*y + 3*x^5*y^2 + y^3;
CoefficientRules[testPoly, All, "DegreeLexicographic"]
(* {{5, 2} -> 3, {3, 0} -> 1, {2, 1} -> 3, {0, 3} -> 1} *)
Given how we ordered the list, we can just extract the highest order and find the sum:
CoefficientRules[testPoly, All, "DegreeLexicographic"][[1, 1]] // Total
(* 7 *)
Others beat me to explaining the original code, but here's another approach that you can generalize. One thing I do to sort of deconstruct an incomprehensible chunk of code is to make some of the symbols into undefined symbols so that I can see what's happening at particular points. Let's just do that for everything even though we probably know what symbols like Max and Plus are going to do.
PolyDeg[expr_] := expr // ToListz // Exponentz[#, Variablesz[#]] & /@ # & // Plusz @@@ # & // Maxz;
Let's test with something simple
PolyDeg[x^2 + 1]
(* Maxz[ToListz[Plusz[1 + x^2, Variablesz[1 + x^2]]]] *)
Okay, honestly that didn't work out great, and it's because we MapApplyd the Plus (so it went "inside" the ToListz expression). But hey, ya gotta learn to fiddle with stuff. And we do see where the argument got "pasted" around in the result. So, let's revert ToListz back to ToList. One problem is that this isn't a built in function and you didn't provide the definition. I'm assuming that it should turn a polynomial into a list of monomials. So, we can do that with either MonomialList or with Apply[List]. Let's choose the former:
ToList = MonomialList;
PolyDeg[expr_] := expr // ToList // Exponentz[#, Variablesz[#]] & /@ # & // Plusz @@@ # & // Maxz;
PolyDeg[x^2 + 1]
(* Maxz[{Plusz[x^2, Variablesz[x^2]], Plusz[1, Variablesz[1]]}] *)
Okay, now we're cooking with gas. The input polynomial was de-structured into monomials and we did some fancy stuff with each monomial. Hmmm, where did Exponentz go to? Well, we mapped over a list, so at some point we have a list of expressions with head Exponentz. Then we MapApplyd Plusz, so the Plusz just replaced the Exponentz. So, at some point we had expressions like
Exponentz[x^2, Variablesz[x^2]]
Next thing to do is figure out what Exponent and Variables do. Read the documentation.... okay, they do pretty much what it sounds like they should do. Let's try them out:
Variables[x^2]
(* {x} *)
Exponent[x^2, Variables[x^2]]
(* {2} *)
Makes sense, and if we had more variables, we'd have longer lists of variables and exponents. Now it makes sense why we're MapApplying Plus--that's how we're getting the degree of each monomial. Since we understand that now, let's revert these two functions:
PolyDeg[expr_] := expr // ToList // Exponent[#, Variables[#]] & /@ # & // Plusz @@@ # & // Maxz;
PolyDeg[x^2 + 1]
(* Maxz[{Plusz[2], Plusz[]}] *)
Okay, we have a Plusz for the x^2 and one for the 1. Maybe we should do something a bit more complicated:
PolyDeg[x^2 + x^2 y^3 + 1]
(* Maxz[{Plusz[2, 3], Plusz[2], Plusz[]}] *)
Yep, looks like it's working as expected. At this point we can see what Plus and Max will do, so let's revert those:
PolyDeg[expr_] := expr // ToList // Exponent[#, Variables[#]] & /@ # & // Plus @@@ # & // Max;
PolyDeg[x^2 + x^2 y^3 + 1]
(* 5 *)
totalDegree[poly_, vars_] := Module[{t}, Exponent[poly /. Thread[vars -> RandomReal[{1, 2}, Length[vars]]*t], t]]$\endgroup$