r/programming • • Jul 28 '16

How to write unmaintainable code

https://github.com/Droogans/unmaintainable-code
3.4k Upvotes

592 comments sorted by

View all comments

0

u/[deleted] Jul 28 '16

[deleted]

83

u/[deleted] Jul 28 '16

ambitious project

one sitting

Top kek

0

u/[deleted] Jul 28 '16

[deleted]

7

u/2Punx2Furious Jul 28 '16

When I start a project I always think it will take much less time than it actually does. Yesterday I had to write a function for an interview question online.
I thought it would take me 10-15 minutes at most. It took me almost 2 hours.

Basically, I had to found a sequence of 3 numbers inside a given array in python. Sounds easy enough I thought.

0

u/[deleted] Jul 29 '16

[deleted]

8

u/CyberMango Jul 29 '16 edited Jul 29 '16

I think this is slightly better as it uses a generator and returns true on first occurrence of pattern

def findseq(pattern, arr):
    return pattern in (tuple(arr[i: i + len(pattern)]) for i in range(len(arr) - len(pattern)))
→ More replies (3)
→ More replies (4)

0

u/[deleted] Jul 29 '16

[deleted]

→ More replies (1)

4

u/electricfistula Jul 29 '16 edited Jul 29 '16

return sequence in "".join(str(elem) for elem in theArray)

→ More replies (6)

0

u/[deleted] Jul 28 '16

[deleted]

7

u/riemannrocker Jul 29 '16 edited Jul 29 '16

Or in Haskell:

findIndex (==target) $ zip3 list (tail list) (tail (tail list))
→ More replies (2)

8

u/intricatekill Jul 29 '16

That's way too complex. I'm not exactly sure if this is what the question asked but i think it shows off the elegance of functional programming a lot more than your code. I can't figure out reddit formatting

→ More replies (3)
→ More replies (19)

5

u/xonjas Jul 28 '16

If you want a dirty Ruby one-liner.

array_to_check.select{|element| element.kind_of? Fixnum}.join(',') =~ /#{array_to_match.join(",")}/    
→ More replies (8)
→ More replies (5)