1. Лучший говнокод

    В номинации:
    За время:
  2. Java / Говнокод #16045

    +68

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    class CircuitBreaker
    {
        boolean broken = false;
        CircuitBreaker() {}
        private void breakCircuit()
        {
            this.broken = true;
        }
        private boolean isBroken()
        {
            return this.broken;
        }
    }
    
    private boolean writeAssetsToDisk()
    {
        CircuitBreaker breaker = new CircuitBreaker();
        writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
        writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
        writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
        writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
        return !breaker.isBroken();
    }
    
    private void writeBase64EncodedAssetToDisk(CircuitBreaker breaker, String base64String, String filename)
    {
        if (breaker.isBroken()) {
            return;
        }
        ...
        try
        {
            ...
        }
        catch (IOException e)
        {
            breaker.breakCircuit(); return;
        }
        ...
    }

    Используй исключения, Люк. Фрагмент из Amazon Mobile Ads SDK.

    chaoswithin, 23 Мая 2014

    Комментарии (3)
  3. PHP / Говнокод #16035

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    function box_navigation($gc, $num, $id, $function, $act){
    	global $tpl, $page;
    	$gcount = $gc;
    	$cnt = $num;
    	$items_count = $cnt;
    	$items_per_page = $gcount;
    	$page_refers_per_page = 5;
    	$pages = '';		
    	$pages_count = ( ( $items_count % $items_per_page != 0 ) ) ? floor( $items_count / $items_per_page ) + 1 : floor( $items_count / $items_per_page );
    	$start_page = ( $page - $page_refers_per_page <= 0  ) ? 1 : $page - $page_refers_per_page + 1;
    	$page_refers_per_page_count = ( ( $page - $page_refers_per_page < 0 ) ? $page : $page_refers_per_page ) + ( ( $page + $page_refers_per_page > $pages_count ) ? ( $pages_count - $page )  :  $page_refers_per_page - 1 );
    	
    	if(!$act)
    		$act = "''";
    	else
    		$act = "'{$act}'";
    			
    	if($page > 1)
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', '.($page-1).', '.$act.'); return false">«</a>';
    	else
    		$pages .= '';
    				
    	if ( $start_page > 1 ) {
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', 1, '.$act.'); return false">1</a>';
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', '.($start_page-1).', '.$act.'); return false">...</a>';
    			
    	}
    					
    	for ( $index = -1; ++$index <= $page_refers_per_page_count-1; ) {
    		if ( $index + $start_page == $page )
    			$pages .= '<span>' . ( $start_page + $index ) . '</span>';
    		else 
    			$pages .= '<a href="" onClick="'.$function.'('.$id.', '.($start_page+$index).', '.$act.'); return false">'.($start_page+$index).'</a>';
    	} 
    			
    	if ( $page + $page_refers_per_page <= $pages_count ) { 
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', '.($start_page + $page_refers_per_page_count).', '.$act.'); return false">...</a>';
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', '.$pages_count.', '.$act.'); return false">'.$pages_count.'</a>';	
    	} 
    				
    	$resif = $cnt/$gcount;
    	if(ceil($resif) == $page)
    		$pages .= '';
    	else
    		$pages .= '<a href="/" onClick="'.$function.'('.$id.', '.($page+1).', '.$act.'); return false">»</a>';
    
    	if ( $pages_count <= 1 )
    		$pages = '';
    
    	$tpl_2 = new mozg_template();
    	$tpl_2->dir = TEMPLATE_DIR;
    	$tpl_2->load_template('nav.tpl');
    	$tpl_2->set('{pages}', $pages);
    	$tpl_2->compile('content');
    	$tpl_2->clear();
    	$tpl->result['content'] .= $tpl_2->result['content'];
    }

    дали проект чтобы разобрался)

    progsmile, 21 Мая 2014

    Комментарии (3)
  4. C++ / Говнокод #16019

    +11

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int FCEUI_SetCheat(....)
    {
      ...
      if((t=(char *)realloc(next->name,strlen(name+1))))
      ...
    }

    А пасиму оно на 2 байта меньше выделяет, насяльника?

    http://www.viva64.com/ru/examples/V518/

    gost, 19 Мая 2014

    Комментарии (3)
  5. Java / Говнокод #16014

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    class Matrix {
        ArrayList<ArrayList<Double>> arrayList = new ArrayList<ArrayList<Double>>();
        ...
    }

    Вот такая у нас реализация sparsed-матриц.

    kostoprav, 19 Мая 2014

    Комментарии (3)
  6. JavaScript / Говнокод #15979

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    $(document).ready(function() {
    	$('#about').click(function(about){    
    		$('#outside, #outside2, #outside3, #outside4, #outside5, #outside6, #outside7, #outside8, #outside9, #outside10, #outside11').fadeToggle('slow');
    	});
    
    	$('#whyus').click(function(whyus){    
    		$('#outsidewhy, #outsidewhy2, #outsidewhy3, #outsidewhy4, #outsidewhy5, #outsidewhy6, #outsidewhy7, #outsidewhy8, #outsidewhy9, #outsidewhy10, #outsidewhy11').fadeToggle('slow');
    	});
    
    	$('#portfolio').click(function(port){    
    		$('#outsideport, #outsideport2, #outsideport3, #outsideport4, #outsideport5, #outsideport6, #outsideport7, #outsideport8, #outsideport9, #outsideport10, #outsideport11').fadeToggle('slow');
    	});
    
    	$('#contact').click(function(con){    
    		$('#outsidecon, #outsidecon2, #outsidecon3, #outsidecon4, #outsidecon5, #outsidecon6, #outsidecon7, #outsidecon8, #outsidecon9, #outsidecon10, #outsidecon11').fadeToggle('slow');
    	});
    });

    В этом коде все хорошо и солнечно

    kostoprav, 14 Мая 2014

    Комментарии (3)
  7. SQL / Говнокод #15902

    −118

    1. 1
    2. 2
    3. 3
    RAISERROR ('Transaction (Process ID 53) was deadlocked on lock resources with another process 
    and has been chosen as the deadlock victim. Rerun thetransaction', 16, 1 );
    RETURN;

    гыгыгы

    bahamot, 05 Мая 2014

    Комментарии (3)
  8. C# / Говнокод #15891

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (result == true) {
                  return true;
              }
              else { return false; }
              return false;

    не баян, а классика

    dotFive, 03 Мая 2014

    Комментарии (3)
  9. C# / Говнокод #15839

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    private static Dictionary<RoleEnum, string> Roles = new Dictionary<RoleEnum, string>
            {
                {RoleEnum.TeamMember, "Team Member"},
                {RoleEnum.ProjectManager, "Project Manager"},
                {RoleEnum.ProgramManager, "Program Manager"},
                {RoleEnum.PortfolioManager, "Portfolio Manager"},
                {RoleEnum.Executive, "Executive"},
                {RoleEnum.Undefined, "Undefined"}
            };
    
            public static RoleEnum ParseRole(string role)
            {
                RoleEnum result = RoleEnum.Undefined;
                Roles
                    .Where(_ => _.Value == role)
                    .ToList()
                    .ForEach(_ => result = _.Key);
    
                return result;
            }

    Странное использование дикшинари, очень странное, в обратную сторону можна сказать

    boades, 24 Апреля 2014

    Комментарии (3)
  10. Python / Говнокод #15818

    −98

    1. 1
    2. 2
    3. 3
    4. 4
    if value is False:
        res = ~res
    elif not value is True:
        raise AnalyzeError("Invalid value {0}".format(condition.value))

    hugr, 22 Апреля 2014

    Комментарии (3)
  11. Pascal / Говнокод #15801

    +84

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    {*********** PosEx ***********}
    function Posex(const substr,str:string; const startloc:integer):integer;
    {Search for "substr" in "str" starting at "startloc" return 0 or the start
     postion where "substr" was found}
    var
      i, j,k,ssLen, sLen, stop:integer;
      a:char;
    begin
      result:=0;
      ssLen:=length(substr);
      slen:=length(str);
      stop:=slen-sslen+1; {highest feasible start location for substring}
      if (ssLen=0) or (sslen>sLen) then exit;
      a:=substr[1];  {1st letter of substr}
      i:=startloc; {start search location}
      while (i<=stop) and (result=0) do
      begin
        while (i<=stop) and (a<>str[i]) do inc(i); {find the 1st letter}
        if i<=stop then
        begin
          if sslen=1 then  result:=i {It was a 1 character search, so we're done}
          else
          begin
            j:=2;
            k:=i-1; {back "K" up by 1 so that we can use K+j as the index to the string}
            while (j<=sslen) do
            begin {compare the rest of the substring}
              if (substr[j]<>str[k+j]) then break
              else inc(j); {The letter matched, go to the next+
                       {When we pass the substring end, "while" loop will terminate}
            end;
            if (j>sslen) then
            begin
              result:=i;
              exit;
            end
            else inc(i); {that search failed, look for the next 1st letter match}
          end;
        end;
      end;
    end;

    Несколько вложенных циклов - это НЕ может работать быстро.
    Для сравнения - функция PosEx из StrUtils.pas

    function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;
    var
    I,X: Integer;
    Len, LenSubStr: Integer;
    begin
    if Offset = 1 then
    Result := Pos(SubStr, S)
    else
    begin
    I := Offset;
    LenSubStr := Length(SubStr);
    Len := Length(S) - LenSubStr + 1;
    while I <= Len do
    begin
    if S[i] = SubStr[1] then
    begin
    X := 1;
    while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) do
    Inc(X);
    if (X = LenSubStr) then
    begin
    Result := I;
    exit;
    end;
    end;
    Inc(I);
    end;
    Result := 0;
    end;
    end;


    А вот что пишет автор:
    The Delphi "Pos" function searches for a
    substring within a string. Later versions of
    Delphi also include a "PosEx" function
    which
    starts the search at a given position so
    multiple calls can return all occurrences.

    This program tests DFF versions of these
    two
    functions. Pos was rewritten to provide a
    base
    of code for PosEx. And PosEx wll provide
    the
    missing function for versions of Delphi
    before
    Delphi 7.

    As an unexpected bonus, it appears that the
    DFF versions of Pos and Posex are slightly
    quicker than the D7 versions.

    brutushafens, 20 Апреля 2014

    Комментарии (3)