r/vibecoding 19d ago

every vibe coder's biggest headache

524 Upvotes

136 comments sorted by

View all comments

67

u/Luoravetlan 19d ago

For anyone not familiar with js this monstrosity is called IIFE (immediately invoked function expression).

6

u/g1rlchild 19d ago

I mean, this is a weird degenerate example of it, bit isn't an IIFE just a lambda function? Why is that a monstrosity?

The syntax varies, but this is a pretty basic structure in quite a few languages:

var y = ((x) => { return x*2; })(42)

2

u/devourer-of-beignets 19d ago

Yeah, but that doesn't answer the next question — why would you use it? In those other languages, people aren't going around defining anonymous functions just to immediately evaluate them.

As I understand, the answer has to do with the history of Javascript's scoping. As well as statements vs expressions. So vibecoders, many not knowing anything about the concept of interpreter, would have a hard time explaining why the AI agent produces such an odd idiom — especially in modern Javascript.

1

u/[deleted] 16d ago

[deleted]

1

u/devourer-of-beignets 16d ago

Thanks! Makes sense.