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

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

    +124

    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
    bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size )
    {
    	const char *val;
    	
        int size = 0;
    	int sum = 0;
        
    	bool negative = false;
    	bool percentage = false;
    	
        if (getValueForKey(key, &val, &size, config))
    	{
    		if ( size )
    		{
    			if (*val == '-')
    			{
    				negative = true;
    				val++;
    				size--;
    			}
    			
    			if (val[size-1] == '%')
    			{
    				percentage = true;
    				size--;
    			}
    			
    			// convert string to integer
    			for (sum = 0; size > 0; size--)
    			{
    				if (*val < '0' || *val > '9')
    					return false;
    				
    				sum = (sum * 10) + (*val++ - '0');
    			}
    			
    			if (percentage)
    				sum = ( dimension_max * sum ) / 100;
    			
    			// calculate offset from opposite origin
    			if (negative)
    				sum =  ( ( dimension_max - object_size ) - sum );
    			
    		} else {
    			
    			// null value calculate center
    			sum = ( dimension_max - object_size ) / 2;
    			
    		}
    		
    		*value = (uint16_t) sum;
    		return true;
    	}
    	
    	// key not found
        return false;
    }

    Cтригозаврус функодавус ...

    Stealth, 09 Августа 2013

    Комментарии (32)
  3. Куча / Говнокод #13477

    +124

    1. 1
    "(\{\{([#%$])([^:\}]+)(:([^\}]+))?\}\})"

    Регуляркоговно.
    Заменено на

    "(\{\{([#%$])(.+?)(:(.+))?\}\})"

    vistefan, 25 Июля 2013

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

    +161

    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
    </if>
    															</if>
    														</ul>
    													</if>
    												</td>
    												</if>
    											</tr>
    										</if>
    									</foreach>
    								</table>
    							</div>
    						</div>
    						<br />
    					</div>
    				</if>
    			</foreach>
    		</if>
    	</div>

    facepalm

    CheshirskyCode, 08 Июля 2013

    Комментарии (32)
  5. PHP / Говнокод #13264

    +149

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <?php
    while($menu = mysql_fetch_assoc($q))
    {
    	?>
    	<option value="<?=$menu['id']?>"<?=($id === $menu['id']) ? ' selected="selected"' : ''?>><?=$menu['title']?></option>
    	<?php
    }
    ?>

    Адовейший пиздец наговнокодил сегодня. Ну не люблю я HTML-теги в PHP писать, о шаблонизаторах никогда не слышал

    3Jlou_OguHo4ka, 30 Июня 2013

    Комментарии (32)
  6. Pascal / Говнокод #13260

    +129

    1. 1
    Что за питух мои г-коды удаляет?

    Stertor, 29 Июня 2013

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

    +8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int wordLen(const char* word) 
    { 
        int i=-1; 
        while(word[++i]!='\0'&&word[i]!='\n'); 
        return i; 
    }

    Типичная лаба, но как же смешно это увидеть спустя некоторое время

    iofjuupasli, 29 Июня 2013

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

    +164

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $res = mysql_query('select `date` from `pic`');
    
    while($data = mysql_fetch_row($res)){
           if(date('d.m.y') != date('d.m.y',$data[0])) continue;
           $countPicToday++;
    }

    Не понятно. Почему нельзя было использовать COUNT() и WHERE

    AlexP, 20 Июня 2013

    Комментарии (32)
  9. Perl / Говнокод #12980

    −103

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    sub exdef {
        my ($hash, $key) = @_;
    
        if (exists $hash->{$key} && defined $hash->{$key}) {
            return 1;
        }
    
        return 0;
    }

    No comments.

    BTW.
    http://perldoc.perl.org/functions/exists.html
    http://perldoc.perl.org/functions/defined.html

    Elvenfighter, 08 Мая 2013

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

    −107

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    - (void)cellButtonTapped:(UIButton *)sender
    {
        UITableViewCell* cell = (id) sender.superview.superview.superview;
        ...
    }

    Жечь в печах таких людей

    notxcain, 01 Апреля 2013

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

    +8

    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
    #include <iostream>
     
    struct Reader_msg;
    template<class T>struct TMsg;
     
    struct IMsg
    {
        virtual ~IMsg(){}
        virtual void SendCast(Reader_msg& obj) = 0;
    };
     
    struct Some{}; 
     
    struct Reader_msg
    {
        template<class T> void ReadMsg(T& msg)
        {
            //Здесь можно приляпать статик_ассерт
            std::cout<<"ERROR UNKNOW TYPE \n";
        }
        void ReadMsg(int msg)   { (void)msg; std::cout<<"TYPE IS INT\n";   }
        void ReadMsg(float msg) { (void)msg; std::cout<<"TYPE IS FLOAT\n"; }
        void ReadMsg(Some msg)  { (void)msg; std::cout<<"TYPE IS SOME\n";  }
     
        template<class T>void TakeMsg(T& msg) { msg.SendCast(*this); }
    };
     
    template<class T>struct TMsg:IMsg
    {
        T data;
        void SendCast(Reader_msg& obj){ obj.ReadMsg(data); }
    };
     
     
    int main()
    {
        Reader_msg reader;
        TMsg<int>    msg1;
        TMsg<float>  msg2;
        IMsg& msg3 = msg1;
        IMsg& msg4 = msg2;
        TMsg<Some>   msg5;
        TMsg<double> msg6;
        
     
        reader.TakeMsg(msg1);
        reader.TakeMsg(msg2);
        reader.TakeMsg(msg3);
        reader.TakeMsg(msg4);
        reader.TakeMsg(msg5);
        reader.TakeMsg(msg6);
    }

    http://liveworkspace.org/code/4FHDTq$6

    LispGovno, 18 Января 2013

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