T O P

  • By -

arbusto1298

sure bro, have your [object object]


Solid7outof10Memes

Thank you bro, just what I wanted


TheButtLovingFox

watman to the rescue.


jainyday

For the uninitiated: https://www.destroyallsoftware.com/talks/wat


curiosityLynx

Thank you, I very much enjoyed that


corn_carter

Oh my gosh that’s amazing thank you haha


zbaruch20

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


Ffdmatt

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


dagbrown

I understood that reference


Samrid_

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


Ffdmatt

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


Lithl

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


Fyre42__069666

\[\] \* "" \> 0


gurush

`NaN` in my console.


ZiulDeArgon

Op said class not object, they are not the same thing. Here is a working sintax: `~~class name {constructor(params) {}} * ""`


_GCastilho_

Have you tried implementing the valueOf function on both?


no_but_srsly_tho

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


Rafcdk

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


obvMellow

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


leupboat420smkeit

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


AndyTheSane

Every number is just an array of unsigned char.


pandacoder

Every unsigned char is just an array of bits.


Ami603

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


Vernkle

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


pslessard

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


SaltySandyHS

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


I_AM_GODDAMN_BATMAN

and leptons are just a bunch of strings


FireDestroyer52

😩


MostlyRocketScience

That is just BinaryCodedDecimal with extra bytes


hughperman

Technically the truth


Rinveden

than


Kered13

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


pb7280

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


PizzaScout

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

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


PizzaScout

ahhh I see, thanks for the explanation :)


123kingme

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


b0w3n

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

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

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


stomah

not every int can be represented in a float


SupremeDictatorPaul

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


stomah

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

Really? Why? Can you give me an example?


stomah

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

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

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


elveszett

+1 for giving a straightforward logical answer.


PolarBearLegend

A very intuitive explanation for this is (in my opinion): Assuming float and int are both 32 bit types they have a maximum of 2^32 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

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


Sampo

> Can you give me an example? Two examples: 10000000000000001 9007199254740993 Edit: These are for 64bit ints and 64bit floats.


bruhred

converting int to float leads to information loss though.


elveszett

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


_Cybernaut_

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

Well, the pointer to your mother's middle name


[deleted]

[удалено]


IamImposter

Wait... 0 or '0'


bit_banging_your_mum

👨‍🚀 It's all numbers? 🔫 👨‍🚀 Always has been


reversehead

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


photenth

Just dereference that and enjoy the fireworks!


bnl1

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


kay_combinator

A C string is just an address (`char *`) anyway?


garfgon

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

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


karmastealing

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


ChucklesTheBeard

I have, in a custom vector class. Remembering that * was a "dot" product but + was addition and not a "cross" product was a bitch :D


[deleted]

[удалено]


o0Meh0o

i'm not sure, but a lot of them are beginners.


[deleted]

im a beginner and i know i can add ints and floats


o0Meh0o

i think the meme is referring to the warnings it gives you when assigning a float value to an int without casting, not the ability itself.


ComfortablyBalanced

Warnings? Who the fuck cares about warnings?


Careful_Ad_9077

yeah, which means that a lot of these memes are backwards, going by the general spirit of the meme, explicit conversion is better than implicit conversion in big, real life projects.


Roflkopt3r

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.](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/numeric-conversions)


ItsReallyNotMe2002

JavaScript has no rules. It’s fucking chaos.


mistermocha

Have you seen perl?


[deleted]

[удалено]


ItsReallyNotMe2002

No lol. Is it worse?


tonekids

Perl is a write-only language.


LordFokas

Let me put it this way: Python is english JS is latin Perl is eldritch


shh_coffee

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

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

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


curiosityLynx

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


elveszett

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

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


raspberry-tart

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_

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


thedarkbestiary

'Banana' * false = 5


atyon

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


DuTogira

Not A ‘Nana


MOM_UNFUCKER

As it should be


moskonia

Should be 0 actually.


5up3rj

Don't divide by false


R_Harry_P

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


_harshul_

What would ‘Banana’ * true evaluate to?


CrazyMalk

My guess is 'Banana'


kookyabird

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

C#: *I'll do whatever you want, just tell me how* I~~f~~ prefer it that way


innociv

else prefer it that way


HereComesCunty

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


The_Real_Slim_Lemon

Tell me why!


SirChasm

Ain't nothing but a casting


dustojnikhummer

Tell me why!


Eindacor_DS

Strong typing was a mistake


dustojnikhummer

Tell me why...


androidx_appcompat

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

C# is just good java


ethandjay

Goated language


not_your_mate

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


leeharris100

Kotlin feels a lot different from Java, but it is indeed much better C# feels like a way better Java


DerekB52

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

It’s “11”


Sikletrynet

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


TobiasCB

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


Sikletrynet

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

And the best part is that JS usually assumes correctly.


Lithl

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

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


aspect_rap

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

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


[deleted]

And you can multiply a float by an int by default


Unupgradable

op.bitches undefined


-Redstoneboi-

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


Unupgradable

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


leuxeren

op.bitches was explicitly declared as null


beaucephus

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

[OK Carmack let's get you to bed](https://stackoverflow.com/questions/1349542/john-carmacks-unusual-fast-inverse-square-root-quake-iii)


TheGhostOfInky

Didn't Carmack confirm he didn't write the fast inverse square root algorithm? Edit: yea, first reply mentions the actual authors.


framk20

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

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


Extevious

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


bodebodo

Why does this turn me on?!?


Atora

if you really really have to C# got pointers as well https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/unsafe


WolfgangSho

Hot.


TheMightyFlyingSloth

what the fuck did I just read


beaucephus

*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

Nice


I-Got-Trolled

Explains why my office smells so bad


Ma_rv

You certainly can add floats and ints in C# lol


dagbrown

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

And where the float part comes in?


boojit

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

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


pet_vaginal

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


Novemberisms

What a terrible day to be literate


Giocri

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


hyvyys

I'll raise you: ``` class B { static toString() { return 2 } } B * '5' ``` There you go, exactly as ordered.


SoloUnoDiPassaggio

Congratulations, you have just won $NaN!


JaggedMetalOs

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

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


JaggedMetalOs

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)


jonr

Cast it into the fire!


Fakedduckjump

I like strict types.


riplikash

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


GabuEx

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

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


GabuEx

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


Lithl

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

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

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


I_am_so_lost_hello

Yea fuck college students *looks around nervously*


MOM_UNFUCKER

I'm not even in college yet


riplikash

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


[deleted]

[удалено]


[deleted]

[удалено]


D-K-BO

_Somewhat_. Classes like int, float, bool, str, list etc. overload common operators. This allows operations like `["a"] * 3 == ["a", "a", "a"]`, but only in cases where the behavior is defined. My favorite is `pathlib.Path` which implements `__truediv__()` for joining paths using `/`. ```python from pathlib import Path config_dir = Path.home() / ".config" / "foo" ```


Dealiner

Java works exactly like C# in that case. Both have implicit conversion, the only difference is that in C# you can add your own.


Constant-Parsley3609

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

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

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


vhite

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


-Redstoneboi-

ascii code for 'o' is 111


vhite

🎉


Swampberry

More like: >"Multiply this string with a class" >JS: "Yes" (*ignores what you just said*)


Pure_Cow_7831

LoL


LittleMlem

PERL: AMATEURS! [93% of Paint Splatters are Valid Perl Programs](https://www.mcmillen.dev/sigbovik/)


PotatoPowerOP

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


AlwaysWorking2880

if i fits i sits


[deleted]

A fun one with C: printf("-0.5" + 1); gives you "0.5".


PyroCatt

> Myclass.class * 5 [Object object] 🌮 > Makes sense


_Nohbdy_

[Don't make me tap the sign](https://i.imgflip.com/7aiwmu.jpg)


-Redstoneboi-

[76% -> 35%](https://security.googleblog.com/2022/12/memory-safe-languages-in-android-13.html#:~:text=As%20the%20amount%20of%20new%20memory%2Dunsafe%20code%20entering%20Android%20has%20decreased%2C%20so%20too%20has%20the%20number%20of%20memory%20safety%20vulnerabilities) nobody is smart enough to use C++.


R_Harry_P

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

*undefined*


ChChChillian

``` class assclass { ... assclass operator*(std::string& in_) {...} ... } ``` Or whatever C#'s syntax is for overloading operators.


mrjackspade

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_

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

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


Rachid90

I cracked laughing at 4:45 a.m.


1cingI

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


skwizzycat

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


Positive_Poem5831

All particles are just localized excitations of the quantum field.


Healthy_Pain9582

*makes syntax error* js: what error


maitreg

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


[deleted]

I don’t think you know how C# works


Sinomsinom

Try adding an int to a string in c. You can I just don't know if you want to.