Си диез / Говнокод #8572 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
/// <summary>
/// Calculates and returns a hashcode based on this user's
/// MarketName and default units. The hashcode should be
/// unique for each different combination of MarketName and 
/// units.
/// </summary>
/// <returns>An int that may be positive or negative.</returns>
public override int GetHashCode()
{
// A function like this raises innumerable questions.  Why did they over ride the 
// hash code function?  Why did they use an attribute that is not certain to be unique?
// why did they not use the one that is going to be unique?  Why did they not cvheck to 
// see if the thing they were hasing was not null?  When did my life go so far off the rails
// that I have to deal with code like this?  How many places call this code? Why did they not 
// include any meaningful comments? Why does it suddenly start breaking after the 3.5 upgrade?
// in an effort to avoid thinking about those questions, I've justy changed the has to use the 
// unique user id instead of the retarded defaultuserunits hash.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(this.MarketName);
if (this.DefaultUserUnits != null)
{
  sb.Append(Utility.StringUtility.GetJSObjectLiteral(this.DefaultUserUnits));
}
else
{
  sb.Append(Utility.StringUtility.GetJSObjectLiteral(this.ID));
}
  return sb.ToString().GetHashCode();
}

Запостил: aprishchepov aprishchepov, (Updated )

Комментарии (6) RSS

  • Наижутчайший пиздец! facepalm

    Был бы это нормальный форум, расписал бы. А так просто приведу ссылку:
    http://blogs.msdn.com/b/ericlippert/archive/2011/02/28/guidelines-and-rules-for-gethashcode.aspx
    Автору сего гк обязательно к ознакомлению! Особенно обратить внимание на то, что String.GetHashCode может возвращать разные значения в разных версиях рантайма.
    Ответить
    • так в чем ГК то?

      и какое имеет значение что в разных версиях - разный результат? Они же не пароль хешируют для хранения в базе.
      Ответить
  • э$K"D?D.A)Q.G"N:U"U:Q J?S!Z?I"R,H!Q?WA(U"V.H$P?B.G.A?K.S$F(X)M.D.A$R,GF.ZVN Q$Y I R!L:H(S?E:U!BA(Y)M(G"X"R(U.I:P$M"F(H(U.D)P,K)R!N)F:M:V:Q,M?K.G P(Z?Z!D:H"Z"I,U)M!G:N:G Y W$Z$K P:Y"G?R!P,S(H,C,F!K"V,H)H.P!S"S?T(Q)DФBNFLIOJFHOAHPTVWIOKFMQBCLBCFWELFUQENRLYDSACDCBVISISL
    Ответить
  • - Давай-ка задом, мила, - я шлёпнул Елену по ляжке, и она неловко перевернулась, встала на колени, высоко подняла зад.
    Ответить

Добавить комментарий

Помни, guest, за тобой могут следить!

    А не использовать ли нам bbcode?


    8