News for hackers. Stuff that matters.
Re:Cold Showers by jacobsenscott on Saturday June 18, 2022 @06:46PM (#31794485)
It is not evident to me. Having used both statically typed and dynamically typed languages my experience is that I can't remember ever seeing a bug in our fairly large rails app that a type system would catch. Nobody's passing strings where hashes are expected, or Widget instances where User instances are expected. The thing to pass to the function is nearly always self evident. If you did it would immediately be caught when a test runs anyway.

However, refactoring code in C# is much easier than refactoring ruby because you can lean on the type system there. However writing new code in C# is often much harder to do in C# because of the constraints of the type system. So really, it ends up being a wash for me.

Re:Cold Showers by devit on Saturday June 18, 2022 @07:02PM (#31794594)
Even trivial things like a typo in the method name in a method call are not detected at compile time by languages like JavaScript or Ruby (since their "method calls" are in fact just lookups in a runtime hash table...).

If you have not seen them, the reason is probably that the code was tested well enough before you looked for the bugs.

Re:Cold Showers by imiric on Saturday June 18, 2022 @06:52PM (#31794526)
> If you did it would immediately be caught when a test runs anyway.

That's the point though. With dynamic typing you would only (hopefully) catch this with manually written tests. With static typing you get that feedback for free at build time.

Re:Cold Showers by tene on Sunday June 19, 2022 @02:38AM (#31796759)
With static types, every function signature implicitly comes with built-in tests for free.
Re:Cold Showers by jacobsenscott on Monday June 20, 2022 @12:45AM (#31806381)
Not true because anyone can implement just part of an interface and throw "method undefined" for the methods they can't figure out how to implement. This happens all the time.
Re:Cold Showers by KptMarchewa on Monday June 20, 2022 @07:16AM (#31808924)
> Not true because anyone can implement just part of an interface and throw "method undefined" for the methods they can't figure out how to implement. This happens all the time.

How would that pass any code review, regardless of static or dynamic typing?

Re:Cold Showers by tene on Monday June 20, 2022 @02:03PM (#31813477)
The only time I have ever seen something like this is using `todo!()` while initially writing code. I have never seen someone check in code like this.

What kind of clown show of a programming org are you working at?

This is morally equivalent to "There's no point to having a safety on a gun, because the safety won't stop you from bashing someone in the face with the gun." If you really want to, you can throw exceptions or crash the process or call exit() or call system("shutdown -h now") anywhere in your codebase. That has nothing to do with a type system.

Re:Cold Showers by KptMarchewa on Monday June 20, 2022 @07:15AM (#31808917)
Even faster, at "type time" if you use any decent IDE.
Re:Cold Showers by unethical_ban on Saturday June 18, 2022 @06:52PM (#31794523)
>Nobody's passing strings where hashes are expected

See, When I'm throwing together apps to clean up configurations, I am Pythonifying XML often. And when handling different return values, reshaping it into the useful components I need and trying to analyze data (and dealing with different return formats depending on number of results, aka a dict if there is one value, or a list(dict) if there are more) I have to constantly remember if I am going to be getting a list(dict(dict(dict(str)))) or just a dict(dict(string)), and so on. But that's me cobbling together scripts and not understanding the API by heart well enough.

Re:Cold Showers by tene on Sunday June 19, 2022 @02:36AM (#31796751)
Have you ever had crashes caused by unexpected use of nil/null/undefined? Using the return value from a function without checking for errors?
Re:Cold Showers by semiquaver on Saturday June 18, 2022 @08:54PM (#31795184)
If you search your exception tracker for NoMethodError in production, do any results come up?
Re:Cold Showers by jacobsenscott on Sunday June 19, 2022 @12:15AM (#31796113)
Yes - in every case it is calling a method on a null reference. And no commonly used statically typed language helps here because they all allow null references. And languages that disallow nulls, if you are one of the 10 programmers on earth working in one of those languages, don't help you because you are dealing with real world data where inputs to your system can be null or not so you end up using some type system escape hatch anyway.
Re:Cold Showers by tene on Sunday June 19, 2022 @03:31AM (#31797083)
> no commonly used statically typed language helps here because they all allow null references

This is false.

TypeScript, Swift, and Rust are commonly used and support non-nullable references.

> those languages, don't help you because you are dealing with real world data where inputs to your system can be null or not so you end up using some type system escape hatch anyway.

You don't need escape hatches to deal with "real world data" that may be missing some values. This blog post is my favorite detailed comparison of handling "real world data" in static vs dynamic languages: https://lexi-lambda.github.io/blog/2020/01/19/no-dynamic-typ...

Rust's serde_json docs on "Operating on untyped JSON values" are also a pretty good description of working with "real world data" where you want to examine an arbitrary document: https://docs.serde.rs/serde_json/#operating-on-untyped-json-...

The only requirement for working with "real world data" in a static non-nullable language is to choose whatever kind of behaviour you want when working with the data. Everything you can do with null references, you can do better with option types; there is nothing that null references uniquely permit.

Re:Cold Showers by jacobsenscott on Monday June 20, 2022 @12:50AM (#31806404)
Typescript, swift, and certainly rust are not common languages by any stretch of the imagination. https://www.tiobe.com/tiobe-index/
Re:Cold Showers by semiquaver on Monday June 20, 2022 @02:11AM (#31806850)
If you really think TIOBE is a reasonable way to gauge dev mindshare, fine.

1. Python with mypy has `strict_optional`. On by default.

2. C, being “portable assembler” is not really statically typed.

3. Java has had Optional for years, although it’s not the most pleasant to work with it does exist. And JVM languages like Kotlin go well beyond this.

4. C++ has `not_null`.

5. C# supports type-system enforced non-nullable types since 8.0.

You said:

> languages that disallow nulls, if you are one of the 10 programmers on earth working in one of those languages

I hope it’s clear that you are simply incorrect. There are plenty of tools to eliminate nullable references in modern mainstream languages.

Re:Cold Showers by gpderetta on Monday June 20, 2022 @10:39AM (#31810891)
> 4. C++ has `not_null`.

Most importantly in C++ only pointers can be null. You can return value types that are not nullable.

Re:Cold Showers by tene on Monday June 20, 2022 @12:23PM (#31812197)
Dunno what to tell you dude; my imagination stretches there just fine. Maybe consider going to imaginary yoga class.

There have been people writing at least two of those languages everywhere I've worked for a while. Most of my professional colleagues can write at least one of these comfortably. I'm extremely confident in being able to hire programmers for all of these. They're all in use at every major tech company.

If you really want to stick your head in the sand and cry about how nothing can be better until they're literally top of the charts, I can't stop you, but they're certainly not rare. There's good stuff out there. Lots of people are using it. You can too.

If you'd rather trade links to charts, I trust Stack Overflow's developer survey's methodology a lot more than TIOBE's. 30% of respondents said they've worked with TypeScript, and that jumps to 36% in the professional developer subset. Rust is 7%/6%. That's a hell of a lot more than 10 developers.

https://insights.stackoverflow.com/survey/2021#technology-mo...

They also got 15% of developers who aren't using TypeScript want to use it, and 14% for Rust:

https://insights.stackoverflow.com/survey/2021#most-loved-dr...

My country has about 15% black people about about 7% asian people. My country has about 4% LGBT people, and my city has about 15% LGBT. It would be really weird to hear someone say that black, asian, and LGBT people are not common, especially after knowing and working with plenty of them.

Re:Cold Showers by ylyn on Sunday June 19, 2022 @01:19AM (#31796351)
> don't help you because you are dealing with real world data where inputs to your system can be null or not so you end up using some type system escape hatch anyway.

You clearly have little experience with such languages, then.

Re:Cold Showers by Too on Sunday June 19, 2022 @03:16AM (#31796999)
Python (with mypy) has strict optional on as default and is the most widely used language, according to the latest stackoverflow ranking. Assuming you use mypy of course, which probably takes the usage rate down a factor of 100x but still.. ;)

It makes you actually have to consider scenarios where a variable can be none or not and try to push the validation up closer to where it entered the system.