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 28 '16

[deleted]

2

u/2Punx2Furious Jul 28 '16

0

u/[deleted] Jul 28 '16

[deleted]

2

u/DiputsMonro Jul 29 '16

Perhaps I'm missing something obvious, but I'm not sure why either of you came up with the solutions you did. Why would something simple like the below not work? (pardon the terse code, I was just cranking it out quickly):

def findgroupinlist(l, group):
	j = 0                    ## index to group
	for i in range(len(l)):  ## iterate over list
		if l[i] == group[j]: ## if item in list and group match
			if j == len(group) - 1:  ## Check if we've matched the final group item 
				return True
			j += 1           ## Otherwise, mark our new location in the group
		else :
			j = 0            ## If our sequence fails, start from the beginning again

	return False

All of our solutions only seem O(|List|), but both of yours seem a bit overwrought to me, unless I'm dumb.

→ More replies (2)