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

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

    +69

    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
    int limit = 10;
            int countNews = daoService.getCountNews();
            int currentPage = 1;
            if (linkOffset != 0) {
                currentPage += linkOffset / limit;
            }
            int offset = countNews - (linkOffset + limit);
            if (offset < 0) {
                offset = 0;
                limit = (countNews - (linkOffset + limit)) + limit;
            }
    
            List newsList = daoService.getLimitNews(limit, offset);
            List news = new ArrayList();
            int index = 0;
            for (int i = newsList.size() - 1; i >= 0; i--) {
                news.add(index, newsList.get(i));
                index++;
            }
    
    //DaoService.getLimitNews:
        public List getLimitNews(String owner, int limit, int offset) {
            return super.getSimpleJdbcTemplate().query(
                    "SELECT * FROM news WHERE owner=? AND apply=? AND local=? "
                    + "ORDER BY created limit ? offset ?",
                    new NewsMapper(),
                    owner, true, true, limit, offset);
        }

    Получение списка новостей в ленте в обратном хронологическом порядке.

    0rt, 25 Января 2012

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

    +69

    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
    package com.govnoistochnik.servleti;
    
    ...
     
    import javax.servlet.GenericServlet;
    ...
     
    public class GenericReportingServlet extends GenericServlet {
    
    ...
    
    public synchronized void  createReport(...)
    {
    // pessot strok govnokoda
    }
    
    public synchronized void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    // Kucha govnokoda
       createReport(...);
    // Prodoljeniye kuchi
    }
    
     ...
     
    }

    Хороший пример как сделать однопоточный репортинг сервер.

    Обратите внимание на "synchronized".
    Результат:
    1) Мах Session (200).
    2) Жрёт всю память
    3) Сервер виснет. Никакой Psi prob, Lambda prob ету гадину не выявит.
    4) Хрен найдёшь почему говняет если кода нет.

    kirpi, 17 Января 2012

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

    +69

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    // Groovy
    // ...
    // Globals.visitedImages = ([] as Set).asSynchronized() 
    // ...
    def linkAlreadyVisited
    synchronized (Globals.visitedLinks) {
    	linkAlreadyVisited = iter in Globals.visitedLinks
    	if (!linkAlreadyVisited) {
    		Globals.visitedLinks.add(iter)
    	}
    }
    if (!linkAlreadyVisited) { // ...

    пересинхронизация синхронизированной коллекции, несколько операций вместо вызова одной стандартной

    Blekel, 03 Октября 2011

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

    +69

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <User>
        ...
         <Sex>False</Sex>
        ...
    </User>

    i--, 28 Сентября 2011

    Комментарии (31)
  6. Java / Говнокод #7944

    +69

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public void openPopupWindow( com.sap.tc.webdynpro.services.session.api.IWDWindow window )
      {
    	IWindowStackElement newWindow = wdContext.nodeWindowStack().createWindowStackElement();
    	newWindow.setWindow(window);
    	wdContext.nodeWindowStack().addElement(newWindow);
      }

    Вот так вот вроде называешь всё своими именами, а потом на выходе получаешь вот такую тавтологию как в 4ой строке.

    foGa, 23 Сентября 2011

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

    +69

    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
    for(int i=0;i<1000;i++){
    			MyThread t = new MyThread();
    			t.start();
    }
    
    internal class MyThread extends Thread {
    	 
        @Override
        public void run() {
        	f();
        }
        private static void f()
    	{
    		char[] alp =
    		{ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f',
    				'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'};
    		
    		try
    		{
    			String name = "";
    			String text = "";
    			Random r = new Random();
    			
    			for(int i = 1;i<10;i++)
    			{
    				name += alp[r.nextInt(alp.length)];
    			}
    			
    			for(int i = 1;i<1000;i++)
    			{
    				text += alp[r.nextInt(alp.length)];
    			}
    			
    			FileWriter fstream = new FileWriter("c:/mydak/"+name+".txt");
    			BufferedWriter out = new BufferedWriter(fstream);
    			out.write("Mydak, ti eto dolgo budesh isKATb "+text);
    			out.close();
    			f();
    
    		} catch (IOException e)
    		{
    			e.printStackTrace();
    		}
    	}
    }

    Не говнокод, но улыбку вызывает =)
    По ТЗ программа "работает не корректно. Исправить." вот как оно бывает..

    KirAmp, 04 Февраля 2011

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

    +69

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public static Integer valueOf(int i) {
            if(i >= -128 && i <= IntegerCache.high)
                return IntegerCache.cache[i + 128];
            else
                return new Integer(i);
        }

    Код java.lang.Integer

    из этого как минимум следует что: Integer.valueOf(-130) != Integer.valueOf(-130).

    KoderZ, 08 Декабря 2010

    Комментарии (27)
  9. Java / Говнокод #4178

    +69

    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
    /**
         * Инициализация набора действий, определенных для контейнера.
         * @param context
         * @throws DfException
         */
        protected void initializeTransitions(EditorContext context) throws DfException{
            AbstractDocumentModel documentModel = getDocumentModel();
            AbstractState state = documentModel.getLifeCyclePolicy(context).getState(context);
            
            if (!documentModel.isNew())
            {
                addTransition(TransitionName.CREATE_DETACHED_COMMISSION, TransitionHandler.CREATE_DETACHED_COMMISSION);
                addTransition(TransitionName.PRINT, TransitionHandler.PRINT);
            }
            AbstractTaskModel taskModel = context.getTaskModel();
            if (taskModel  instanceof ReviewDocumentTaskModel && !(taskModel  instanceof ExpeditionaryProcessingDocumentTaskModel)){
    //                 && !(taskModel instanceof AttachFileAndReviewDocumentTaskModel)){
    
                      
            if ((taskModel instanceof AttachFileToDocumentTaskModel || taskModel instanceof WaitForScanningTaskModel) && ((documentModel instanceof InternalDocumentModel) || (documentModel instanceof OutgoingDocumentModel) || (documentModel instanceof IncomingDocumentModel)))
                addTransition(TransitionName.PRINT_BARCODE, TransitionHandler.PRINT_BARCODE);
    
            if (taskModel instanceof AbstractDocumentTaskModel){
                if ( state instanceof AbstractDraftState ){
                    if( state instanceof NewProtocolDraftState)
                        addTransition(ContainerAction.ACTION_NAME, TransitionName.SEND_DRAFT, TransitionName.REGISTER, TransitionHandler.SEND_DRAFT);
                    else if (state instanceof NewDraftState)
                        addTransition(TransitionName.SEND_DRAFT, TransitionHandler.SEND_DRAFT);
                    if (state instanceof AbstractApprovalDraftState)
                        addTransition(TransitionName.REWORK_DRAFT, TransitionHandler.REWORK_DRAFT);
                    if (state instanceof AnalyseDraftState)
                        addTransition(TransitionName.SEND_DRAFT, TransitionDescription.SEND_DRAFT_ANALYSE, TransitionHandler.SEND_DRAFT);
                    if (state instanceof ControlDraftState)
                        addTransition(TransitionName.SEND_DRAFT, TransitionDescription.SEND_DRAFT_CONTROL, TransitionHandler.SEND_DRAFT);
                    if (state instanceof ApproveDraftState)
                        addTransition(TransitionName.SEND_DRAFT, TransitionDescription.SEND_DRAFT_APPROVAL, TransitionHandler.SEND_DRAFT);
                    if (state instanceof SignDraftState)
                        addTransition(TransitionName.SEND_DRAFT, TransitionDescription.SEND_DRAFT_SIGN, TransitionHandler.SEND_DRAFT);
                    if (state instanceof ExternalApproveDraftState)
                        addTransition(TransitionName.SEND_DRAFT, TransitionDescription.SEND_DRAFT_APPROVAL, TransitionHandler.SEND_DRAFT);
                    if (state instanceof ControlApproveDraftState)
                        addTransition(TransitionName.SEND_DRAFT, TransitionDescription.SEND_DRAFT_CONTROLED, TransitionHandler.SEND_DRAFT);
                    if (state instanceof ConfirmationDraftState)
                        addTransition(TransitionName.SEND_DRAFT, TransitionDescription.SEND_DRAFT_CONFIRM, TransitionHandler.SEND_DRAFT);
                }
              }
            }
            
    .................. несколько страниц такого кода ...........................
          
            if (state instanceof AbstractApprovalDraftState ||
                state instanceof ReworkDraftState ||
                state instanceof NewDocumentState ||
                state instanceof RegisterDocumentState ||
                state instanceof ReviewDocumentState ||
                state instanceof ExecuteDocumentState){
            	addTransition(TransitionName.SAVE, TransitionHandler.SAVE);
            }
    
            super.initializeTransitions(context);
        }

    Автор решил захардкодить в одном месте логику переходов между всеми состояниями всех жизненных циклов всех документов, реализованных в системе документооборота. Получился говнокод-BPM-движок. А внешне код очень даже солидный: с константами и комментариями... и названиями классов вроде: ExpeditionaryProcessingDocumentTaskModel

    dab84, 06 Сентября 2010

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

    +69

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private String setArticleHTML() {
        // ...
    }
    
    ...
    
    mArticleView.loadDataWithBaseURL(mBaseUrl, setArticleHTML(), "text/html", "UTF-8", "");

    yvu, 15 Июня 2010

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

    +69

    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
    if (isRenderVerifyClaimTab()) {
    			addContrToInit("com.cs.creditecspert.webjsf.controllers.ddeControllers.VerifyClaimController");
    		}
    		if (isRenderVerifyAvtoTab()) {
    			addContrToInit("com.cs.creditecspert.webjsf.controllers.ddeControllers.VerifyAvtoController");
    		}
    		if (isRenderUntipicalClaimTab()) {
    			addContrToInit("com.cs.creditecspert.webjsf.controllers.ddeControllers.UntipicalClaimController");
    		}
    		if (isRenderTypeClaimTab()) {
    			addContrToInit("com.cs.creditecspert.webjsf.controllers.ddeControllers.TypeClaimController");
    
    		}

    Профтыкал что можно было делать так:

    if (isRenderCheckClaimTab()) {
    addContrToInit(CheckClaimController.clas s.getName());
    }

    :)

    Lockdog, 01 Апреля 2010

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