1. JavaScript / Говнокод #8619

    +146

    1. 1
    2. 2
    3. 3
    <a href="javascript:void(0);" onclick="suspend(8)">
    	<input type="checkbox" value="Suspend Listing" name="" id="id8">
    </a>

    ревьювил код нового джуниора, который пришёл к нам из достаточно крупной компании. Строилось через JS поэтому и запостил в JS

    mgauk, 23 Ноября 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Thread thread1 = new Thread();
    Thread thread1 = new Thread();
    thread1.start();
    thread2.start();
    while(thread1.isAlive() || thread2.isAlive()){}

    askell, 23 Ноября 2011

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if c = 'y' then 
    begin 
      Writeln('Yes'); 
    end else 
    if c = 'n' then 
    begin 
      Writeln('No'); 
    end;

    Вот это кака... http://delphisources.ru/forum/showthread.php?t=19000

    Nikitiy_II, 23 Ноября 2011

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

    +82

    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
    private static void createFile(File f) {
    	try {
    		f.createNewFile();
    		FileOutputStream fs = new FileOutputStream(f);
    		Long time = new Date().getTime();
    
    		int b = 0;
    
    		b = (int) (time % 256);
    		fs.write(b);
    		time /= 256;
    
    		b = (int) (time % 256);
    		fs.write(b);
    		time /= 256;
    
    		b = (int) (time % 256);
    		fs.write(b);
    		time /= 256;
    
    		b = (int) (time % 256);
    		fs.write(b);
    		time /= 256;
    
    		b = (int) (time % 256);
    		fs.write(b);
    		time /= 256;
    
    		b = (int) (time % 256);
    		fs.write(b);
    		time /= 256;
    
    		b = (int) (time % 256);
    		fs.write(b);
    		time /= 256;
    
    		b = (int) (time % 256);
    		fs.write(b);
    		time /= 256;
    
    		fs.flush();
    		fs.close();
    	} catch (IOException e) {
    		e.printStackTrace();
    	}
    }

    Сохранение даты в файл :)

    mastermind, 23 Ноября 2011

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

    +122

    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
    @SuppressWarnings("unused")
    // Sure it's used. By Guice. So stop complaining.
    protected ColQueryProvider() {
    	try {
    		// Exhibit one: ye olde dependency hell.
    		// We *should* be able to just use new EclipseCompiler(), but GWT complains
    		// in dev mode when ECJ is in the Eclipse classpath. So it's not.
    		// ECJ is still loaded by the servlet container, so this is not an issue in deployment.
    		final JavaCompiler compiler = (JavaCompiler)
    				Class.forName("org.eclipse.jdt.internal.compiler.tool.EclipseCompiler").newInstance();
    		
    		// Tweaked based on QueryEngine.DEFAULT
    		final DefaultEvaluatorFactory evaluatorFactory = new DefaultEvaluatorFactory(ColQueryTemplates.DEFAULT,
    				(URLClassLoader) DefaultEvaluatorFactory.class.getClassLoader(), compiler);
    		
    		queryEngine = new DefaultQueryEngine(evaluatorFactory);
    	} catch (final ClassNotFoundException e) {
    		throw new ProvisionException("Eclipse compiler cannot be loaded", e);
    	} catch (final InstantiationException e) {
    		throw new ProvisionException("Eclipse compiler cannot be loaded", e);
    	} catch (final IllegalAccessException e) {
    		throw new ProvisionException("Eclipse compiler cannot be loaded", e);
    	}
    }

    someone, 23 Ноября 2011

    Комментарии (0)
  6. JavaScript / Говнокод #8614

    +145

    1. 1
    <img title="говнокод, смешной код, быдлокод, быдлокодеры, индусы, для программистов, про программистов, индусский код, записки программиста, говно, говнокод на php, mysql, perl" class="highslide" onclick="try{hs.expand(this,{src:'/c/128681/d/img_3302_1.jpg'});}catch(e){}" alt="говнокод, смешной код, быдлокод, быдлокодеры, индусы, для программистов, про программистов, индусский код, записки программиста, говно, говнокод на php, mysql, perl" src="/c/128681/d/363042302_1.jpg" width="173" height="269" border="0" />

    Камрад-фотограф так хорошо отзывался о вебдев-конторе "ГигаТруп", где он заказал сайт и SEO, что я решил посмотреть исходники страницы и поучиться их высокому мастерству.

    Код одной из сотни картинок с превьюшками (да, всё сделано в одну страницу!) вы видите выше. А SEO там типичное - грабим ключевые слова, по котором найден сайт, кладём их в h1, замазываем фоном-картинкой и попадаем в бан через несколько индексаций, когда деньги уже заплачены и на клиента насрать.

    Так работает русский ебизнес.

    actuator, 23 Ноября 2011

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

    +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
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    private static final char DELIM = '_';
    
    public String createDocName() {
        ...
        final String sDelim = Character.toString(DELIM);
        String res = stringWithDelimiter(docType) + stringWithDelimiter(docNumber) + stringWithDelimiter(docDate) + stringWithDelimiter(documentReceiptDate);
        res = res.length() < sDelim.length() ? "" : res.substring(0, res.length() - sDelim.length());
        res = res.replace(sDelim + sDelim + sDelim, sDelim);
        res = res.replace(sDelim + sDelim, sDelim);
    
        if (res.charAt(0) == DELIM)
          res = res.substring(1);
    
        if (res.charAt(res.length() - 1) == DELIM)
          res.substring(0, res.length() - sDelim.length());
        
        return res;
    }
    private String stringWithDelimiter(Object o) {
        final String sDelim = Character.toString(DELIM);
        String s = (String) o;
        return StringUtils.isNotEmpty(s) ? s + sDelim : sDelim;
    }

    метод createDocName должен из нескольких полей документа составить имя документа, используя в качестве разделителя "_".
    Сначала я не мог предположить что делает этот код, но подсказал коллега по работе:
    потензицально, вызов String res = stringWithDelimiter(docType) + stringWithDelimiter(docNumber) + stringWithDelimiter(docDate) + stringWithDelimiter(documentReceiptDate) ; может давать запись например такую: "docType___" - в случае если docNumber, docDate и documentReceiptDate будут пустыми строками (а можно получить и "___documentReceiptDate".
    НО, предусмотрительный разработчик позаботился об это проблеме!
    Он заменяет, "___" и "__" с помощью:
    res = res.replace(sDelim + sDelim + sDelim, sDelim);
    res = res.replace(sDelim + sDelim, sDelim);
    Затем удаляет знаки подчеркиваний в начале и в конце строки:
    if (res.charAt(0) == DELIM)
    res = res.substring(1);
    if (res.charAt(res.length() - 1) == DELIM)
    res.substring(0, res.length() - sDelim.length());

    Отличное решение, можно было бы конечно переписать метод stringWithDelimiter, чтобы он не дописывал "_" для пустых строк, но это ведь не так круто правда? Жаль только что придется этот класный код снова переписывать если вдруг измениться число параметров, или поменяется разделитель...

    LexeY4eg, 23 Ноября 2011

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (!field.parentElement.childNodes[0].checked)
    {
    getElementByFieldName("Original").parentNode.childNodes[0].disabled = true;
    getElementByFieldName("Duplicate").parentNode.childNodes[0].disabled = true;
    ...

    Далее идет ещё примерно 20 аналогичных обращений, аля parentNode.childNodes[0]
    Очень читабельный и понятный код! :)

    LexeY4eg, 23 Ноября 2011

    Комментарии (20)
  9. Python / Говнокод #8611

    −100

    1. 1
    2. 2
    3. 3
    4. 4
    class SomeThing(object)
        def _get_value(self):
            return #return some value
        get_value = property(_get_value)

    Декораторы? не не слышал.

    Zapix, 23 Ноября 2011

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Date date = (Date)value.getParam("DocReceiptDate");
        if (date.getHours() == 24) {
          date.setHours(0);
        }
        String documentReceiptDate = (new SimpleDateFormat("dd.MM.yyyy.kk.mm")).format(date);

    Элегантная попытка форматирования даты.
    Задача было вместо 24 часов писать 00, например не "24.11.2011.24.23", а "24.11.2011.00.23".
    Как все уже догадались, следовало просто использовать формат "dd.MM.yyyy.HH.mm".

    LexeY4eg, 23 Ноября 2011

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