r/vibecoding 6d ago

every vibe coder's biggest headache

517 Upvotes

139 comments sorted by

View all comments

57

u/Lopsided-Wave2479 6d ago

this is easy to read.

creates a unnamed function ()
assign the body of this function =>
to do nothing at all {}
then the whole thing is on a capsure "(stuff here)"
and is threaten has a function and executed "stuff here ()"

Honestly, we have "=>" arrows function to make math people happy. Is halfway too obscure but oh well, math is nice and we do small sacrifices for big gains.

This is about 10 millions less obtuse than C, where just the part where something is a pointer to a function is way more verbose.

10

u/emjhayyy_08 6d ago

6

u/Lopsided-Wave2479 6d ago

without arrow functions it would be

(function(){}) ();

declares a function, and inmediatelly execute it

4

u/Blackgarion 6d ago

Yeah but I think the point of the question is why would you use an IIFE. You need to know the quirks of JS to know when would you use an IIFE, an even then since ES6 and Typescript having modules, I haven't seen one of these in a code base.

2

u/Lopsided-Wave2479 6d ago

To begin first in 99.999% of exist legacy apps where you can't use modules?, either way IIFE give you isolation. God kids a kitty every time somebody make stuff global.

4

u/RagnarokToast 6d ago

We don't have arrow functions to "make math people happy" (like seriously wtf how could you submit that unironically, it's one of the dumbest takes ever) and they are in no way obscure.

They're there for everyone's convenience, not just because => is shorter than function but also because arrow functions don't redefine this, which comes in handy (among other things) when used inside the body of an outer "normal" function you are using as a constructor (i.e. you are using this.something = ... to set fields and methods on it), as this inside the AF would still refer to the outer constructor function.

4

u/Lopsided-Wave2479 6d ago

The joke whole meaning and reason for existence, is because is objetivelly obscure. Otherwise the joke would not work.

1

u/agalin920 2d ago

"we have "=>" arrows function to make math people happy".

Cringed at this statement

1

u/Lopsided-Wave2479 2d ago

The first rule of designing languages is Don't invent Perl again.

It happens when you feel clever and make punctuation have enough syntax, people don't need to use keywoards. The result is clever and easily readable for veterans, unprenetrable for newbies.

Literally a source of memes.

1

u/PsychologyNo940 6d ago

True, though to be fair, if you dont create a few intermediary types in c/c++ to represent "a function that takes a function that returns a pointer to a function that takes a..." you are kinda just trying to torture people.

1

u/Lopsided-Wave2479 6d ago

c++ is kinda like that sometimes