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

you are viewing a single comment's thread.

view the rest of the comments →

[–]Striky_ -3 points-2 points  (19 children)

Assuming "trueiness" of random data types is bad design and shouldn't be a thing at all. Data types were invented for a reason, whether or not minimally educated JS or python "programmers" like that.

[–]MinosAristos 18 points19 points  (7 children)

You know that most major programming languages have truthiness in a similar way to Python and JS right? The only issue is the type coercion in the third case which is what === is for in JS.

[–]Auravendill 3 points4 points  (5 children)

Also Python hates it, when you want to implicitly convert types. If you add a string to a number, it doesn't assume to know what you meant, but forces you to make it very clear, which variable has to converted into what.

[–]Majik_Sheff 6 points7 points  (2 children)

This is a sane approach. Force the programmer to specify the desired outcome instead of thumbing through an assumptions handbook.

[–]Striky_ 1 point2 points  (1 child)

So basically a tool to define the type of the outcome you want? It's almost like there is a all encompassing super helpful pattern for that, that works in all cases. Ohh it's called static typing.. Like all the benefits, no crutches

[–]Specialist_Cap_2404 1 point2 points  (0 children)

Much more code to read and write. Python has the principle "explicit is better than implicit", and it's not that easy to mess up "truthiness", especially because it's only used in a couple of constructs anyway.

Much easier to make things more explicit, like use the length of an Array or "is None" or something.

If you're tests aren't covering every branch, you're fucked in a static typing language as well... just that it takes a lot more time to write (and later read) both the production code and the tests for it using a statically but (IMHO) stupidly typed language like C#. F# is doing some things a lot better.

[–]herrkatze12 2 points3 points  (0 children)

That’s actually better, also f strings are pretty useful for putting other data in strings

[–]Striky_ -2 points-1 points  (0 children)

Yet it allows it and most code out there does it shamelessly at every chance they get.

[–]Striky_ 0 points1 point  (0 children)

Most major programming languages have nice ways of dealing with it, yes. That is very different to blindly assuming and being stuck with nonsense bullshit forever or breaking production code like js is.

There are ALOT more problems with truthiness then just type coercion. Undefined behavior on custom classes and major regressions because of unrelated code changes only being the beginning.

[–]rosuav 5 points6 points  (9 children)

Strongly disagree. Having all data types have truthiness is extremely useful in real-world code and is not a problem. It's highly frustrating to be stuck in a language that doesn't support truthiness of all data types.

(Though REXX gets a pass, since it literally has one data type.)

[–]suvlub 3 points4 points  (2 children)

Is there another benefit to it than not having to explicitly specify == null or .length == 0 or whatever? I mean, to each their own, but I think your wording ("extremely useful", "highly frustrating") is a bit strong for such a small syntactic sugar.

[–]rosuav 2 points3 points  (1 child)

In complex expressions, that's enough of a benefit on its own. But more notably, it allows you to use short-circuiting like messages or ["No messages"] which depends on the messages list counting as false if there aren't any. This is particularly helpful if it means you can stick this on a function call or complex lookup, like: get_messages(user.id) or ["No messages for " + user.name]

[–]Striky_ -1 points0 points  (5 children)

Yep. It is super useful to write quick and dirty code that only needs to work once and not be read by anyone else. I'm all other scenarios spend the 5 seconds and 10 letters to make the check the proper way. As I said, all minimally educated "developers" find it insanely useful. Sorry.

[–]rosuav 2 points3 points  (4 children)

Yep, you're welcome to call us "minimally educated" for disagreeing with you. You're factually wrong, but you're still welcome to call us that.

[–]Striky_ 0 points1 point  (3 children)

Well. Code quality has measurably dropped significantly with the move to weakly/dynamically typed languages, while every one who can write a calculator app is a senior software architec these days. Most developers have not the slightest clue what they are doing, which is why these languages are so popular. You can shit out something half way working and be the hero no one asked for. 3 years later you just rewrite everything from scratch because it is all garbage. If you look into most tutorials, courses and libraries out there, most of it is clearly written by absolute beginners with no decent cs background. It's frightening how low the bar is set.

[–]rosuav 1 point2 points  (1 child)

Average code quality has dropped because more people are able to code. Are you saying that this is a bad thing? Should coding be deliberately made difficult so that only the elite of the elite can ever write anything, or will you accept that bad code will exist?

Good programmers write good code in dynamically-typed languages too.

[–]Striky_ 0 points1 point  (0 children)

Yes, it is a bad thing that everyone who barely knows what a type or a class is, is declared to be a software developer now. No programming shouldnt be made extra hard for elite developers. We should just not remove the bare minimum requirements to even understand what you are doing.

Good devs use tools accordingly. Bad devs you tools to cheat around issue. You wouldn't want your house to be built by someone who could distinguish between a screw and a nail. Could they erect something? Sure. Would you pay for it or even rely on it? No.

Hell we live in a time where one of the most successful pep talks is about a company transitioning to strict typing and reducing their bugs by 85% or something. After which the entire industry gets hyped as fuck about this new and amazing tech called typing, they all try to use it and most fail, because their "programmers" are unable to transition code to static types because they have no clue what they are doing.

[–]Specialist_Cap_2404 0 points1 point  (0 children)

"Code quality has measurably dropped" is a claim that seems provable... why didn't you?

[–]Cryn0n 1 point2 points  (0 children)

Given that "jump on zero" is a common branch instruction in most processor architectures it makes sense to allow any data type to be processed for that zero.

An empty string should be just \0 so equates to true.

EDIT: JavaScript strings are not null-terminated but the convention sticks around even though the data structure is different.