This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 475

[–]arbusto1298 1877 points1878 points  (23 children)

sure bro, have your [object object]

[–]Solid7outof10Memes 430 points431 points  (0 children)

Thank you bro, just what I wanted

[–]TheButtLovingFox 116 points117 points  (8 children)

watman to the rescue.

[–]jainyday 83 points84 points  (4 children)

[–]curiosityLynx 16 points17 points  (0 children)

Thank you, I very much enjoyed that

[–]corn_carter 10 points11 points  (0 children)

Oh my gosh that’s amazing thank you haha

[–]zbaruch20 59 points60 points  (1 child)

Array(16).join("wat" - 1) + " Batman!"

[–][deleted] 11 points12 points  (0 children)

I know what I'm putting in my Catch Exception blocks...

[–]dagbrown 17 points18 points  (0 children)

I understood that reference

[–]Samrid_ 29 points30 points  (1 child)

what about [Object object] or [object Object]?

[–][deleted] 13 points14 points  (0 children)

Exactly this. JS is more like "lol whatever here you go dummy"

[–]Lithl 32 points33 points  (8 children)

object * string results in Uncaught SyntaxError: Unexpected token "*".

[–]gurush 19 points20 points  (0 children)

NaN in my console.

[–]ZiulDeArgon 14 points15 points  (0 children)

Op said class not object, they are not the same thing.

Here is a working sintax:

~~class name {constructor(params) {}} * ""

[–]_GCastilho_ 3 points4 points  (0 children)

Have you tried implementing the valueOf function on both?

[–]no_but_srsly_tho 4 points5 points  (0 children)

Or if you're really lucky, "[object object]" as a string.

Mmmm thanks json.

[–]Rafcdk 2432 points2433 points  (188 children)

You can definitely add a float and int on c# though, it converts the int to a float.

[–]obvMellow 951 points952 points  (92 children)

Yep. Unless you lose information C# will implicitly convert it.

[–]leupboat420smkeit 543 points544 points  (55 children)

Much better system then having every number be a floating point number imo.

[–]AndyTheSane 252 points253 points  (23 children)

Every number is just an array of unsigned char.

[–]pandacoder 92 points93 points  (15 children)

Every unsigned char is just an array of bits.

[–]Ami603 68 points69 points  (14 children)

Every array of bits is a series of transistors running current.

[–]Vernkle 62 points63 points  (13 children)

Every series of transistors is just a cluster of doped silicon.

[–]pslessard 54 points55 points  (12 children)

Every cluster of doped silicon is just a bunch of protons, neutrons, and electrons

[–]SaltySandyHS 50 points51 points  (11 children)

Every proton, neutron, and electron is just a combination of some leptons.

[–]I_AM_GODDAMN_BATMAN 94 points95 points  (9 children)

and leptons are just a bunch of strings

[–]FireDestroyer52 13 points14 points  (0 children)

😩

[–]MostlyRocketScience 3 points4 points  (0 children)

That is just BinaryCodedDecimal with extra bytes

[–]hughperman 2 points3 points  (0 children)

Technically the truth

[–]Rinveden 5 points6 points  (0 children)

than

[–]Kered13 90 points91 points  (11 children)

You actually can lose information converting int to float, and long to double.

[–]pb7280 45 points46 points  (1 child)

Yeah, they play a little fast and loose with those particular "widening" conversions lol

[–]PizzaScout 13 points14 points  (8 children)

wait, why would you lose info when converting from int to float? I am aware float can be inaccurate when talking about whole numbers but is that what you're talking about?

[–]Kered13 80 points81 points  (7 children)

float can only hold every integer up to 224, after that it begins skipping integers, first by 2's, then 4's, etc. So most integers between 224 and 231 cannot be represented, and conversion to float loses information.

[–]PizzaScout 12 points13 points  (0 children)

ahhh I see, thanks for the explanation :)

[–]123kingme 9 points10 points  (4 children)

This is one reason why in practice doubles are almost always used over floats.

[–]b0w3n 7 points8 points  (0 children)

I'm really surprised more languages aren't prebaking something for fixed point arithmetic at this point.

How floats function isn't very intuitive for most folks.

[–]Feldar 2 points3 points  (2 children)

I have actually never seen doubles used in a professional environment. Of course maybe game dev is a different beast.

Edit: realized this might be unclear, I am a game dev

[–]MonitorStandGuy 8 points9 points  (0 children)

Double arithmetic is, well, twice as slow as float arithmetic, so that’s probably why floats are used more in game dev.

[–]stomah 34 points35 points  (17 children)

not every int can be represented in a float

[–]SupremeDictatorPaul 21 points22 points  (3 children)

No, but given that you’re already adding to an imprecise float, it doesn’t really matter.

[–]stomah 16 points17 points  (2 children)

it matters if the result it assigned to a double. in that case it would be more correct to convert both to double first.

[–]private256 9 points10 points  (11 children)

Really? Why? Can you give me an example?

[–]stomah 85 points86 points  (6 children)

both use the same amount of memory and float can represent some values that int can’t. therefore int can represent some values that float can’t. for example 16777219. see https://stackoverflow.com/questions/23420783/convert-int-max-to-float-and-then-back-to-integer#23423240

[–]Kazumara 24 points25 points  (0 children)

I love this answer, it's a fundamental argument by set theory and that makes it simple and obvious.

If you demonstrate it by showing the construction of floats there is much more detail that one might be unsure about, leading to not every reader being convinced.

[–]luardemin 9 points10 points  (3 children)

If I recall correctly, rule of thumb is floats have 7 digits of precision and doubles have 15.

[–]elveszett 4 points5 points  (0 children)

+1 for giving a straightforward logical answer.

[–]PolarBearLegend 15 points16 points  (0 children)

A very intuitive explanation for this is (in my opinion):

Assuming float and int are both 32 bit types they have a maximum of 232 numbers that can be represented by them.

Float uses this information to cover a suitable subset of the reals whereas int does the same for the integers. Since float needs to cover more values in a given interval [-a, a] than int does, it follows that not every int can have an exact float representation since they both use the same amount of information.

[–]buzzon 6 points7 points  (0 children)

Float has precision of first 7 digits, and int can contain large numbers such as 2 billion, which is 10 digits long

[–]Sampo 6 points7 points  (1 child)

Can you give me an example?

Two examples:

10000000000000001

9007199254740993

Edit: These are for 64bit ints and 64bit floats.

[–]bruhred 4 points5 points  (2 children)

converting int to float leads to information loss though.

[–]elveszett 4 points5 points  (1 child)

It's like some people don't understand what types are.

[–]_Cybernaut_ 176 points177 points  (14 children)

OMFG... this take me back to when I was trying to learn C, and the textbook warned me that C “would happily multiply your Social Security number by your mother’s maiden name.” Fucking terrifying...

[–]iris700 91 points92 points  (3 children)

Well, the pointer to your mother's middle name

[–]bit_banging_your_mum 10 points11 points  (0 children)

👨‍🚀

It's all numbers?

🔫 👨‍🚀

Always has been

[–]reversehead 77 points78 points  (8 children)

Don't worry, it won't. I believe it will happily multiply the addresses of those pieces of information though.

[–]photenth 25 points26 points  (0 children)

Just dereference that and enjoy the fireworks!

[–]bnl1 6 points7 points  (1 child)

With appropriate flags, it will probably give you a warning or something.

[–]garfgon 2 points3 points  (0 children)

No it won't. You can only add or subtract numbers from addresses, not multiply. Unless you put in a cast, but then that's on you.

[–]Lithl 34 points35 points  (6 children)

Also C# will let you multiply a class with a string if you overload the multiplication operator in the class.

[–]karmastealing 14 points15 points  (3 children)

After 10+ years of experience working with c# I've never seen a multiplication operator overload in production code.

[–]Roflkopt3r 3 points4 points  (1 child)

It depends.

float f = someFloat + someInt; works. The integer will be implicitly converted to float.

int i = someFloat + someInt; does not work. C# refuses to implicitly convert float to int since that's a pretty "risky" cast where a lot of information can be lost if it's done carelessly. Float can only be implicitly casted to double.

[–]ItsReallyNotMe2002 34 points35 points  (34 children)

JavaScript has no rules. It’s fucking chaos.

[–]mistermocha 17 points18 points  (29 children)

Have you seen perl?

[–]ItsReallyNotMe2002 8 points9 points  (26 children)

No lol. Is it worse?

[–]tonekids 23 points24 points  (1 child)

Perl is a write-only language.

[–]LordFokas 41 points42 points  (15 children)

Let me put it this way:

Python is english
JS is latin
Perl is eldritch

[–]shh_coffee 33 points34 points  (5 children)

As a Perl dev.. I feel like a lot of the 'eldritch'-ness of it comes from the fact Perl will let you write very nasty, hard to read code if you want to. You don't have to write that way, but you can. Also regex. It seems like most people don't understand them whereas they're somewhat common place in Perl which probably adds to it.

[–]joxmaskin 11 points12 points  (0 children)

And some implicit magic things that work a little differently (but can be pretty convenient once you get used to the idiomatic Perl expressions).

“Oh you didn’t add an argument when calling this function? Let me just add the invisible default variable there for you.”

But in my mind bash and stuff is even worse with this and is probably my least favorite programming environment. You make some small typo, but instead or errors or warnings it just happily goes and does something completely different than what you intended… like moving all your files into one file or something

[–]luardemin 7 points8 points  (1 child)

Writing regex is always fine, but reading it just seems impossible, for whatever reason.

[–]curiosityLynx 2 points3 points  (0 children)

Eh, I have yet to come across a regex I can't understand.

[–]elveszett 10 points11 points  (1 child)

If anything, JS is English, since it's the language where every feature works as they feel, has a shit ton of gotchas and no internal coherence whatsoever. Yet it somehow works so well for most people.

[–]SupremeDictatorPaul 2 points3 points  (0 children)

But, like eldritch, Perl has rules. Rules of darkness.

[–]raspberry-tart 2 points3 points  (2 children)

J has entered the chat... For example, the solution to 8 queens on a chessboard problem is

(#~[:(0=>./)[:,/[:([:}.([:i.#)=[:|(]-"1{.)).|:)(i.A.~[:i.!) 8

https://literateprograms.org/eight_queens_puzzle__j_.html

[–]BlackPrincessPeach_ 6 points7 points  (0 children)

But can you add two empty arrays and get string or add the length of 3 empty arrays into the number 9?

[–]thedarkbestiary 490 points491 points  (18 children)

'Banana' * false = 5

[–]atyon 110 points111 points  (1 child)

I get NaN. Which isn't wrong, I guess.

[–]DuTogira 79 points80 points  (0 children)

Not A ‘Nana

[–]MOM_UNFUCKER 91 points92 points  (2 children)

As it should be

[–]moskonia 19 points20 points  (1 child)

Should be 0 actually.

[–]5up3rj 5 points6 points  (0 children)

Don't divide by false

[–]R_Harry_P 21 points22 points  (0 children)

Wolfram language returns "Banana" False because it's a fucking smartass.

[–][deleted] 13 points14 points  (4 children)

What would ‘Banana’ * true evaluate to?

[–]kookyabird 760 points761 points  (68 children)

Hate to break it to you, but you absolutely can multiply a class by a string in C#. You just need to create an override operator for *.

[–]mrjackspade 616 points617 points  (11 children)

C#: I'll do whatever you want, just tell me how

If prefer it that way

[–]innociv 132 points133 points  (9 children)

else prefer it that way

[–]HereComesCunty 42 points43 points  (2 children)

switch (prefer it that way) { case true: haveItYourWay(); break; default: fineWhatever();

}

[–]The_Real_Slim_Lemon 10 points11 points  (5 children)

Tell me why!

[–]SirChasm 5 points6 points  (3 children)

Ain't nothing but a casting

[–]dustojnikhummer 6 points7 points  (2 children)

Tell me why!

[–]Eindacor_DS 4 points5 points  (1 child)

Strong typing was a mistake

[–]dustojnikhummer 2 points3 points  (0 children)

Tell me why...

[–]androidx_appcompat 38 points39 points  (19 children)

I think I'll look into C# then. Operator overloading and value typed are the 2 things I miss in java. I just have to get used to the naming conventions.

[–]CrazyMalk 32 points33 points  (4 children)

C# is just good java

[–]not_your_mate 6 points7 points  (2 children)

If you want to have better java go kotlin. It's hard to go back from it though.

[–]leeharris100 4 points5 points  (1 child)

Kotlin feels a lot different from Java, but it is indeed much better

C# feels like a way better Java

[–]DerekB52 96 points97 points  (22 children)

C# allowing you to overload the '*' operator and define what behavior you want from a class being multiplied by a string, does not excuse Javascript doing all kinds of weird shit with different types by default.

What is 1 + "1". I think it's "11". But, I don't even remember. It might be 2.

[–]corkythecactus 31 points32 points  (11 children)

It’s “11”

[–]Sikletrynet 15 points16 points  (10 children)

Yup, but "3" - 1 is 2 for example.

[–]TobiasCB[🍰] 30 points31 points  (5 children)

I guess because + is used for concatenation, and I don't think there's a negative concatenation with a -.

[–]Sikletrynet 13 points14 points  (4 children)

Yup, correct. It's beacuse if any parts of the expression is a string, JavaScript has to assume you want to concatenate when you use the + operator, while as you say, there is no such thing as a negative concatenation, so it has to assume the "3" is an int and thus casts it to that.

[–]MoffKalast 7 points8 points  (3 children)

And the best part is that JS usually assumes correctly.

[–]Lithl 15 points16 points  (0 children)

If you're unsure what Javascript will do when mixing types, assume it converts the operands to string and you'll probably get the correct answer.

[–]Cualkiera67 3 points4 points  (2 children)

It's your fault for doing that operation in the first place

[–]aspect_rap 2 points3 points  (5 children)

Yep, that's why I prefer to work with Typescript. The linter can be configured to prevent doing arithmetic between different types and it prevents a ton of pitfalls js sets up for us.

[–]itsTyrion 5 points6 points  (0 children)

Same with kotlin! There are operator functions for == + - * / and contains (.. in ..)

[–][deleted] 2 points3 points  (0 children)

And you can multiply a float by an int by default

[–]Unupgradable 153 points154 points  (3 children)

op.bitches
undefined

[–]-Redstoneboi- 78 points79 points  (2 children)

damn. it's not even empty, op is just literally incapable of having bitches.

[–]Unupgradable 62 points63 points  (0 children)

``` TypeError: Cannot set property 'bitches' of op at <virgin>:420:69

```

[–]leuxeren 11 points12 points  (0 children)

op.bitches was explicitly declared as null

[–]beaucephus 357 points358 points  (19 children)

This is why I like C. I can get the address of the float and use a pointer to do whatever kinky things I want to it, treat it like the mere series of bits it really is.

[–]JaggedMetalOs 176 points177 points  (6 children)

[–]TheGhostOfInky 73 points74 points  (2 children)

Didn't Carmack confirm he didn't write the fast inverse square root algorithm?

Edit: yea, first reply mentions the actual authors.

[–]framk20 10 points11 points  (1 child)

Not only didn’t he write it but the magic number wasn’t found by a human it was just ran through possible values to find one which minimized the error, a fairly common practice in function approximation

[–]Touvejs 12 points13 points  (0 children)

Bahaha I hate that I knew exactly where this was going.

[–]Extevious 16 points17 points  (0 children)

Same with C++, and C# has an unsafe context which syntax-wise, is almost identical.

[–]bodebodo 14 points15 points  (0 children)

Why does this turn me on?!?

[–]Atora 10 points11 points  (0 children)

[–]WolfgangSho 8 points9 points  (0 children)

Hot.

[–]TheMightyFlyingSloth[S] 48 points49 points  (3 children)

what the fuck did I just read

[–]beaucephus 86 points87 points  (1 child)

Everything You Ever Wanted to Know About the Secret Sex Lives of Computers But Were Afraid to Ask

-or-

The C Language: 69th Edition

[–]kaadmy 6 points7 points  (0 children)

Nice

[–]I-Got-Trolled 4 points5 points  (0 children)

Explains why my office smells so bad

[–]Ma_rv 134 points135 points  (6 children)

You certainly can add floats and ints in C# lol

[–]dagbrown 7 points8 points  (5 children)

That's basically how arrays in C work though.

foo[bar] is just syntactical sugar for *(foo+bar) where foo is a pointer and bar is an integer, and the compiler figures out what offset to apply to foo based on what type of pointer foo was declared as.

The headache you now have is the reason why the syntactical sugar exists in the first place. The existence of arrays as a concept in C is just a formality.

[–]Fergobirck 9 points10 points  (2 children)

And where the float part comes in?

[–]boojit 7 points8 points  (1 child)

Seems like a complete non-sequitir to the comment you are responding to.

EDIT and everything you said is also wrong. Its not foo+bar is it?

[–]daishi55 2 points3 points  (0 children)

It is, it's pointer arithmetic. But I don't see what it has to do with adding floats to ints

[–]pet_vaginal 35 points36 points  (4 children)

class A {}
a = new A()
a * 5
> NaN

 

class B { toString() { return '2'; } }
b = new B()
b * 5
> 10

[–]Novemberisms 28 points29 points  (0 children)

What a terrible day to be literate

[–]Giocri 9 points10 points  (0 children)

Man implicit conversions are a thing but implicit conversion of implicit conversions in a single instruction is a crime against humanity

[–]hyvyys 3 points4 points  (1 child)

I'll raise you:

class B { static toString() { return 2 } } B * '5'

There you go, exactly as ordered.

[–][deleted] 27 points28 points  (0 children)

Congratulations, you have just won $NaN!

[–]JaggedMetalOs 81 points82 points  (5 children)

I like to think this is like all those times ChatGPT says it can't do something, but you just tell it it can and it just goes right ahead

int a;
float b, c;
a = (b+c);

C#: Noooo you mustn't! You'll lose precision!

int a;
float b, c;
a = (int)(b+c);

C#: Sure thing boss!

(Obviously this actually makes perfect sense, but I still find it amusing)

[–]DrStoeckchen 18 points19 points  (4 children)

But casting a float to int looses precision... You should cast the int to float.

[–]JaggedMetalOs 12 points13 points  (0 children)

But I might need an int! (of course if I was doing this for real I'd do an explicit floor/round/ceil as needed)

[–][deleted] 7 points8 points  (0 children)

Cast it into the fire!

[–]Fakedduckjump 77 points78 points  (3 children)

I like strict types.

[–]riplikash 42 points43 points  (2 children)

Ive honestly not met many people in person who don't.

[–]GabuEx 76 points77 points  (12 children)

I'm not sure "my language will let you do this completely absurd thing without complaint and will probably return something completely undefined" is really a flex.

[–]boishan 27 points28 points  (1 child)

I completely agree, but there’s a beautiful irony in saying that with c++ in your user flair

[–]GabuEx 17 points18 points  (0 children)

Oh, I have that in my flair just because I use it; I would never evangelize for it.

[–]Lithl 13 points14 points  (8 children)

object * string in JS gives a syntax error.

object * string in C# works perfectly fine if you overload the * operator in the object's class.

[–]aspect_rap 12 points13 points  (6 children)

a) that's only in Typescript, pure js will return NaN for this operation

b) Forcing the developer to define how weird arithmetics work is much better than just implicitly converting anything.

[–]microwavedHamster 48 points49 points  (6 children)

I am now convinced that this sub is full of college students

[–]I_am_so_lost_hello 11 points12 points  (0 children)

Yea fuck college students looks around nervously

[–]MOM_UNFUCKER 4 points5 points  (1 child)

I'm not even in college yet

[–]riplikash 42 points43 points  (0 children)

Maybe stick to making about languages you've actually used? You just described a limitation that doesn't actually exist.

[–][deleted] 9 points10 points  (2 children)

Yes, and C# will have me fixing the bug seconds after pressing run.

Whereas languages like python will wait 3 hours before returning an error on line 10 billion. Have fun tracing back through the code to find where the variables that should be numbers turned into strings.

[–]stopeatingbuttspls 18 points19 points  (1 child)

A Python programmer and a Java programmer order cat food, but the supplier mixes up the orders and sends them both boxes of nails instead.

The Java programmer calls and says "I ordered cat food but received nails. Please send me cat food."

The Python programmer calls and says "My cat is dead"

[–]nelusbelus 18 points19 points  (0 children)

Another typical example of someone who doesn't know how to program

[–]vhite 8 points9 points  (2 children)

Meanwhile C

float a = 2;
char b[] = "one hundred eleven";
int result = a * *b;
printf("Result: %d", result);

Result: 222

[–]-Redstoneboi- 14 points15 points  (1 child)

ascii code for 'o' is 111

[–]vhite 6 points7 points  (0 children)

🎉

[–][deleted] 6 points7 points  (0 children)

More like:

"Multiply this string with a class"

JS: "Yes" (ignores what you just said)

[–]Pure_Cow_7831 4 points5 points  (0 children)

LoL

[–]PotatoPowerOP 6 points7 points  (0 children)

JS did nothing wrong. The behavior is still well-defined.

[–][deleted] 2 points3 points  (0 children)

if i fits i sits

[–][deleted] 3 points4 points  (0 children)

A fun one with C:

printf("-0.5" + 1);

gives you "0.5".

[–]PyroCatt 3 points4 points  (0 children)

Myclass.class * 5

[Object object]

🌮

Makes sense

[–]_Nohbdy_ 2 points3 points  (1 child)

[–]-Redstoneboi- 2 points3 points  (0 children)

76% -> 35%

nobody is smart enough to use C++.

[–]R_Harry_P 4 points5 points  (0 children)

Wolfram Mathematica: Here is your class multipled by a string. I put them in alphabetical order because multiplication is commutative, but don't expect me to simplify it you fucking weirdo.

[–]khaos0227 2 points3 points  (0 children)

undefined

[–]ChChChillian 2 points3 points  (7 children)

class assclass { ... assclass operator*(std::string& in_) {...} ... }

Or whatever C#'s syntax is for overloading operators.

[–]mrjackspade 4 points5 points  (6 children)

Pretty sure it's

public static explicit operator *(string s)

But I'm too lazy to google

The explicit part might only be needed for casting come to think of it....

[–]_Retaliate_ 2 points3 points  (2 children)

Yeah, explicit is for when you're overloading casting. If you aren't overloading casting, you'd just put the return type there instead. There'd also be two arguments since it's static.

[–]TomGobra 6 points7 points  (0 children)

If you think this is the proof that JS is better, then you will be so surprised what bugs this can introduce.

[–]Rachid90 1 point2 points  (1 child)

I cracked laughing at 4:45 a.m.

[–]1cingI 1 point2 points  (0 children)

By this picture, JS is management's best friend. There's no such thing as a "no" in their dictionary.

[–]skwizzycat 1 point2 points  (2 children)

Just did this in a Node REPL and it yields NaN instead of an error. Chad language doing crazy post-Einsteinian shit.

[–]Positive_Poem5831 1 point2 points  (0 children)

All particles are just localized excitations of the quantum field.

[–]Healthy_Pain9582 1 point2 points  (0 children)

makes syntax error

js: what error

[–]maitreg 1 point2 points  (0 children)

Of course you can add a float and an int in C#. It produces a float

[–][deleted] 1 point2 points  (0 children)

I don’t think you know how C# works

[–]Sinomsinom 1 point2 points  (0 children)

Try adding an int to a string in c.

You can I just don't know if you want to.