1. C++ / Говнокод #12695

    +23

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    class ANameCreator
    {
    public:
                virtual void Create(const std::string& /*name*/)
                {
                    throw std::runtime_error("<ANameCreator::Create()> : abstract method stub call");
                }
    };

    odeni, 06 Марта 2013

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

    +18

    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
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    //main.cpp:
    #define THREAD_COUNT 2
    #include "winparallel.h"
    
    main1()
    {
        lock(1);
        int i=0; while(i++<10)
        printf("1: %d\n", i);
        unlock(1);
    }
    
    main2()
    {
        lock(1);
        int i=0; while(i++<10)
        printf("2: %d\n", i);
        unlock(1);
    }
    
    main3(){};
    main4(){};
    main5(){};
    main6(){};
    main7(){};
    main8(){};
    
    
    
    //=====================================================================================
    //winparallels.h:
    #include <windows.h>
    #define _MAX_CORES 8
    LPVOID _void;
    #define main1() DWORD WINAPI _main1(LPVOID lpParam)
    #define main2() DWORD WINAPI _main2(LPVOID lpParam)
    #define main3() DWORD WINAPI _main3(LPVOID lpParam)
    #define main4() DWORD WINAPI _main4(LPVOID lpParam)
    #define main5() DWORD WINAPI _main5(LPVOID lpParam)
    #define main6() DWORD WINAPI _main6(LPVOID lpParam)
    #define main7() DWORD WINAPI _main7(LPVOID lpParam)
    #define main8() DWORD WINAPI _main8(LPVOID lpParam)
    DWORD WINAPI _main1(LPVOID);
    DWORD WINAPI _main2(LPVOID);
    DWORD WINAPI _main3(LPVOID);
    DWORD WINAPI _main4(LPVOID);
    DWORD WINAPI _main5(LPVOID);
    DWORD WINAPI _main6(LPVOID);
    DWORD WINAPI _main7(LPVOID);
    DWORD WINAPI _main8(LPVOID);
    HANDLE _locks[_MAX_CORES];
    int _argc; char **_argv;
    void lock(int n) { DWORD res = WaitForSingleObject(_locks[n], INFINITE); }
    void unlock(int n) { ReleaseMutex(_locks[n]); }
    int main(int argc,char **argv) {
        HANDLE threads[_MAX_CORES];
        DWORD id;
        int THREADS = THREAD_COUNT;
        if (THREADS<=0) {
            SYSTEM_INFO sysinfo;
            GetSystemInfo(&sysinfo);
            THREADS = sysinfo.dwNumberOfProcessors;
            if (THREADS>_MAX_CORES) THREADS = _MAX_CORES;
        }
        _argc = argc; _argv = argv;    
        _locks[0] = CreateMutex(NULL,FALSE,NULL);
        _locks[1] = CreateMutex(NULL,FALSE,NULL);
        _locks[2] = CreateMutex(NULL,FALSE,NULL);
        _locks[3] = CreateMutex(NULL,FALSE,NULL);
        _locks[4] = CreateMutex(NULL,FALSE,NULL);
        _locks[5] = CreateMutex(NULL,FALSE,NULL);
        _locks[6] = CreateMutex(NULL,FALSE,NULL);
        _locks[7] = CreateMutex(NULL,FALSE,NULL);    
        threads[0]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main1,NULL,0,&id);
        if (THREADS>=2) 
        threads[1]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main2,NULL,0,&id);
        if (THREADS>=3) 
        threads[2]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main3,NULL,0,&id);
        if (THREADS>=4) 
        threads[3]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main4,NULL,0,&id);
        if (THREADS>=5) 
        threads[4]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main5,NULL,0,&id);
        if (THREADS>=6) 
        threads[5]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main6,NULL,0,&id);
        if (THREADS>=7) 
        threads[6]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main7,NULL,0,&id);
        if (THREADS>=8) 
        threads[7]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main8,NULL,0,&id);
        WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
        return 0;
    }

    >После этого всё что нужно освоить про потоки - работу с локами. Локи - это скандинавский бог приостановки потока.

    LispGovno, 05 Марта 2013

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

    +7

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class Pa || Ra || Ll || El
    {  
       int f || o || o; // четвертое ядро простаивает - надо длиннее переменные заводить
       int b || a || r;
    }
    
    int m || a || i || n(int argc, CHAR* argv[])
    { 
        Parallel parallel = new Pa() || Ra() || Ll() || El ();
    }

    LispGovno, 05 Марта 2013

    Комментарии (14)
  4. PHP / Говнокод #12692

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $_SESSION["db_options"] = array ('host'     => trim($this->IP).":".trim($this->Port),
    										'user'     => trim($this->User),
    										'password' => trim($this->Pass),
    										'database' => trim($this->DB)
    										);

    Наследование? Не, не слышал

    nonamez, 05 Марта 2013

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

    +114

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    private List<PalletePath> killDupes(List<PalletePath> pathesNew) {
    	List<PalletePath> noDupes = new ArrayList<PalletePath>();
    	for (PalletePath tp : pathesNew) {
    		if (!noDupes.contains(tp)) {
    			noDupes.add(tp);
    		}
    	}
    	return noDupes;
    }

    Set? Не, не слышали.

    someone, 05 Марта 2013

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

    −122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Если ВыгружатьВзаиморасчеты тогда
        Если ВыгружатьВзаиморасчеты() тогда
            УспешноВзаиморасчетыВыгружено=ВыгрузитьВзаиморасчетыНаСайт(СтруктураПараметровСайта);
        КонецЕсли;
    КонецЕсли;

    Херово, когда имен не хватает =(

    kovyl2404, 05 Марта 2013

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

    +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
    $code_date = strtotime($sms_action_date);
        $date = date(
            "Y-m-d H:i:s",
            mktime(
                date('H', $code_date),
                date('i', $code_date) + 30,
                date('s', $code_date),
                date("m", $code_date),
                date("d", $code_date),
                date("Y", $code_date)
            )
    );

    Определяем +30 минут грамотно.

    miraage, 05 Марта 2013

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

    +74

    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
    private boolean userInOneRegistrationNode() throws DfException {
    
            String uname = OrganizationStaffStructureHelper.getCurrentUserName();
    
            int i = 0;
            IDfCollection NodesCol = DQLHelper.getCollection(DQL_GET_REGISTRATOR_DIV, new String[]{uname});
            while (NodesCol.next()) {
                if (!(NodesCol == null)) {
                    String group_name = NodesCol.getString(GROUP_NAME);
                    i = i + 1;
                }
            }
    
            if (i == 1) {
                return true;
            }
            return false;
    }

    Заменяется 2мя строками один - select count(*), вторая - полученный результат Integer.ValueOf(...).

    Landing, 04 Марта 2013

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

    +140

    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
    [WebMethod]
            public void runCompareService(string mAuthToken, int documentId, int origVerNum, int revisedVerNum)
            {
                //string result = null;
                DirectoryInfo tmpDirInfo = getTempDirectoryPath(documentId);
                try
                {
                    //authToken = authClient.AuthenticateUser(username, password);
                    authToken = mAuthToken;
                    otAuth.AuthenticationToken = authToken;
    
                    try
                    {
                        string origFilePath = String.Format(tmpFilePath, tmpDirInfo.ToString(), origVerNum);
                        string revisedFilePath = String.Format(tmpFilePath, tmpDirInfo.ToString(), revisedVerNum);
                        string resultFilePath = String.Format(tmpResFilePath, tmpDirInfo.ToString(), origVerNum, revisedVerNum);
    
                        string origContextId = getDocContextId(documentId, origVerNum);
                        string revisedContextId = getDocContextId(documentId, revisedVerNum);
    
                        try
                        {
                            downlodFileByContextId(origContextId, origFilePath);
                            downlodFileByContextId(revisedContextId, revisedFilePath);
                            try
                            {
                                doCompare(origFilePath, revisedFilePath, resultFilePath);
                                try
                                {
                                    DownloadToBrowser(resultFilePath);
                                    
                                    //uploadResultToCS(targetId, resultFilePath);
                                }
                                catch (Exception e)
                                {
                                    throw new Exception(String.Format("Failed to Download To Browser. Error: {0}", e.ToString()));
                                }
                            }
                            catch (Exception e)
                            {
                                throw new Exception(String.Format("Failed to do compare method . Error: {0}", e.ToString()));
                            }
                        }
                        catch (Exception e)
                        {
                            throw new Exception(String.Format("Failed to create and download file. Error: {0}", e.ToString()));
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Failed to get Context ID for version Exeption details: " + e.ToString());
                    }
    
                }
                catch (Exception e)
                {
                    throw new Exception("Failed to auth user. Exeption details: " + e.ToString());
                }
                finally
                {
                    docManClient.Close();
                    contentServiceClient.Close();
                    if (Directory.Exists(tmpDirInfo.ToString()))
                    {
                        tmpDirInfo.Delete(true);
                    }
                }
                
            }

    Landing, 04 Марта 2013

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

    +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
    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
    using System;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using System.Text;
    using System.Xml.Linq;
    
    namespace SplitSpace {
      class Program  {
        static void Main(string[] args) { 
            test();
        }
      
        static void test() {
          if(testfun(0, 0, 3, 1020, 0.05*180/Utils.PI, 1,  40, 5.80020838542985, 5.80020838542985, 0.0125032560359095)) return;
          if(testfun(0, 0, 3, 1020, 0.05*180/Utils.PI, 2,  5, 1.75, 9.85005209635745, 0.00156290700448869)) return;
          if(testfun(0, 0, 3, 1020, 0.05*180/Utils.PI, 3,  1.5, 0.0375078144536192, 0.0375078144536192, 0.000468872101346607)) return;
          if(testfun(0, 0, 3, 219, 0.00, 1,  15.000, 4.900000000, 4.900000000, 0.000000000)) return;
          if(testfun(0, 0, 3, 219, 0.50, 1,  15.000, 4.900000415, 4.900000415, 0.000142791)) return;
          if(testfun(0, 0, 3, 219, 5.00, 1,  15.000, 4.900415674, 4.900415674, 0.014290277)) return;
          if(testfun(0, 0, 3, 219, 5.10, 1,  15.000, 4.900441130, 4.900441130, 0.014868082)) return;
          if(testfun(0, 0, 3, 219, 5.90, 1,  15.000, 4.900683170, 4.900683170, 0.019903983)) return;
          // Спустя 8369 строчек
          // ...
          // ...
          // ...
          if(testfun(2, 1, 4, 1420, 55.00, 2,  7.000, 5.512975201, 5.512975201, 1.316853521)) return;
          if(testfun(2, 1, 4, 1420, 60.00, 2,  7.000, 5.817691454, 5.817691454, 1.558845727)) return;
          if(testfun(2, 1, 4, 1420, 66.00, 2,  7.000, 6.589343466, 6.589343466, 1.708953962)) return;
          if(testfun(2, 1, 4, 1420, 75.00, 2,  7.000, 7.385125168, 7.385125168, 2.367207113)) return;
          if(testfun(2, 1, 4, 1420, 85.10, 2,  7.000, 8.438873737, 8.438873737, 3.248627191)) return;
          if(testfun(2, 1, 4, 1420, 89.00, 2,  7.000, 8.848026526, 8.848026526, 3.610990132)) return;
          if(testfun(2, 1, 4, 1420, 89.99, 2,  7.000, 8.932590260, 8.932590260, 3.699354242)) return;
          if(testfun(2, 1, 4, 1420, 90.00, 2,  7.000, 8.932590181, 8.932590181, 3.700000000)) return;
    
          MessageBox.Show("OK!"); 
        }
    
        static bool testfun(int dir, int coolType, int hotType, double dia, double angG, int angType,  double Rad, double Tan1, double Tan2, double Bis) {
          // тут всякие тесты
          // ...
          // ...
          // ...
          return false;
        }
    
      } 
    }

    diimdeep , 04 Марта 2013

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