1. Objective C / Говнокод #13463

    −120

    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
    - (NSManagedObject *)entityForName:(NSString *)entityName withServerID:(NSString *)serverID inContext:(NSManagedObjectContext *)context
    {
        if ((entityName==nil) || ([entityName isEqualToString:@""]) || (serverID==nil) || ([serverID isEqualToString:@""]))
        {
            return nil;
        };
    
        NSFetchRequest *fr=[[NSFetchRequest alloc] init];
        [fr setEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:context]];
        [fr setPredicate:[NSPredicate predicateWithFormat:@"server_id == %@", serverID]];
        [fr setIncludesPropertyValues:YES];
        NSError *err;
        NSArray *res=[context executeFetchRequest:fr error:&err];
        if (err!=nil)
        {
            NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: an error occured while gathering objects. %@ | %@ | %@", err.localizedDescription, err.localizedFailureReason, err.localizedRecoverySuggestion);
            return nil;
        }
        else
        {
            if ([res count]<=0)
            {
                NSLog(@"[res count]<=0");
                //NSLog(@"PTDataFetchHelper: findEntity:%@ withServerID:%@ inContext: not found", entityName, serverID);
                return nil;
            }
            else if([res count]>1)
            {
                NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: unable to fetch single object. server_id uniqueness error");
                return nil;
            }
            else //[res count] == 1
            {
                return [res objectAtIndex:0];
            };
        };
    }

    Фетч

    stanislaw, 21 Июля 2013

    Комментарии (20)
  2. Pascal / Говнокод #13462

    +141

    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
    if x > 0 then 
    begin
    if y <= 0 then 
    begin
    if z <> 0 then 
    begin
    if x1 > 0 then 
    begin
    if y1 < 7 then 
    begin
    if z1 > 0 then 
    begin
    if z1 mod 5 = 0 then 
    begin
    if m <> 3 then 
    begin
    if n > 5 then 
    begin
    writeln('1');
    end;
    end;
    end;
    end;
    end;
    end;
    end;
    end;
    end;

    iNsectus, 21 Июля 2013

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

    +134

    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
    #include <stdio.h>
    #include <stdint.h>
    #include <string.h>
    #include <inttypes.h>
    
    union Str
    {
       uint64_t a;
       char  str[8];
    };
    
    int main(void)
    {
      union Str str;
      memcpy( &str.str, "12345678", sizeof(str.a));
    
    
    str.a = ((str.a & 0x0F000F000F000F00)>>8) +
            ((str.a & 0x000F000F000F000F)*10);
    
    str.a = 1000000 * ((str.a >> 0 ) & 0xFF) +
              10000 * ((str.a >> 16) & 0xFF) +
                100 * ((str.a >> 32) & 0xFF) +
                      ((str.a >> 48) & 0xFF);
    //little-endian only. Можно переделать под big-endian
    
    printf("%"PRIu64, str.a);
    
    return 0;
    }

    Байтоебское преобразование строки из 8 цифр(в виде ascii символов) в число

    j123123, 21 Июля 2013

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

    +7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    namespace engine { namespace ui { class Console; } }
    
    class Dummy
    {
       engine::ui::Console * _ptr;
    };

    Решение проблемы с перекрёстными #include, когда классы должны хранить указатели друг на друга. Простое объявление class engine::ui::Console; не работает.
    Не в первый раз сталкиваюсь с этой проблемой из-за примитивной системы импорта.

    an0nym, 20 Июля 2013

    Комментарии (18)
  5. C++ / Говнокод #13456

    +17

    1. 1
    2. 2
    3. 3
    #if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
    #define main    SDL_main
    #endif

    Боже, за что??!

    http://hg.libsdl.org/SDL/file/75726efbf679/include/SDL_main.h

    bazhenovc, 19 Июля 2013

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

    +115

    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
    private string GenerateUserName(ISession session)
    {
      string userName = "";
      while (true)
      {
        if (IsBrand) userName = FName.Replace(" ", "");
        else userName = string.Format("{0}.{1}", FName, LName);
    
        if (String.IsNullOrEmpty(FName) && String.IsNullOrEmpty(LName))
        {
          userName = UserID.ToString();
        }
        else
        {
          var i = 0;
          while (UserBeanHelper.GetUserByUserName(session, userName) != null)
          {
            i++;
            userName = string.Format("{0}.{1}-{2}", FName, LName, i);
          }
        }
    
        UserTransferBean userByUserName = UserBeanHelper.GetUserByUserName(session, userName);
        if (userByUserName != null)
           ;
        else
        {
          break;
        }
      }
      return userName;
    }

    DarkThinker, 19 Июля 2013

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

    +5

    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
    #include <iostream>
     
    using namespace std;
     
    void f(void){cout<<"f"<<endl;}
    void f1(void){cout<<"f1"<<endl;}
     
    bool secondIfIsTryed(){cout<<"secondIfIsTryed"<<endl;return true;}
     
    #define asserts(Condition) {cout<<"Assert"<<endl;}
     
    int main() {
        if(true)
            if(secondIfIsTryed() && false)
                f();
            else
                f1();
        
        if(true)
            if(secondIfIsTryed() && false)
                asserts(true)
            else
                f1();
        return 0;
    }

    Помните того вечно сомневающегося знакомого, тест крестов, написанный которым я недавно приводил?
    http://ideone.com/9Q61D1
    В этот раз под его глуповатый, но пытливый взгляд попал макрос ассерта. Написан он конечно не так, как в этом тесте, но имеет код вида:

    #define asserts(Condition) {/*...*/}


    В итоге он сделал умозаключение: "Вокруг меня собрались голубцы" и надулся.

    LispGovno, 19 Июля 2013

    Комментарии (14)
  8. Куча / Говнокод #13452

    +124

    1. 1
    2. 2
    3. 3
    // Просрока быть недолжно.
            // Если нет платежа, то будет исключение.
            // Оба эти случая логически исключены, если медот не дергать в неположеном месте.

    dimkich, 19 Июля 2013

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

    +124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class Comparer : IComparer<int>
    {
        Random random = new Random();
    
        public int Compare(int x, int y)
        {
            return 1 - random.Next() % 3;
        }
    }

    Ccik, 18 Июля 2013

    Комментарии (21)
  10. Perl / Говнокод #13449

    −165

    1. 1
    if ( $method{'out_format'} && $method{'out_format'} eq lc(q{json}) ) {

    Yo dawg, we heard that you like lowercase, so we put some lowercase into your lowercase

    Elvenfighter, 18 Июля 2013

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