A Visual Studio Code extension to make your code spaghetti. 🍝
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 sorti