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

    +80

    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
    public class лаба22 {
    	int i;
    	лаба22(int k){
    	
    		i=k;}
    	
    	int [] a = new int [i];
    	
    	void длина(){
    		System.out.println(a.length);
    	}
    	public static void main(String[] args) {
    		лаба22 s = new лаба22(5);
    		s.длина();
    	}
    }

    Студеньтики... тупоголовые как и их преподы

    argamidon, 24 Февраля 2015

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

    +133

    1. 1
    2. 2
    HTTP referer (originally a misspelling of referrer) is an HTTP header field that identifies the address of the webpage
    (i.e. the URI or IRI) that linked to the resource being requested.

    Originally a misspelling of referrer...

    bormand, 24 Февраля 2015

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

    +133

    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
    public string GenerateWinCode(String PrefixWinCode, String Name, String LastName, String NameCompany, bool IsCompany = false)
            {
                string _NormalWinCode = "";
                if (!IsCompany)
                    _NormalWinCode = (PrefixWinCode + Name[0] + LastName[0]).ToUpper();
                else
                {
                    var i = 1;
                    try
                    {
                        while (String.IsNullOrWhiteSpace(NameCompany[i].ToString()))
                        {
                            i++;
                        }
                        _NormalWinCode = (PrefixWinCode + NameCompany[0] + NameCompany[i]).ToUpper();
                    }
                    catch (Exception)
                    {
                        _NormalWinCode = (PrefixWinCode + NameCompany[0] + NameCompany[0]).ToUpper();
                    }
                }
                if (PrefixWinCode == "IN")
                    throw new RuleException("ErrorWincode", Resources.Accounts.Account.WincodeInvalid);
                try
                {
                    using (var context = db)
                    {
                        var _WincodesSim =
                            (from q in context.UserPartners.Where(m => m.WinCode.ToUpper().StartsWith(_NormalWinCode))
                             where q.WinCode.Length > 4
                             select q.WinCode).ToList();
                        var _Sufix = _WincodesSim.Select(m => Convert.ToInt32(m.Substring(4))).Max();
                        return _NormalWinCode + (_Sufix + 1);
                    }
                }
                catch (InvalidOperationException)
                {
                    return _NormalWinCode + 1;
                }
            }

    Генерация уникальных ключей

    AndrewTakker, 24 Февраля 2015

    Комментарии (2)
  4. Java / Говнокод #17686

    +77

    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
    public static void main(String[] args) {
            testIndiaLazy();
        }
    
        private static void testIndiaLazy() {
            LazyInstantiator lazyInstantiator = new LazyInstantiator();
            lazyInstantiator.getInstance();
            lazyInstantiator.getInstance();
        }
    
        public static class LazyInstantiator {
            private Object instance;
    
            public Object getInstance() {
                System.out.println("getInstance");
                if (instance != null || create());
                return instance;
            }
    
            private boolean create() {
                System.out.println("create");
                instance = new Object();
                return true;
            }
        }

    Out:
    getInstance
    create
    getInstance

    dmli, 24 Февраля 2015

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

    +137

    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
    #include <time.h>
    
    
    int rrand(int start, int end)
    {
    	int range=end-start+1;
    	int speed=1;
    	int base=0;
    	int rez=start;
    	if(range>200) speed=range/100;
    	while(range>=0)
    	{
    		srand(clock());
    		if(rand()%2) base=base+speed+1;
    		else base--;
    		rez=rez+base;
    		rez=(rez < start)? end-rez : rez;
    		rez=(rez > end)? (rez%end)+start : rez;
    		range=range-speed;
    	}
    	return rez;
    }

    случайные числа в определенном диапазоне...

    pl7ofit, 24 Февраля 2015

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

    +137

    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
    public bool StartListener()
    		{
    			bool flag;
    			try
    			{
    				flag = (this.m_Listener.BeginAccept() ? true : false);
    			}
    			catch (Exception exception)
    			{
    				CAssert.ReportAssert(exception);
    				flag = false;
    			}
    			return flag;
    		}

    Из реального корпоративного проекта.

    Danmer, 23 Февраля 2015

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

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if(!item.contact.middleInitial)
                  {
                    fullAddress = item.contact.firstName+' '+item.contact.lastName+' '
                    +item.contact.companyName+' '+item.streetLine1 +' '+item.city +', '+item.state +' '+item.postalCode;
                  }
                  else
                  {
                    fullAddress = item.contact.firstName+' '+item.contact.middleInitial+' '+item.contact.lastName+' '
                    +item.contact.companyName+' '+item.streetLine1 +' '+item.city +', '+item.state +' '+item.postalCode;
                  }

    Сабж))

    rainerg, 23 Февраля 2015

    Комментарии (0)
  8. Си / Говнокод #17682

    +136

    1. 1
    2. 2
    for (j = 0; j < NUM_DMA_BUFFERS; j++)
            *(int *)dev->channel[0].virtDma[j] = 0x1235+j;

    ЯННП

    codemonkey, 23 Февраля 2015

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

    +51

    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
    template<class T, size_t N>
    constexpr size_t sa(T (&)[N])
    {
    	return N;
    };
    
    static std::memory_order mmo[] = 
    {
        memory_order_relaxed,
        memory_order_consume,
        memory_order_acquire,
        memory_order_release,
        memory_order_acq_rel,
        memory_order_seq_cst
    };
    
    std::memory_order current_program_memory_order()
    {
    	return mmo[rand()%sa(mmo)];
    }
    
    void current_program_memory_barier()
    {
    	std::atomic_thread_fence(current_program_memory_order());
    }

    LispGovno, 23 Февраля 2015

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

    +102

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public class Permuter                                {
        private static void permute(int n, char[] a)     {
            if (n == 0)                                  {
                System.out.println(String.valueOf(a))    ;}
            else                                         {
                for (int i = 0; i <= n; i++)             {
                    permute(n-1, a)                      ;
                    swap(a, n % 2 == 0 ? i : 0, n)       ;}}}
        private static void swap(char[] a, int i, int j) {
            char saved = a[i]                            ;
            a[i] = a[j]                                  ;
            a[j] = saved                                 ;}}

    "I finally figured out how to get those pesky semicolons and curly braces out of my Java code"

    Xom94ok, 22 Февраля 2015

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