News for hackers. Stuff that matters.
Re:What the Fuck Python by alabhyajindal on Saturday July 19, 2025 @04:09PM (#44618910)
Preach. We need more Python slander. It annoys me to no end when people trash JavaScript as if it was some exception in bad language design. Most languages have something bad that can be picked up and trashed on - some more than others.
Re:What the Fuck Python by heavenlyblue on Saturday July 19, 2025 @04:12PM (#44618937)
Given that it starts with a thing called "id" which is an implementation detail and probably should not be used for equality, it seems like this is a geniuinely well designed language :)
Re:What the Fuck Python by mirashii on Saturday July 19, 2025 @04:15PM (#44618960)
id is not an implementation detail, it's a core built-in function of the language. The value that it returns is an implementation detail, but the properties of the value it returns are not and perfectly valid to rely on.
Re:What the Fuck Python by 0xDEAFBEAD on Sunday July 20, 2025 @03:08AM (#44622668)
The "properties of the value it returns" are, by design, implementation-dependent. You're only supposed to use the id function if you need to know something about what's going on under the hood. The id function is working exactly as intended: it's exposing aspects of the implementation, if for some reason you need to know that stuff.

It would not be a positive change to sacrifice Python performance in order to make the output of id() more intuitive. I've spent many hundreds of hours coding Python and I don't believe I ever used that function or saw someone else use it.

Re:What the Fuck Python by zahlman on Saturday July 19, 2025 @05:05PM (#44619400)
`id()` is documented and mandated to exist, and the result provides guarantees that make it suitable for identity (not equality) checks[1] (although of course you should normally use the `is` operator). Pitfalls involving it are generally really pitfalls with understanding object lifetimes[2].

[1]: https://docs.python.org/3/library/functions.html#id

[2]: see e.g. https://stackoverflow.com/questions/52096582

Re:What the Fuck Python by bnchrch on Saturday July 19, 2025 @04:46PM (#44619221)
Thank you! For years Ive been saying the sheer volume and fury by which Javascript is criticized is much more applicable to Python.

Both aren't perfect languages, and both are far from "the best" but it is maddening that Python get often picked as a darling when its implementation, ecosystem and tooling are fundamentally at odds with correctness and productivity.

Re:What the Fuck Python by verbify on Saturday July 19, 2025 @05:00PM (#44619355)
I think people pick on js more because it's the only option for scripting frontend for the web, while if you don't like python there's probably another language that can be used instead.
Re:What the Fuck Python by dreamcompiler on Saturday July 19, 2025 @05:49PM (#44619753)
Unless you're doing AI, in which case you're royally screwed.
Re:What the Fuck Python by orhmeh09 on Saturday July 19, 2025 @08:29PM (#44620787)
You can get by with R and reticulate.
Re:What the Fuck Python by mmasu on Sunday July 20, 2025 @01:06AM (#44622142)
the Python ecosystem for AI is far ahead than R, sadly (or not :-) )
Re:What the Fuck Python by orhmeh09 on Sunday July 20, 2025 @03:12AM (#44622686)
Reticulate is a bridge that lets you use Python from R so that you don't have to suffer Python the language.
Re:What the Fuck Python by socalgal2 on Sunday July 20, 2025 @02:18AM (#44622450)
I'd say people pick on JS because they don't learn it. They jump in, use it like python or C++, get frustrated it's not the same as what they're used to, vow to use it as little as possible. This was especially true before es5/es6 with var function scope and no class syntax.
Re:What the Fuck Python by 0xDEAFBEAD on Sunday July 20, 2025 @03:17AM (#44622707)
The author of this notebook does not appear to agree with you. They describe Python in the beginning as "beautifully designed".

This is not idiomatic Python code. It's code designed to demonstrate Python performance optimizations, through use of relatively obscure Python functionality which exposes details of the internals in situations where you need that.

"its implementation, ecosystem and tooling are fundamentally at odds with correctness and productivity"

You'll need a lot more than just this notebook to argue for that position.

Re:What the Fuck Python by moffkalast on Saturday July 19, 2025 @05:06PM (#44619403)
Yeah python deserves a good bashing as well, it's about as bad as JS in this regard. I mean for bool("false") resolves to True ffs.
Re:What the Fuck Python by 3eb7988a1663 on Saturday July 19, 2025 @05:18PM (#44619501)
That is entirely consistent with how truthiness works in Python. The function does not claim to parse strings, that is how you get YAML Norway.

Do you think there should be different results for bool("no"), bool("false"), bool("heckno!"), bool("heckyes!")?

Edit: should have included internationalization: bool("nein!")

Re:What the Fuck Python by crazygringo on Saturday July 19, 2025 @05:31PM (#44619617)
> The function does not claim to parse strings

But it's entirely reasonable to think it would. I honestly don't understand why it wouldn't, because:

  >>> int("35")
  35
  >>> float("3.5")
  3.5
  >>> bool("False")
  True
If casting from a string to a type works with ints and floats, why not with bools? What possible justification is there?

And of course it doesn't need to work for "no" or "heckno!", that's silly. But it sure seems like it ought to work on whatever the official string representation is. And not produce:

  >>> bool(str(False))
  True
I'd honestly much prefer bool() threw an exception on receiving a string, rather than act the way it does now.
Re:What the Fuck Python by jonathrg on Saturday July 19, 2025 @08:16PM (#44620720)
> If casting from a string to a type works with ints and floats, why not with bools? What possible justification is there?

There's no type casting in Python. int(), float() and bool() just create objects of their respective types, passing the arguments to the initializer. They are not fundamentally different from, say, PostgresqlDriver() in this regard.

Different classes will provide different ways to construct objects depending on what is most useful. For int and float, the most useful thing to do when receiving a string is to parse it; for bool, the most useful thing to do is to check its truthiness; for PostgresqlDriver, the most useful thing to do is to interpret it as a database URL and connect to it.

Re:What the Fuck Python by crazygringo on Saturday July 19, 2025 @08:58PM (#44620951)
> There's no type casting in Python.

If you search "type casting in Python" you will find lots of articles explaining how to use int(), str(), etc. to cast. This is a common and well-documented concept, even if it's different under the hood from e.g. C.

The idea that you'd name a function bool() and have it act differently is a deeply confusing design decision that it's understandable people would get misled by and frustrated with. This is a function named after a fundamental type. It's not a random user-defined constructor.

Re:What the Fuck Python by bb88 on Saturday July 19, 2025 @09:59PM (#44621255)
If we do it that way, we have worse problems.

    if "False":  
       # What do you expect?  True or False?  
       print("True")
    else:
       print("False")
bool() is consistent with how "truthiness" happens in python. Otherwise we end up with the YAML norway problem.

    if bool("False"):
       print("True")
    else:
       print("False")  # This would be different if we landed here.
And that would be different behavior then the above -- creating a nasty inconsistency.

Honestly it's not that hard to write something that looks like this:

    def str_to_bool(val: str) -> bool:
        return val.lower() in ["yes", "true", "1"]
Re:What the Fuck Python by jonathrg on Sunday July 20, 2025 @06:53AM (#44623875)
bool() is not a function named after a fundamental type. bool is a type. As with any type, you can call bool(...) to construct a new object of that type.

https://docs.python.org/3/library/functions.html#bool

A good tutorial will reflect this fact and use appropriate language.

Both the idea that you can "cast", and the idea that bool is a function, are misunderstandings rooted in the idea that Python should be like C in all ways.

Re:What the Fuck Python by tmh88j on Saturday July 19, 2025 @09:22PM (#44621057)
> There's no type casting in Python. int(), float() and bool() just create objects of their respective types, passing the arguments to the initializer

int() and float() behave like type casting, bool() does not. It's a truthiness check that would be more aptly named istruthy(). In python non-empty strings are truthy, so providing any string except for "" to bool() will return True, including "False".

Re:What the Fuck Python by shakna on Saturday July 19, 2025 @09:38PM (#44621146)
It's not casting.

    (char*)21 != "21"
Casting is converting the container, the interpretation.

What you're reaching for is type conversion. Some languages have "implicit conversion" when casting, but the word itself doesn't require it.

Re:What the Fuck Python by kazinator on Saturday July 19, 2025 @10:13PM (#44621341)
In C, cast converts a value to another type (or a more or less qualified version of the same type). What that conversion means depends on the source and destination type.

A cast of insert a conversion that wouldn't take place:

  1/2 vs 1/(double)2
or coerce a conversion that otherwise requires a diagnostic:

  bar *b = 0;
  foo *f = (foo *) b;
Loosely speaking, casting is another name for coercion, which refers to making a conversion happen that might not otherwise.
Re:What the Fuck Python by shakna on Saturday July 19, 2025 @10:51PM (#44621572)
Implicit conversion, which is what you're mostly referring to here, is not required. It happens in some languages, and not others.

Because I'm tired, and this is a very basic topic, I'm afraid I'm just going to rip from Wikipedia:

> In most ALGOL-like languages, such as Pascal, Modula-2, Ada and Delphi, conversion and casting are distinctly different concepts. In these languages, conversion refers to either implicitly or explicitly changing a value from one data type storage format to another, e.g. a 16-bit integer to a 32-bit integer. The storage needs may change as a result of the conversion, including a possible loss of precision or truncation. The word cast, on the other hand, refers to explicitly changing the interpretation of the bit pattern representing a value from one type to another. For example, 32 contiguous bits may be treated as an array of 32 Booleans, a 4-byte string, an unsigned 32-bit integer or an IEEE single precision floating point value. Because the stored bits are never changed, the programmer must know low level details such as representation format, byte order, and alignment needs, to meaningfully cast.

> In the C family of languages and ALGOL 68, the word cast typically refers to an explicit type conversion (as opposed to an implicit conversion), causing some ambiguity about whether this is a re-interpretation of a bit-pattern or a real data representation conversion. More important is the multitude of ways and rules that apply to what data type (or class) is located by a pointer and how a pointer may be adjusted by the compiler in cases like object (class) inheritance.

Re:What the Fuck Python by kazinator on Sunday July 20, 2025 @12:45PM (#44626889)
The difference between implicit conversion and explicit is just syntactic sugar: do you have to put some visible tokens into the code to allow a conversion to happen, or not.

Implicit conversion can be seen as the compiler deciding among several possible conversions (or possibly just one) and inserting the coercion/casting operator into the intermediate code to make it happen.

(Of course, this can be a run-time decision based on dynamic types also, but the reasoning is the same. E.g. the run-time sees that a plus operation is adding an integer and float, and can either signal an error (requiring the program to be repaired by inserting a conversion operation into the expression), or just do that conversion, like the integer operand to float.

Re:What the Fuck Python by shakna on Sunday July 20, 2025 @04:49PM (#44629185)
I really wouldn't call something you need to write, to make something happen, "syntactic sugar".

Otherwise types are just sugar. Indicies are just sugar. Lists are just sugar.

Re:What the Fuck Python by fc417fc802 on Friday July 25, 2025 @03:40PM (#44687446)
It's the other way around. Implicit conversion is syntactic sugar for explicit conversion. Sugar is anything that is functionally identical, just notated more conveniently.

That said, I think you're correct about the casting versus conversion distinction. Languages frequently overload established terminology with slightly modified variants and it's incredibly confusing.

Re:What the Fuck Python by tmh88j on Saturday July 19, 2025 @09:49PM (#44621193)
Yep, that's why I said "behaves like".
Re:What the Fuck Python by tmh88j on Saturday July 19, 2025 @07:23PM (#44620428)
> If casting from a string to a type works with ints and floats, why not with bools? What possible justification is there?

> I'd honestly much prefer bool() threw an exception on receiving a string, rather than act the way it does now.

They serve fundamentally different purposes. bool() is a truthiness check and not a type cast like int() and float(). It seems like a lot of people take issue with the name, because it was called something like istruthy() the discussion about it wouldn't be happening.

Re:What the Fuck Python by akoboldfrying on Saturday July 19, 2025 @07:48PM (#44620568)
> bool() is a truthiness check and not a type cast like int() and float(). It seems like your issue is with the name of the function, because if it was more aptly named to something like istruthy() this discussion wouldn't be happening.

Right, the bug is in the inconsistent naming.

It's roughly as bad as having arithmetic operators named +, -, *, / that perform arithmetic as usually understood, except that + actually performs XOR and is documented to do so.

Re:What the Fuck Python by tmh88j on Saturday July 19, 2025 @07:51PM (#44620592)
> Right, the bug is in the inconsistent naming.

The comment I responded to didn't seem to realize that because they asked why it behaves the way it does, so I explained.

Re:What the Fuck Python by 3eb7988a1663 on Saturday July 19, 2025 @05:49PM (#44619750)

  prefer bool() threw an exception on receiving a string, rather than act the way it does now.
That breaks the truthiness cornerstone of the language. You can write

  a = 1 # or [], (), "yo", "false", 3.2, MyFooClass(), (1,), False
  if a:
    fire_ze_missles()
  else:
    declare_peace()
Upon encountering `a`, Python is evaluating bool(a). If that no longer works for strings, you now need a separate code path for determining a non-empty string.

It can short-circuit the brain upon reading a word that you know means false, but the Python rules are consistent. "Empty" is False, everything else is True.

Re:What the Fuck Python by moffkalast on Saturday July 19, 2025 @05:52PM (#44619768)
You can write that yes, but I'm calling the police.
Re:What the Fuck Python by jonathrg on Saturday July 19, 2025 @08:00PM (#44620635)
You can't go calling the police on people for writing idiomatic Python code.
Re:What the Fuck Python by Jtsummers on Saturday July 19, 2025 @07:34PM (#44620486)
> I'd honestly much prefer bool() threw an exception on receiving a string, rather than act the way it does now.

`bool` would have no value if it threw an error in this case because if strings can't be passed to it, then no other type would sensibly work either. It would basically just become `bool(False) -> False` and `bool(True) -> True`.

Re:What the Fuck Python by crazygringo on Saturday July 19, 2025 @08:53PM (#44620928)
> because if strings can't be passed to it, then no other type would sensibly work either

It's pretty standard to convert integers to bools, where 0 becomes False and everything else becomes True. That is absolutely sensible and useful current behavior.

Re:What the Fuck Python by Jtsummers on Saturday July 19, 2025 @08:53PM (#44620931)
Right. Zero-values become False (empty set, empty string, 0, etc.) and non-zero-values become True. So we agree bool is consistent then.
Re:What the Fuck Python by crazygringo on Sunday July 20, 2025 @11:06AM (#44625881)
Nope, because str(False) produces "False", not "".

Not consistent at all.

There's nothing consistent about bool(str(False)) == True.

It's standard in computing for zero integers to represent False. Heck, bool is a subclass of int. Extending that to the length of strings is where things start to go off the rails in terms of consistency... and why you would ever even want that is beyond me.

Re:What the Fuck Python by 3eb7988a1663 on Sunday July 20, 2025 @03:46PM (#44628661)
Sounds like your complaint is with str() and not bool().

Which becomes a different issue - what do you think str(True) and str(False) should produce. Integer representations? That then makes other things unintuitive with changing the form of a boolean.

  print(0, 1, False, True)
  # today: 0 1 False True 
  # as ints: 0 1 0 1
  # new str: 0 1 "True" ""
Re:What the Fuck Python by crazygringo on Sunday July 20, 2025 @05:47PM (#44629622)
No, my problem is with bool().

str(False) == 'False' is entirely logical.

So therefore bool('False') == False would be consistent.

And bool('foo') would produce an exception the exact same way int('foo') and float('foo') already do.

Who on earth thought it was a good idea that 'foo' could or should be interpreted as a boolean...?? The entire concept of 'truthiness' outside of ints is unhelpful. It's just asking for bugs. That the length of a string, rather than its content, should determine a boolean value is one of the more bizarre things I've come across in programming languages. Use len() if you want that. It's only 5 extra characters.

Re:What the Fuck Python by moffkalast on Saturday July 19, 2025 @05:24PM (#44619557)
Honestly once you really think about it just about nothing about these decisions ever makes any real sense which is why JS is made fun of constantly. It's nonsense functions running on nonsense data. "if some_non_bool_value:" should not be valid syntax and truthy and falsy is a concept that would get you locked up in an asylum if you decided to explain it to a doctor.
Re:What the Fuck Python by bnchrch on Saturday July 19, 2025 @05:16PM (#44619494)
Don't forget its transitive dependencies creating non-deterministic builds
Re:What the Fuck Python by librasteve on Saturday July 19, 2025 @06:42PM (#44620107)
yeah

in raku, i checked

  say False.so; #False
Re:What the Fuck Python by Jtsummers on Saturday July 19, 2025 @06:53PM (#44620194)
If I understand raku correctly, the Python example would be more like this:

  say "False".Bool
or:

  say "False".so
Both of which display True.

Leaving out the quotes means you're testing something else entirely.

Note that the Python example is converting (via `bool`) a string with the text "false" (which would make more sense as "False" which is the actual name of `False` in Python) into a boolean value. It's consistent with how Python behaves, in that the empty string (like in Raku from what I can tell) is false-y and non-empty strings are truth-y. It would be weird to have this use the else branch:

  if bool("False"):
    ...
  else:
    ...
But not this:

  if "False":
    ...
  else:
    ...
Re:What the Fuck Python by gpderetta on Saturday July 19, 2025 @07:19PM (#44620402)
As mentioned else thread, the problem is not so much that book("false") evaluates to true, which is consistent with a lot of the language, but that int("1") evaluates to 1.

Generally python is much better than some other dynamic languages in avoiding stringly typed confusion, but the convenience of the int from string constructor set expectations that the rest of the language can't sanely meet.

String to type construction should have been relegated to a dedicated syntax in all cases.

Re:What the Fuck Python by librasteve on Sunday July 20, 2025 @02:17AM (#44622445)
thanks for the correction
Re:What the Fuck Python by motorest on Saturday July 19, 2025 @05:23PM (#44619541)
> We need more Python slander. It annoys me to no end when people trash JavaScript as if it was some exception in bad language design.

Python's file system support across platforms is notoriously problematic or even outright broken. Wasn't this enough reason to put it lower in the quality bar than JavaScript?

Re:What the Fuck Python by akdor1154 on Saturday July 19, 2025 @11:12PM (#44621665)
JavaScript doesn’t even have file system support.. each runtime has its own tacked on implementation in the relevant “standard” library. Now which is notoriously problematic?
Re:What the Fuck Python by motorest on Sunday July 20, 2025 @07:29AM (#44624131)
> JavaScript doesn’t even have file system support..

https://nodejs.org/api/fs.html

Re:What the Fuck Python by wormius on Sunday July 20, 2025 @03:06PM (#44628296)
node is a js runtime, not the official spec, you make no point in refuting the above.
Re:What the Fuck Python by fragmede on Saturday July 19, 2025 @05:30PM (#44619613)
Re:What the Fuck Python by bb88 on Saturday July 19, 2025 @09:45PM (#44621178)
I came here to say that. That was an eye opening intro to Javascript for me.
Re:What the Fuck Python by throwaway314155 on Saturday July 19, 2025 @06:07PM (#44619873)
JavaScript is far more jarring than Python depending on your background. They do both have issues of course, but that's the reason JavaScript gets "picked on" more.
Re:What the Fuck Python by bb88 on Saturday July 19, 2025 @10:09PM (#44621315)
How does this attract more people to hackernews who come from the python world? If anything, it just shows how toxic people can be on this site.
Re:What the Fuck Python by hamstergene on Saturday July 19, 2025 @11:01PM (#44621610)
There could be generational gap here: for many people the first JS was ES5 or later, which is after the language was taken seriously and fixed. The difference between Python2 and ES1-ES3 was much bigger than between modern Python and modern JavaScript, so some protest against old bad fame is understandable.

But, if you have any suspicion that JavaScript has been treated unfairly: it hasn't. It is literally being replaced by TypeScript as we speak. The fact you have to invite people to come up with more Python slander is itself a testimony, JavaScript has never needed an invitation. Having lot more issues than others is what being exception means, and JavaScript is one.