1. Java / Говнокод #13748

    +67

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /**
         * Удаляет "плохие" символы в пути и заменяет пробелы на символ подчеркивания.
         * Двойные кавычки заменяются на одинарные.
         * @param path путь.
         * @return путь с удаленными недопустимыми символами.
         */
    public static String correctPath(String path) {
            return correctPath(path);
    }

    Moloth, 06 Сентября 2013

    Комментарии (21)
  2. Куча / Говнокод #13747

    +121

    1. 1
    #include "commode.h"

    //development might be long and harassing
    //we'll need some furniture to keep food and coffee

    ckopo, 06 Сентября 2013

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

    +142

    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 string AddStr(string s1, string s2)
    		{
    			string result;
    			if (s1 == string.Empty)
    			{
    				result = s2;
    			}
    			else
    			{
    				if (s2 == string.Empty)
    				{
    					result = s1;
    				}
    				else
    				{
    					result = s1 + " " + s2;
    				}
    			}
    			return result;
    		}

    Код - бессмысленный и беспощадный

    leon_mz, 06 Сентября 2013

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

    +14

    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
    constexpr const char str1[] = "Anna";
    constexpr const char str2[] = "Denis";
    constexpr const char str3[] = "Vladimir";
    constexpr const char str4[] = "Alexey";
    
    constexpr const char *arr[] = { str1, str2, str3, str4 };
    
    #define GetMaxLenght(array) \
    constexpr unsigned char str_len(const char* const str) \
    {\
       return *str ? (1 + str_len(str + 1)) : 0;\
    }\
    \
    template <int index> \
    struct MaxLenght\
    {\
        static const int prev_size = MaxLenght<index-1>::max_size;\
        static const int cur_size = str_len(array[index]);\
        static const int max_size = cur_size > prev_size ? cur_size : prev_size;\
    };\
    \
    template <>\
    struct MaxLenght<-1>\
    {\
        static const int max_size = 0;\
    };\
    static const int AmountStr = sizeof(array) / sizeof(array[0]);\
    static const int array##_max_size = MaxLenght<AmountStr-1>::max_size;
    GetMaxLenght(arr);
    
    //   в *.cpp
    //   static_assert((arr_max_size == 8), "Error");

    http://habrahabr.ru/post/192736/

    LispGovno, 06 Сентября 2013

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

    +73

    1. 1
    2. 2
    String format = String.format("%%0%dd", 2); // format = "%02d";
    String seconds = String.format(format, milTime % 60);

    nikanmf, 06 Сентября 2013

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

    +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
    double vvod (double a1, double a2, double a3) {
     
    // a1=a a2=b a3=c
     
    	cout<<"Введите значение коэфицента a: ";
    	cin>>a1;
    	cout<<endl;
    	cout<<"Введите значение коэфицента b: ";
    	cin>>a2;
    	cout<<endl;
    	cout<<"Введите значение коэфицента c: ";
    	cin>>a3;
    	cout<<endl;
    	return (a1);
    	return (a2);
    	return (a3);
    }

    Оказывается в С++ можно возвращать 3 значения из функции
    http://ideone.com/tGWRpl - полная версия.

    pabloid, 05 Сентября 2013

    Комментарии (51)
  7. Objective C / Говнокод #13742

    −105

    1. 1
    2. 2
    3. 3
    4. 4
    NSArray* arry = [NSArray arrayWithObjects:arrayWithObjects:prev, next, nil];
    [arry performSelector:NSSelectorFromString(@"retain")];
    //---
    [actionSheet performSelector:@selector(setTag:) withObject:arry];

    АРЦ нельзя кастовать указатели? Хватит это терпеть!

    Psionic, 05 Сентября 2013

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

    −1

    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
    #include <iostream>
    using namespace std;
    
    struct NG
    {
    	template<class T>
    	struct get
    	{
    		typedef typename T::f type;
    	};
    };
    
    template <typename T, typename NameGetter>
    struct has_member_impl
    {
        typedef char matched_return_type;
        typedef long unmatched_return_type;
        
        template <typename C>
        static matched_return_type f(typename NameGetter::template get<C>*);
        
        template <typename C>
        static unmatched_return_type f(...);
        
    public:
        static const bool value = (sizeof(f<T>(0)) == sizeof(matched_return_type));
    };
    
    template <typename T, typename NameGetter>
    struct has_member{
       enum { value = has_member_impl<T, NameGetter>::value };
     };
     
     class T{};
    
    int main() {
    	cout<<has_member<T, NG>::value;
    	return 0;
    }

    http://ideone.com/4LDGhZ

    LispGovno, 04 Сентября 2013

    Комментарии (36)
  9. PHP / Говнокод #13739

    +149

    1. 1
    2. 2
    foreach (cms::hooks('template_output') as $hook_file)
       require($hook_file);

    хуки содержатся в отдельных файлах и вставляются в код напрямую.

    fidelcomandante, 04 Сентября 2013

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

    +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
    /* Формируемый запрос через Ajax */
    function MakeSearchQuery() {
        searchQuery = "";
    
        if (SearchDataQuery.CityFrom != "") {
            searchQuery = "CityFrom=" + SearchDataQuery.CityFrom;
    
            if (SearchDataQuery.Country != "") {
                searchQuery += "&Country=" + SearchDataQuery.Country;
    
                if (SearchDataQuery.Station != "" && SearchDataQuery.Station != "&Station=") {
                    searchQuery += "&Station=" + SearchDataQuery.Station;
                }
                if (SearchDataQuery.Date != "" && SearchDataQuery.Date != "&Date=") {
                    searchQuery += "&Date=" + SearchDataQuery.Date;
                }
            }
        }
    }

    Формируемый Ajax запрос

    sladkijBubaleh, 04 Сентября 2013

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