Why Lua 🥺

preview_player
Показать описание
1 + "1" = ERROR
1 + "1" = 2?
Рекомендации по теме
Комментарии
Автор

who the fuck invited javascript devs to lua 💀🙏

timelessnesses
Автор

I like Java's way of handling things: if there is a string on the middle, then everything is a String.

Ulissescars
Автор

This sounds scary, but starts making a lot more sense when you consider that "+" is ALWAYS supposed to be addition in Lua. For string concatenation, ".." is used.

G-u-z-i-o
Автор

So Lua doesn't stop you from shooting your leg. Very nice

tldr_rm_-rf
Автор

I love it when scripting languages decide to make things "convenient" for new programmers who have never read a line of code in their life at the expense of everyone else.

NanerBag
Автор

"static types are better"
"no! dynamic types are better!"
can't a man just get type inference with reasonable implicit casts?

badradish
Автор

Lua it just 150KB compiler while Python over a hundred megabytes does.

yerenzter
Автор

I think this is actually part of the standard string library, it creates an __add metamethod for strings that converts them to numbers. Without it i believe this would just give "Attempted to perform arithmetic on a string value."

somenameidk
Автор

why people are dumb?
lua gave you “..” operator for concat and “+” for math 😒

qing-hhsu
Автор

The problem is that + is an arithmetic operation in lua, so lua will always try to do type coercion and you can even overload the operator to behave differently. For concatenation in Lua you always use *..* as it is the only method of joining two strings and with numbers it would cause an error.

hadawardgz
Автор

Lua was almost big in the game industry but it died because of the 1-indexing which made subtle off-by-1 incompatibility with all existing libraries, and made it impractical to directly bind libraries because they would have inconsistent indexing with Lua. The 1-indexing kind of destroyed the entire Lua project.

zyxyuv
Автор

This type conversion is useful in some cases. But if you just wanna concatenate strings, doing ("1"+"1") wont actually work. This is why ".." exists.

Nox-Music
Автор

tbh I expected it to be "11" like javascript

TheCubicLog
Автор

I started programming with C++, which, for most people, is a difficult language. I started programming in Python recently and it actually makes no sense lol. Its confusing how easy something can be

Michael-pplz
Автор

What about C?
printf("%c", 1 + '1') prints 2

CrazyStranger
Автор

To be entirely fair, string concatenation in lua isn’t done with the + operator, it has a special .. operator
Still hate that it tries to automatically cast a string to a number that’s horrible

melody_florum
Автор

when you play with the metatable too much

cattokomo
Автор

it's type coercion, it happen too in javascript 😂

type coercion is the automatic or implicit conversion of values from one data type to another (such as strings to numbers). type conversion is similar to type coercion because they both convert values from one data type to another with one key difference — type coercion is implicit whereas type conversion can be either implicit or explicit.

junetxpid
Автор

Shit man, i don't know how i got here or why i stayed but damn my brain just farted

potatony
Автор

lets be real, programming languages are cringe. i think we should send electrical impulses directly to the CPU to write binary code.

gordonramsay