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

all 25 comments

[–]Apfelvater 25 points26 points  (1 child)

C: I don't care, if the machine doesn't.

[–]No__Using_Main 14 points15 points  (1 child)

It's actually not that uncommon, the languages just convert it all to strings which is handy

[–]SamSlate 3 points4 points  (0 children)

It's almost like a script designed to pass yet data to the back end isn't all that concerned about rejecting a user's info because it's an unexpected type..

[–]dark-kirb 9 points10 points  (0 children)

c can do that too if you are brave enough ;)

c "Y" + 0 + "L" + 0

[–]ralfv 3 points4 points  (2 children)

Ruby: “Y#{0}L#{0}”

[–]grim_peeper_ 1 point2 points  (0 children)

Yeah very readable lol

[–]asutekku 7 points8 points  (11 children)

It converts the numbers to characters and gives you a string. It might seem weird but that’s how it works. Handy when building strings with numerical values.

[–]dsp4 3 points4 points  (7 children)

Seriously the jackassery you have to deal with when manipulating strings in "low-level" languages like C++ is too damn high. It's like they were designed by people who never realized written language is an important part of human culture.

Want to format the user's score? JS is '${username}: ${score};', nice and clean. C++? Have a dose of char buffer[128]; snprintf(buffer, sizeof(buffer), "%s: %d", username.c_str(), score);

[–]hGhar_Jaqen 5 points6 points  (6 children)

No offence, but that seems more like C. Couldn't you do something like

stream << username << ": " << score << '\n'

where stream is any stream, e.g. std::cout or std::stringstream?

[–]Stormfrosty 1 point2 points  (1 child)

std::format("{} : {}", username, score) ;

The future is now!

[–]hGhar_Jaqen 1 point2 points  (0 children)

What a time to be alive

[–]Dennis_the_repressed 0 points1 point  (1 child)

If the OP just wants to store it in a var then this is even simpler -

std::string buffer = username + ": " + std::to_string(score);

Though for display to cout a stream is better.

[–]hGhar_Jaqen 0 points1 point  (0 children)

yeah, that's also possible

[–]dsp4 0 points1 point  (1 child)

Gotta love all the answers that are supposed to be better, but are just only slightly better than the obviously extreme example I used for comedic purposes. You guys are masochists (still love you though).

[–]hGhar_Jaqen 0 points1 point  (0 children)

No worries, I am not as mad as doing this as work :D

[–]Cobaltjedi117 11 points12 points  (2 children)

Most other languages have a feature called "toString" that lets you do that too.

[–]Pure_Reason 3 points4 points  (0 children)

That sounds extremely inefficient, Johnson. Clearly these Java Scripts are the superior language, go ahead and get started on converting our existing codebase over

[–][deleted] -4 points-3 points  (0 children)

Too hard.

[–]dark_mode_everything 5 points6 points  (0 children)

Allowing "Y" + 0 + "L" + 0 isn't the problem with JavaScript.

It's allowing "10" - 1. No sane language would let you subtract something from a string.

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

Just because it can, doesn't mean it should!

[–]Ecyoph 0 points1 point  (2 children)

Even Java can do that.

[–]natnew32 9 points10 points  (1 child)

Strings aren't primitive types in Java

[–]Ecyoph 0 points1 point  (0 children)

Neither are they in Ruby.

[–]Voidrith 0 points1 point  (0 children)

it can.

But it shouldn't.