Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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.

share|improve this question
2  
They did this on TheDailyWTF about a month and a half ago. – Joey Adams Apr 30 '11 at 4:10
2  
My favourite was setting String.Empty to another value :) – rynah Apr 30 '11 at 4:15
6  
3  
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? – Timwi May 2 '11 at 13:48
3  
Deleting all the code is just?? I don't think so :) – mellamokb May 2 '11 at 18:29
show 2 more comments

closed as not constructive by PleaseStand, Joey, MtnViewMark, st0le, dmckee May 4 '11 at 17:19

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

4 Answers

up vote 10 down vote accepted
#define if(x) if(random(100) > 0 && (x))
share|improve this answer
1  
For C, I think you'd need to say random() % 100. – Joey Adams May 1 '11 at 2:38
No... not with stdlib.h. – rynah May 1 '11 at 2:40

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)
share|improve this answer

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.

share|improve this answer
5  
Of course, I'm not quite sure why you'd be coding in GolfScript for any 'project' other than golf... :) – muntoo May 1 '11 at 20:54

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>  
share|improve this answer
I prefer this: class Fixnum; alias - +; end – Matma Rex May 3 '11 at 16:15
1  
@Matma Rex: That's a bit easier to notice... – Lowjacker May 3 '11 at 21:00
I'm reading 1984 at the moment. :) – muntoo May 5 '11 at 4:19

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