1. PHP / Говнокод #5686

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $this->setLayout('empty');
            $this->setTemplate('step3');
    
            if ($this->getBrokerId() == 19 || $this->getBrokerId() == 29)
            {
                $this->setLayout('empty');
                $this->setTemplate('step3');
                $this->brokerId = $this->getBrokerId();
            }

    Нашел в чужом проекте. При этом $this->getBrokerId() не просто возвращает переменную, а производит сравнение строк (то есть вызывать этот метод 3 раза - явный перебор).

    blaster999, 15 Февраля 2011

    Комментарии (2)
  2. C# / Говнокод #5685

    +123

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    string callPage = CallPage;
    if (callPage != "Checkout.aspx")
    {
          callPage = "Checkout.aspx";
    }
    ServerTransfer(callPage + "?makerefresh=true", Server, Request);

    Найди лишнее

    uaavg, 15 Февраля 2011

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

    +159

    1. 1
    2. 2
    3. 3
    $ar=$arFields['GROUP_ID'];
    $arFields['GROUP_ID']=array();
    foreach($ar as $a) $arFields['GROUP_ID'][]=$a;

    Смысл данной конструкции не ясен, если так нужно обнулить ключи для массива то array_values() в помощь.

    tkf, 15 Февраля 2011

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

    +113

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                string[] exit_program = { "1", "2", "3", "4", "5", "6" };
                bool flag = true;
                while(flag)
                {
                    Console.WriteLine("Введите команду");
                    string ss = Console.ReadLine();
    
                    for (int i = 0; i < exit_program.Length&&flag;i++)
                    {
                        
                        if (ss == exit_program[i])
                        {
                            Console.WriteLine("Вы ввели {0} и теперь можете выйти из цикла",ss);
                            flag = false;
                            break;
                        }
                                  
                    }
                    
                    
    
                   
                }
    
                Console.ReadLine();
              
            }
        }
    }

    Говнокод, позволяющий выйти из консольного приложение по нажатию цифр 1,2....6

    user12, 15 Февраля 2011

    Комментарии (37)
  5. PHP / Говнокод #5682

    +164

    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
    <?php
    class Gcont extends Controller {
    
    // ...
        
        function gcont(){
            $this->load->model('am_loader');
            $title = $this->am_loader->gettitle();
            echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"';
            echo '<html xmlns="http://www.w3.org/1999/xhtml">';
            echo '<head><title>'.$title.'</title>';
     
    // ...
            
            $this->load->view('gcont');
            
        }
    }

    Суровая генерация контента нубом из контроллера MVC.

    Sony, 15 Февраля 2011

    Комментарии (16)
  6. C# / Говнокод #5681

    +116

    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
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    public static class ControlManager
        {
            public static UIElement GetControlByName(UIElement control, string name)
            {
                if (EntityType.GetValue(control, "Name").Equals(name))
                    return control;
                if (EntityType.IsProperty(control, "Children"))
                {
                    foreach (var element in (UIElementCollection)EntityType.GetValue(control, "Children"))
                    {
                        if (EntityType.GetValue(element, "Name").Equals(name))
                            return element;
                        var temp = GetControlByName(element, name);
                        if (temp != null)
                            return temp;
                    }
                }
                if (EntityType.IsProperty(control, "Child"))
                {
                    var element = (UIElement)EntityType.GetValue(control, "Child");
                    if (EntityType.GetValue(element, "Name").Equals(name))
                        return element;
                    var temp = GetControlByName(element, name);
                    if (temp != null)
                        return temp;
                }
                if (EntityType.IsProperty(control, "SelectionElement"))
                {
                    var element = (UIElement)EntityType.GetValue(control, "SelectionElement");
                    if (EntityType.GetValue(element, "Name").Equals(name))
                        return element;
                    var temp = GetControlByName(element, name);
                    if (temp != null)
                        return temp;
                }
                return null;
            }
    
            public static UIElement GetControlByType(UIElement control, Type type)
            {
                if (control.GetType() == type)
                    return control; 
                if (EntityType.IsProperty(control, "Children"))
                {
                    foreach (var element in (UIElementCollection)EntityType.GetValue(control, "Children"))
                    {
                        if (element.GetType() == type)
                            return element;
                        var temp = GetControlByType(element, type);
                        if (temp != null)
                            return temp;
                    }
                }
                if (EntityType.IsProperty(control, "Child"))
                {
                    var element = (UIElement)EntityType.GetValue(control, "Child");
                    if (element.GetType() == type)
                        return element;
                    var temp = GetControlByType(element, type);
                    if (temp != null)
                        return temp;
                }
                if (EntityType.IsProperty(control, "SelectionElement"))
                {
                    var element = (UIElement)EntityType.GetValue(control, "SelectionElement");
                    if (element.GetType() == type)
                        return element;
                    var temp = GetControlByType(element, type);
                    if (temp != null)
                        return temp;
                }
                return null;
            }
        }

    Автор тот же.
    Этот код пошатнул мою психику. А может так и надо. а?
    всё-таки stringly-static programming....

    tubus, 15 Февраля 2011

    Комментарии (10)
  7. JavaScript / Говнокод #5680

    +172

    1. 1
    var rus_rl = ('А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я-а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я').split('-');

    vugluskr, 15 Февраля 2011

    Комментарии (20)
  8. PHP / Говнокод #5679

    +163

    1. 1
    $sIsPublic = ($oPageInfo->is_public == 'true') ? 'false' : 'true';

    1_and_0, 15 Февраля 2011

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

    +115

    1. 1
    2. 2
    3. 3
    4. 4
    ViewData["PlanActivated"] = ((model.Count > 0) && (model.First().PlanActivate == true) 
                     && (model.First().PredictActivate == true) 
                     && (model.First().FactActivate == true)) 
                     ? true : false;

    Даже не стал разбираться, стер и переписал....

    fr0mrus, 15 Февраля 2011

    Комментарии (2)
  10. PHP / Говнокод #5677

    +171

    1. 1
    <?php eval(gzinflate(base64_decode('s7ezsS/IKODl4uVKzkksLlYISS0uUagG8RXSSvOSSzLz88BiGpogUQUFhdTkjHwFJUeFEqCgkjVQqBZVcXF+bmo8iKehkgjTU5RaUlqUp6CSqKCtYATXU2tjDwA='))); ?>

    Сегодня приятель спросил «а есть смысл сжимать PHP» и выдал вот эту хуйню. Сказал, что все свои проекты так сжимает. Как такое поддерживать потом?

    proxor, 15 Февраля 2011

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