My code is too 

Meet Spaghettify

A Visual Studio Code extension to make your code spaghetti. 🍝

SHARE
DOWNLOAD

Coding is not a very delicious activity. You sit in front of a screen, type some stuff, and then you have some stuff on a screen. What if we could make it more delicious, like shoveling down a massive plate of spaghetti?

Meet Spaghettify, a Visual Studio Code extension that turns your not-so-tasty code into spaghetti. Mama Mia! 🤌

What can Spaghettify do?

Spaghettify comes with several ways to make your code a lot more flavorful. (and...maybe a bit less healthy)

Spaghetti Time

Here's some Python code which finds neighbors in a 2D array. Let's spaghettify it.

1 2 3 4 5 6 7 8 9 10 11 def neighbors(arr, x, y, n): result = [] row_start = max(0, x-n) row_end = min(len(arr)-1, x+n) col_start = max(0, y-n) col_end = min(len(arr[0])-1, y+n) for i in range(row_start, row_end+1): for j in range(col_start, col_end+1): result.append((i, j)) return result

Introduce a Bug

Throw in a subtle change that will break the code, leaving your coworkers scratching their heads for hours. Add a stray +1, extra iteration, or nested list with ease! Can you spot the bug? 🐛

1 2 3 4 5 6 7 8 9 10 11 def neighbors(arr, x, y, n): result = [] row_start = max(0, x-n) row_end = min(len(arr)-1, x+n) col_start = max(0, y-n) col_end = min(len(arr[0])-1, y+n-1) for i in range(row_start, row_end+1): for j in range(col_start, col_end): result.append((i, j)) return result

Obscure Code

Was the code too readable? Too elegant? Could your coworkers understand what it did with a passing glance? Well not anymore!

1 2 def neighbors(arr,x,y,n): r=[] ; rS=max(0,x-n); rE=min(len(arr)-1,x+n); cS=max(0,y-n); cE=min(len(arr[0])-1,y+n); [r.append((i,j)) for i in range(rS,rE+1) for j in range(cS,cE+1)]; return r

Add Irrelevant Comments

Do you ever look at code and think, "This sorting function sure could use an existential questioning about why it's there". Now it's easy!

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # Definition of neighbor-finding function # 🤔 what a weird thing. Wonder why they need this. def neighbors(arr, x, y, n): # 👋 Hello! result = [] # initialized result row_start = max(0, x-n) # setting row start row_end = min(len(arr)-1, x+n) # setting row end col_start = max(0, y-n) # setting col start col_end = min(len(arr[0])-1, y+n) # setting col end # Now iterating to find matches 🤔?? for i in range(row_start, row_end+1): # Duh!! 😒 for j in range(col_start, col_end+1): # Still going result.append((i, j)) # Coo doodly doo! :) return result # Returning the result # 🤷‍♂️ So much logic 😱

Document with Emoji

While we're ✍️ writing comments, how 👏 about documenting the 👏 code 😤 entirely with 🐺 emoji? 🎭🙋

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 """ 🌐🕵️‍♂️🔍👀📍👨‍👩‍👧‍👦 """ def neighbors(arr, x, y, n): """ 📊🎯🎖️ """ result = [] # 🔍 row_start = max(0, x-n) row_end = min(len(arr)-1, x+n) col_start = max(0, y-n) # 💯 col_end = min(len(arr[0])-1, y+n) for i in range(row_start, row_end+1): # 🔃 for j in range(col_start, col_end+1): result.append((i, j)) # 🤝 return result # 🛩️

Overly Descriptive Names

Make your code just a little bit more explicit about what it does. (We see you, Objective-C developers.)

1 2 3 4 5 6 7 8 9 10 11 12 def neighboring_locationFinder_routine(matrix_of_cells, x_index_coordinate, y_index_coordinate, adjacency_boundaries_bracket): list_of_neighbor_locs = [] vertical_axis_start_index = max(0, x_index_coordinate-adjacency_boundaries_bracket) vertical_axis_end_index = min(len(matrix_of_cells)-1, x_index_coordinate+adjacency_boundaries_bracket) horizontal_axis_start_index = max(0, y_index_coordinate-adjacency_boundaries_bracket) horizontal_axis_end_index = min(len(matrix_of_cells[0])-1, y_index_coordinate+adjacency_boundaries_bracket) for horizontal_index in range(vertical_axis_start_index, vertical_axis_end_index+1): for vertical_index in range(horizontal_axis_start_index, horizontal_axis_end_index+1): list_of_neighbor_locs.append((horizontal_index, vertical_index)) return list_of_neighbor_locs

Random Whitespace

Win the space race by adding random, inconsistent spaces all throughout your formerly symmertrical code.

1 2 def neighbors (arr ,x, y , n): result =[]; row_start= max ( 0 , x-n ); row_end =min(len(arr)-1 , x + n );col_start = max (0, y - n); col_end =min ( len (arr[ 0 ]) -1 , y +n ); for i in range ( row_start , row_end +1 ): for j in range ( col_start , col_end + 1):result.append( (i , j ) ) ;return result ;

Fancy Docstring

Document your code automatically using any character or style. Rap lyrics? Dirty limerick? Fast talkin' 1930's gangster? A pirate on acid? Whatever you need, Spaghettify heeds.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 """ Returns a list full of points From given matrix, they anoints Up to n away Each row and column they sway 'Til each neighbor is accounted for joint """ def neighbors(arr, x, y, n): result = [] row_start = max(0, x-n) row_end = min(len(arr)-1, x+n) col_start = max(0, y-n) col_end = min(len(arr[0])-1, y+n) for i in range(row_start, row_end+1): for j in range(col_start, col_end+1): result.append((i, j)) return result

Drop #2, by BCAD

;