4
\$\begingroup\$

Figure out how to mess up another programmer's project by making a subtle, hard to find (but "harmless") "bug". (Double quotes FTW!)

Try to keep them short; shorter ~= subtle.


For example:

#define true false

Don't actually destroy the code directly. For example, from this:

for(size_t i = 0; i < 10; ++i)

To:

for(size_t *i = new size_t; ++i; delete i)

Or even:

for(size_t i = 0; i <= 10; ++i)

Is not OK. If a language actually allows you to change < to <= without changing that code "directly", then it's alright. (You know what I mean. Deleting all the code is just


Voting

Up vote the most original/creative/subtle solutions.

On Mother's Day (May 8, 2011), the most up voted answer will be chosen as the winner.

\$\endgroup\$
7
  • 2
    \$\begingroup\$ They did this on TheDailyWTF about a month and a half ago. \$\endgroup\$
    – Joey Adams
    Apr 30, 2011 at 4:10
  • 2
    \$\begingroup\$ My favourite was setting String.Empty to another value :) \$\endgroup\$
    – Ry-
    Apr 30, 2011 at 4:15
  • 6
    \$\begingroup\$ Subjective? meta.codegolf.stackexchange.com/questions/305/… \$\endgroup\$ Apr 30, 2011 at 4:18
  • 3
    \$\begingroup\$ I don’t understand why “number of votes” is considered a subjective criterion. One would have thought that most people can read the vote-counts and determine, objectively, which is highest? \$\endgroup\$
    – Timwi
    May 2, 2011 at 13:48
  • 4
    \$\begingroup\$ Deleting all the code is just?? I don't think so :) \$\endgroup\$
    – mellamokb
    May 2, 2011 at 18:29

4 Answers 4

12
\$\begingroup\$
#define if(x) if(random(100) > 0 && (x))
\$\endgroup\$
2
  • 1
    \$\begingroup\$ For C, I think you'd need to say random() % 100. \$\endgroup\$
    – Joey Adams
    May 1, 2011 at 2:38
  • \$\begingroup\$ No... not with stdlib.h. \$\endgroup\$
    – Ry-
    May 1, 2011 at 2:40
7
\$\begingroup\$

Haskell

module UnsafePrelude where

import Prelude hiding ((.), (+), (-), sum, map, foldl)
import qualified Prelude as P

import Unsafe.Coerce

-- disallow (f . g . h)
infix 9 .
(.) = (P..)

-- Make arithmetic a bit more exciting.
-- These actually work correctly for trivial Int and Integer cases,
-- at least in GHC 6.12.1 on x86.
(+), (-) :: (Num a) => a -> a -> a
(+) = unsafeCoerce ((P.+) :: Float -> Float -> Float)
(-) = unsafeCoerce ((P.-) :: Float -> Float -> Float)

sum :: (Num a, Num b) => [a] -> b
sum = unsafeCoerce (P.sum :: [Float] -> Float)

-- Make map a little less type-safe.
map :: (a -> b) -> [c] -> [b]
map   = unsafeCoerce P.map

-- Make foldl associate the wrong way, but still have the same type.
foldl :: (a -> b -> a) -> a -> [b] -> a
foldl f = foldr (flip f)
\$\endgroup\$
6
\$\begingroup\$

GolfScript

1: 

Note there is a space after the colon. This assigns the value 1 to the space character. All further code that uses the space for readability will find unexpected extra ones on its stack!

Alternatively,

0:1

assigns the value 0 to the character 1.

\$\endgroup\$
1
  • 6
    \$\begingroup\$ Of course, I'm not quite sure why you'd be coding in GolfScript for any 'project' other than golf... :) \$\endgroup\$ May 1, 2011 at 20:54
3
\$\begingroup\$

Ruby

class Fixnum
    alias add +
    def + (n)
        add n.add 1
    end
end

And now, like in 1984...

(33):0>  2 + 2 == 5
>>> true
(36):0>  
\$\endgroup\$
2
  • \$\begingroup\$ I prefer this: class Fixnum; alias - +; end \$\endgroup\$
    – Matma Rex
    May 3, 2011 at 16:15
  • 2
    \$\begingroup\$ @Matma Rex: That's a bit easier to notice... \$\endgroup\$
    – Lowjacker
    May 3, 2011 at 21:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.