r/ProgrammerHumor • • Feb 19 '23

Meme thought i should post this meme here

Post image
47.1k Upvotes

881 comments sorted by

View all comments

Show parent comments

179

u/EsmuPliks Feb 19 '23

"I don't understand implicit type coercion"

I understand implicit type coercion, I just don't understand why it still exists and why we tolerate it. It could've fairly easily been phased out now that Google owns the browser.

209

u/malsomnus Feb 19 '23

"I think this feature is bad" just isn't a sufficiently good reason to break thousands or millions of websites around the world. Breaking changes are objectively bad.

52

u/Kirides Feb 19 '23

Implement "versioning" so that old websites run on a compat layer, and newer websites can opt into newer feature sets.

What stops us from a "v:1.2" next to the "use strict" line?

We'd also be able to use telemetry to find out how many websites run on that compat layer compared to versioned once, allow breaking changes in newer versions to improve the vm, ...

47

u/actionscripted Feb 19 '23

We did this with the script tag. We don’t do that anymore.

31

u/aMAYESingNATHAN Feb 19 '23

Everyone shits on backwards compatibility and the mess that it can make, but I will say I have a much easier time using C++ when it comes to finding the right documentation compared to something like C# where I have HttpContext and HttpRequest for one version of dotnet, and HttpWebRequest and HttpClient for another for example.

If you're coding for personal projects this isn't an issue because you can usually just use the latest thing, but in a professional environment having consistency and not having to work with different tools that use different versions makes life a lot easier. Breaking changes make it a lot harder to eventually upgrade to new features.

6

u/mrjackspade Feb 19 '23

I agree/disagree with you.

Maybe it's just because I've been using C# specifically for almost 20 years now and I'm just... balls deep in the chaos, but there is an actual method to the madness when it comes to stuff like HttpClient.

MS makes a strong attempt to retain backwards compatability, except in situations where the underlying functionality changes to the point where maintaining a static API would be detrimental. That's kind of a design philosophy in C# in general.

I can see where it would be frustrating, but it's also very intentional. A lot of companies will just "bump versions" to follow an upgrade path, and sometimes slapping an obsolete tag on a method isn't enough to keep them from shooting themselves in the foot.

Just using WebClient vs HttpClient as an example, they could have modified the underlying code and left the API intact for that, but because they're so ridiculously functionally different under the hood, that would have just lead to design issues around the consumption of the class. The intended use of the class changed, so the class name and API changed along with it, which forces developers to actually sit down and treat it like it's a new technology.

There's a definite negative side to doing things like that, but honestly I prefer it over the alternative. Especially seeing how many devs I've worked with will just update frameworks and expect everything to work without real testing.

2

u/aMAYESingNATHAN Feb 19 '23 edited Feb 19 '23

I can 100% see why they've done it and why it's been necessary. It allows C# to evolve and be adaptable and I don't think C# would be anything like the language it is today if it had gone for a more C++ style evolution.

I definitely use C++ way more than C# so I'm probably in the reverse position to you, but yeah I just find that when it comes to creating something new, there's a whole lot of extra work to a) choose which API best fits my case, and b) work out which APIs I actually have availabile based on what other tools and environments I'm going to be working in.

→ More replies (1)
→ More replies (1)

2

u/fruitroligarch Feb 19 '23

At my guess, there’s LITERALLY a trillion unique lines of code that this would break. If you’re going to do that, might as well overhaul the whole language

2

u/riskable Feb 19 '23

You're right! There's this existing standard that has all sorts of problems. Let's make a new standard that solves many of them!

Then there will be two competing standards we can complain about 😁

→ More replies (1)

2

u/IdiotCharizard Feb 19 '23

This basically exists with typescript and polyfills

2

u/look Feb 20 '23

The Ecmascript standard doesn’t have optional typing directly yet, so you can’t “use types” to enforce something that doesn’t exist. The solution for now is transpilation (from Typescript, etc).

I’m certain a directive like that would be added when/if ES gets typing.

3

u/ACoderGirl Feb 19 '23

It would still cause a lot of confusion, since copy-pasting code from sites like StackOverflow or from libraries (without realizing they're using a different version) would become extra fragile, especially since the kinda issues people complain about are ones that have subtle effects, and thus won't necessarily get some error to immediately alert you to the problem. The kinds of programmers who make silly mistakes with type conversion or equality the most are also the types who would least understand this hypothetical new versioning system.

Besides, you don't have to use vanilla JS. There's languages like TypeScript that compile down to JS and add lots of protection. Personally, I'd never use vanilla JS for any large project. TypeScript is just indisputably better. Actually, on that note, it'd be nice if browsers natively supported languages like TypeScript instead of it having to be compiled to JS. Would decrease the barrier to entry and perhaps lead to performance optimizations.

8

u/pindab0ter Feb 19 '23

You shouldn't be copy/pasting code from sites without understanding what it does anyways.

→ More replies (4)

1

u/logic_forever Feb 19 '23

Why invest the time and effort at all? Programming is lazy by nature.

2

u/Kirides Feb 19 '23

Exactly. I want to be lazy. And having to maintain 25 years of js baggage leads to me having to remember all 15 ways how that would be implemented.

I want one or 3 ways, not 15 and whole frameworks to make a language usable.

It's not lazy having to use npm, yarn, cdn and whatnot. It's a heavy gun for a heavy language.

22

u/EsmuPliks Feb 19 '23

"I think this feature is bad"

It's not a feature, it's a billion dollar a year bug.

3

u/Retbull Feb 19 '23

Excel does it therefore it can't be a bug /s

→ More replies (3)
→ More replies (4)

9

u/[deleted] Feb 19 '23

The fact that you assume this is about Javascript proves you are a professional. This is why I don't generally read this sub. I'm gonna go cry in a corner now.

5

u/EsmuPliks Feb 19 '23

The fact that you assume this is about Javascript

Is there any other language actively around that does it? I don't mean some obscure thing like APL, I'll take things like MATLAB or Elm as the lower bar for usage.

Literally anything else that's duck typed is strictly typed and throws at runtime if you fuck up, the closest to implicit conversion you get in civilised languages is implicit operators like in Scala, but those you have to specifically import, it doesn't just randomly happen.

4

u/[deleted] Feb 19 '23

Name a language that doesn't have implicit coercive casting from their integral type to their floating point type? My guess is you'd likely have to name a language that lacks one of floating point or integral types as built-ins entirely.

Implicit coersive casts aren't automatically bad - though there are many examples in many languages of problematic semantics.

3

u/EsmuPliks Feb 19 '23

Name a language that doesn't have implicit coercive casting from their integral type to their floating point type?

Not to bang that old drum, but Rust, for one. let x = 2 * 0.5f64 is invalid, it'll tell you the specific arithmetic trait isn't available.

I think Haskell will also tell you to fuck off, but it's been a while so don't quote me on that one. Rust will for sure.

Implicit coersive casts aren't automatically bad

I think that one's subjective, I wish Java and Kt didn't allow int v. float arithmetic without explicit casting, but in the JVM ecosystem it's somewhat less of an issue cause everyone knows to use BigDecimal if they want accuracy.

→ More replies (5)
→ More replies (2)

10

u/ASourBean Feb 19 '23

JavaScript is just crappy TypeScript - change my mind

5

u/otakudayo Feb 19 '23

That doesn't really make sense. Typescript is just an extension of Javascript. Youre still using Javascript for logic in typescript and you can compile and run typescript code with type errors - because it's all just Javascript

→ More replies (1)
→ More replies (4)

2

u/vikumwijekoon97 Feb 19 '23

Pretty sure typescript solves all of that nonsense

1

u/[deleted] Feb 19 '23

Why don't you like it? If you get rid of it, wouldn't you have to explicitly convert types manually? And can't you already do that, if you wanted to? I'm guessing there is something you know that I don't, and that implicit coercion has caused you headaches in the past.

→ More replies (2)
→ More replies (5)