News for hackers. Stuff that matters.
Re:Ask HN: Why Did Python Win? by KptMarchewa on Tuesday August 29, 2023 @07:56PM (#37315807)
> Python has a default None return, Ruby returns the value of the last expression.

I would really hate this feature in a language without strong static typing.

Re:Ask HN: Why Did Python Win? by randomdata on Tuesday August 29, 2023 @10:51PM (#37317086)
Doesn’t seem like that big of a deal. You’re going to have a really hard time getting your first test to pass if you make a mistake.

I don’t mean using testing as a poor man’s type system, I mean even the tests you would write in a statically typed language will quickly uncover any mistakes you could possibly make there.

Re:Ask HN: Why Did Python Win? by KptMarchewa on Wednesday August 30, 2023 @09:21AM (#37321721)
In statically typed systems, this wouldn't even compile.

I'm pretty sure I'd see multiple cases where the function would return different types depending on a code path.

Re:Ask HN: Why Did Python Win? by dragonwriter on Wednesday August 30, 2023 @12:22PM (#37324383)
> I'm pretty sure I'd see multiple cases where the function would return different types depending on a code path.

Quite commonly by design, or, “why union (and sum) types are a thing”.

Something returning type “Foo | nil” is very often going to return Foo on one branch and nil on another.

Re:Ask HN: Why Did Python Win? by randomdata on Thursday August 31, 2023 @08:55AM (#37336424)
> In statically typed systems, this wouldn't even compile.

Still, it's not like you're going to miss that a function doesn't return something expected. Even in statically typed languages you are going to have tests to validate that much.

> I'm pretty sure I'd see multiple cases where the function would return different types depending on a code path.

That's another problem entirely. Although even then it would be pretty hard for an errant type to not blow up your tests. Again, not tests specifically meant to check that your types or sane, just the same tests you would write in a statically typed language.