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

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

    +106

    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
    function IsRunningWithAdminPrivs: Boolean;
    begin
    var
      List: TStringList;
    begin
      List := TStringList.Create;
      try
        try
          List.Text := 'Sample';
          // Use SHGetFolder path to retreive the program files folder
          // here is hardcoded for the sake of the example
          List.SaveToFile('C:\program files\test.txt');
          Result := True;
        except
          Result := False;
        end;
      finally
        List.Free;
        DeleteFile('C:\program files\test.txt');
      end;
    end;

    Нуфф Саид

    bugmenot, 22 Декабря 2010

    Комментарии (63)
  3. Куча / Говнокод #5005

    +144

    1. 1
    public static const INFINITY:int = 100000;

    а вы говорите, что скорость света недостижима... Вон, мы даже уже бесконечность обозначили!

    Lure Of Chaos, 21 Декабря 2010

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

    +111

    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
    [WebMethod]
    public PackageHoldResult RegisterHold(
        string login,
        string password,
        PackageHoldRequest holdRequest)
    {
        PackageHoldResult result = new PackageHoldResult();
        result.ResultCode = 0;
    
        try
        {
            // ...
        }
        catch
        {
            result.ResultCode = (int) PackageHoldRequestResultCode.InternalError;
        }
    
        return result;
    }

    Логирование?... что это?

    svkandroid, 23 Июля 2010

    Комментарии (63)
  5. Ruby / Говнокод #3394

    −92

    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
    def get_next_line(max_level, current_level, current_line_items)
            next_line_items = []
            result_string = ''
    
            if current_level == 1
                    next_line_items.push(1)
                    result_string = "1\n"
            else
                    current_line_number = false
                    current_line_number_count = 0
                    current_index = 0
    
                    current_line_items.each do |line_number|
                            if current_index == 0
                                    current_line_number = line_number
                                    current_line_number_count = 1
                            else
                                    if line_number == current_line_number
                                            current_line_number_count = current_line_number_count + 1
                                    else
                                            next_line_items.push(current_line_number_count)
                                            next_line_items.push(current_line_number)
    
                                            current_line_number_count = 1
                                            current_line_number = line_number
                                    end
                            end
    
                            if current_index >= current_line_items.length - 1
                                    next_line_items.push(current_line_number_count)
                                    next_line_items.push(current_line_number)
                            end
    
                            current_index = current_index + 1
                    end
    
                    result_string = next_line_items.join(' ') + "\n"
            end
    
            if current_level < max_level
                    result_string = result_string + get_next_line(max_level, current_level + 1, next_line_items).to_s
            end
    
            # return result
            result_string
    end
    
    puts 'Input max level:'
    level = gets
    
    puts ''
    puts get_next_line(level.to_i, 1, [])

    реальное тестовое задание кандитата.
    задача - вывести несколько членов последовательности
    1
    11
    21
    1211
    ....

    malleus, 04 Июня 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    string buf;
    ...
    char c_buf[MAX_LEN];
    strncpy(c_buf, buf.c_str(), MAX_LEN);

    в чём ошибка?

    skor4ik, 10 Мая 2010

    Комментарии (63)
  7. Go / Говнокод #28342

    +1

    1. 1
    Конструктор по умолчанию?

    Не, не слышали.
    Рефлексией итерируемся по свойствам и вызываем функцию инициализации полей ))))))))))))))

    3_dar, 22 Августа 2022

    Комментарии (62)
  8. JavaScript / Говнокод #27863

    0

    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
    type NetworkLoadingState = {
      state: "loading";
    };
    
    type NetworkFailedState = {
      state: "failed";
      code: number;
    };
    
    type NetworkSuccessState = {
      state: "success";
      response: {
        title: string;
        duration: number;
        summary: string;
      };
    };
    
    type NetworkState =
      | NetworkLoadingState
      | NetworkFailedState
      | NetworkSuccessState;
    
    
    function logger(state: NetworkState): string {
      switch (state.state) {
        case "loading":
          return "Downloading...";
        case "failed":
          // The type must be NetworkFailedState here,
          // so accessing the `code` field is safe
          return `Error ${state.code} downloading`;
        case "success":
          return `Downloaded ${state.response.title} - ${state.response.summary}`;
        default:
          return "<error>";
      }
    }
    
    function main() {
        print(logger({ state: "loading" }));
        print(logger({ state: "failed", code: 1.0 }));
        print(logger({ state: "success", response: { title: "title", duration: 10.0, summary: "summary" } }));
        print(logger({ state: "???" }));
        print("done.");
    }

    Ура... радуйтесь.... я вам еще говнокодца поднадкинул... ну и перекопал же говна в коде что бы это сделать. Дампик тут.. https://pastebin.com/u7XZ00LV Прикольно получается если скомпилить с оптимизацией то нихрена от кода не остается. и результат работы

    C:\temp\MLIR_to_exe>1.exe
    Downloading...
    Error 1 downloading
    Downloaded title - summary
    <error>
    done.

    ASD_77, 10 Декабря 2021

    Комментарии (62)
  9. Куча / Говнокод #27281

    +5

    1. 1
    2. 2
    3. 3
    inkanus-gray
    gost
    syoma

    Вернитесь.

    OCETuHCKuu_nemyx, 03 Марта 2021

    Комментарии (62)
  10. Куча / Говнокод #26981

    +2

    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
    Function/method calling convention. Here’s a simple example:
    
    struct Foo { a: i32 }
    impl Foo { fn bar(&mut self, val: i32) { self.a = val + 42; } }
    fn main() {
      let mut foo = Foo { a: 0 };
      foo.bar(foo.a);
    }
    
    For now this won’t compile because of the borrowing but shouldn’t the compiler be smart enough to create a copy of foo.a before call?
    I’m not sure but IIRC current implementation first mutably borrows object for the call and only then tries to borrow the arguments.
    Is it really so and if yes, why?
    Update: I’m told that newer versions of the compiler handle it just fine but the question still stands (was it just a compiler problem or the call definition has been changed?).
    
    The other thing is the old C caveat of function arguments evaluation. Here’s a simple example:
    
    let mut iter = “abc”.chars();
    foo(iter.next().unwrap(), iter.next().unwrap(), iter.next().unwrap());
    
    So would it be foo('a','b','c') or foo('c','b','a') call. In C it’s undefined because it depends on how arguments are passed on the current platform 
    (consider yourself lucky if you don’t remember __pascal or __stdcall). 
    
    In Rust it’s undefined because there’s no formal specification to tell you even that much. 
    And it would be even worse if you consider that you may use the same source for indexing the caller object like 
    handler[iter.next().unwrap() as usize].process(iter.next().unwrap()); in some theoretical bytecode handler 
    (of course it’s a horrible way to write code and you should use named temporary variables but it should illustrate the problem).

    https://codecs.multimedia.cx/2020/09/why-rust-is-not-a-mature-programming-language/

    3.14159265, 27 Сентября 2020

    Комментарии (62)
  11. Куча / Говнокод #26632

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Срочно нужна помощь с засылкой на хабр!
    
    Желательно перед этим почитать от того, что не пропустит анальная модерация и сектанты.
    
    Предложения так же жду в комментах. По тексту и в целом.

    https://tsar1997.blogspot.com/2020/05/blog-post_54.html

    Исходник пасты - просьба кидать патчи. Позже зашлю на хабр.

    https://pastebin.com/raw/haeHPx89

    3.14159265, 03 Мая 2020

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