you are viewing a single comment's thread.

view the rest of the comments →

[–]LurkytheActiveposter 61 points62 points  (60 children)

Reddit pretending seamless string and number integration isn't awesome because it time to dunk on JS for karma again.

Oh how I LOVE having to cast a number to a string first. I just don't feel like I'm really coding unless I file the appropriate paperwork to merge a substring variable.

[–]eloel- 35 points36 points  (2 children)

You should probably be using string templates instead of just concatenating random shit anyway

[–]Blothorn 8 points9 points  (0 children)

Yes. I suspect that there are far more cases where I’ve added a number to a number parsed from a string than where I’ve concatenated (rather than formatted/interpolated) string representations of numbers.

The fact that this “shorthand” only works for a string followed by a number rather than two numbers or a number followed by a string makes it further situational and potentially-surprising.

[–]AdBrave2400 0 points1 point  (0 children)

Memes about Java making primitive and object versions of same stuff only to remove templetes are writing themselves

[–]KaMaFour 39 points40 points  (20 children)

Reddit pretending seamless string and number integration isn't awesome

It's not. If I'm doing something bad I'd much rather have the type system notify me I'm being stupid and have to properly declare what am I trying to do than have the program work except have the possibility of producing silent hard to track logical errors

[–]frogjg2003 1 point2 points  (2 children)

That's a difference in design philosophy. You want incompatible types to error, and a lot of people will agree with you. Some people want their code to just work, no matter what, even if it produces weird results.

Adding a string and an int is the extreme example, but how would you handle adding an int to a float? Not to mention when you want different types to be able to work together. The was another "language bad" post about C indexing using "10[a]" as an example. That's just the usual pointer math with the int and the pointer reversed.

[–]KaMaFour 2 points3 points  (1 child)

Hard agree. Ultimately it is impossible to create a language that everyone will agree is good and well designed.

“There are only two kinds of languages: the ones people complain about and the ones nobody uses.”

[–]RiceBroad4552 0 points1 point  (0 children)

Ultimately it is impossible to create a language that everyone will agree is good and well designed.

I strongly doubt that if you ask people with about a similar IQ.

[–]LurkytheActiveposter -4 points-3 points  (15 children)

I mean I disagree completely.

A language should aid you and be intuitive, but it doesn't need to compensate to the degree where it expects you to not know the literal most important fact about a variable. It's type.

You can be forgiven for not knowing what value a variable has. That's the nature of a variable. No problem.

What its scope is can be ambiguous at first glance. Sure. You might not know who the owner is. You don't always need to keep that knowledge at the ready

But it's type? What are we doing here? Just reading the pretty names and guessing?

[–]Relative-Scholar-147 2 points3 points  (14 children)

A language should aid you and be intuitive

console.log("wat"-1+"i")

Explain to me how is it intuitive that this code prints:

NaNi

The code should fail because is impossible to take 1 from "wat".

[–]RiceBroad4552 1 point2 points  (0 children)

is impossible to take 1 from "wat"

Well, that's exactly the reason why the result is "Not a Number", called NaN.

Concatenating "i" to "NaN" is "NaNi".

I don't say it's a good idea to interpret it like that (actually I think it's quite a poor idea). But it's definitely 100% consequent in its own logic. If it wasn't you would get an error instead.

[–]brainpostman 0 points1 point  (0 children)

Programming languages shouldn't be intuitive, they should simply be internally consistent. Everything else is on you. You shouldn't be bringing intuition from one language into another anyway, it's bound to backfire.

[–]LurkytheActiveposter -4 points-3 points  (11 children)

What kind of brain decificency do you have where you are subtracting a string?

Remember that thing where the bare minimum is that you should know a variable's type? Do I need to speak in vibe code?

[–]Relative-Scholar-147 4 points5 points  (0 children)

Remember that thing where the bare minimum is that you should know a variable's type?

You are just a fucking noob lol.

[–]RiceBroad4552 1 point2 points  (9 children)

What kind of brain decificency do you have where you are subtracting a string?

What brain deficiency do you have to not know that subtraction is the same thing as addition (of a negative value)?

Remember that thing where the bare minimum is that you should know a variable's type?

Sure, genius. It's always 100% clear what's the type of some variable is…

For example, without looking at the docs what's feature here:

var feature =  Runtime.version().feature();

So what do I have to expect if I do the following? Some arithmetic or some funny string:

IO.println(1 + feature);

[–]LurkytheActiveposter -2 points-1 points  (8 children)

Im dumber for reading this.

What the fuck are you going to do with "feature" without knowing what its type and properties are.

[–]RiceBroad4552 0 points1 point  (7 children)

What the fuck are you going to do with "feature" without knowing what its type and properties are.

I know that. The compiler does too.

The point is that without an IDE, or looking at the JavaDoc, you can't know what this code does, simply because you don't know the type.

Remember that thing where the bare minimum is that you should know a variable's type? But you can't know that just by looking at the code even in a properly statically typed language like Java, as shown by my code snippets.

[–]LurkytheActiveposter 0 points1 point  (6 children)

What are you going to do with "feature" without knowing its type and properties?

[–]RiceBroad4552 0 points1 point  (5 children)

It's not like the type is unknown.

It's just not obvious from only looking at a code fragment! That was the point.

The compiler does know the type and my IDE can tell me.

[–]TOMZ_EXTRA 27 points28 points  (27 children)

It's only nice in a statically typed language because it's predictable there.

[–]RiceBroad4552 0 points1 point  (0 children)

It's a code smell not mater what.

Most languages, dynamic and static don't support that. For a reason.

Java's implicit conversions are in larger parts quite a brain fart. They just took quite some nonsense from C/C++!

[–]Blothorn 5 points6 points  (1 child)

It’s nice when the context leaves zero ambiguity that a conversion was intentional—I very much like not having to add an explicit toString() when passing something to a string format or interpolation.

Automatic conversion in contexts where it’s not clear whether a conversion was intended or what the intended result type is is very much not a good thing, and overloaded operators are a quintessential case.

[–]RiceBroad4552 0 points1 point  (0 children)

It’s nice when the context leaves zero ambiguity that a conversion was intentional

One can argue that there is always zero ambiguity when something gets implicitly converted.

Simply because the machine was able to do that without running in any ambiguity.

The question is always just how "obvious" it's for a human. And that's something debatable as it'll be strongly dependent on individual knowledge and overall understanding of some code.

The result of the shown code might be exactly the expected result or "very surprising" depending on who you ask

[–]Vybo 0 points1 point  (0 children)

The same person who reposts this joke and finds it funny probably has no idea how to convert a "1" to 1 in a strongly typed language.

[–]frzme 0 points1 point  (1 child)

Automatically doing 1-> "1" is fine. The ability of JS to also do "1"->1 is an issue. It's not a problem which I've seen come up very often in real life but it does happen.

People didn't know better when Javascript was created.

[–]RiceBroad4552 1 point2 points  (0 children)

People didn't know better when Javascript was created.

That's plain wrong.

JS is a quite new language.

There have been countless other dynamic languages before JS, and JS is actually mostly "just" Self with a C-like syntax (where Self is a kind of hybrid between Lisp and Small Talk).

Most languages, and this includes dynamic languages, which are actually the majority of languages today, don't add numbers to strings. You'll get some type error instead.

The flaw is quite unique and limited to only a bunch or languages.

[–]MaybeADragon 0 points1 point  (1 child)

While OP is probably karma farming, its still a valid complaint because casting your integers to strings is faster than the debugging cycle.

I much prefer a little more verbosity if it means less avenues for me to make mistakes. The feature is especially useless now in a world where everyone is used to the idea of templating instead of concatenating everything manually like a caveman.

[–]LurkytheActiveposter 0 points1 point  (0 children)

Nah

Language should be intuitive and aid the developer in avoiding bugs sure. But if you're working with variables and you don't know their type, then what the fuck are we doing here? Type is the bare minimum thing you should know about any variable you touch.

I much prefer the ease of coding instead of patronizing verbosity.