Readit News logoReadit News
ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
rurban · 2 days ago
I am talking about gradual typing here. Types are optional, if not given or implied they default to any. No need to annotate anything. If given they are enforced, and lead to optimized op codes and errors if violated. Some at compile-time, some at run-time. If fully typed, all errors are caught at compile-time already.

Duck typing as done with python is the worst of both worlds. No optimizations, no enforcement. Just optional external typechecks.

Of course untyped code (ie runtime types in each var) is to write faster. You only need to add types to some vars or args, and gradually improve from there. Eg ints only, because they are optimized the easiest. No need to check for strings, bigint, floats,.... Or arrays to check for overflows at compile-time and restrict to ints or strings. Massive improvements possible, in size and runtime.

Or object fields. Hash lookups vs static offsets.

ReflectedImage · 2 days ago
If JITs hadn't been invented you would be completely right but JITs have been invented.

There are deeper optimizations that JITs can do such as knowing at runtime that the value of a variable is always 2 that typing information simply can't express.

Duck typed Python is optimal for development speeds, the only thing that matters in startup environments. It has it's niche.

You aren't gradually improving, you are gradually deteriorating the codebase to make it look more familar to you.

ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
rurban · 3 days ago
Because the anti-types crew showed up and sabotaged it. Similar with perl and lua.

But languages with stronger and more intelligent leadership showed what's possible.

You cannot implement all the compiler optimizations for const and types in extensions. You need to fork it.

ReflectedImage · 2 days ago
The problem is there are a lot of developers who have only coded with static typing and have no idea about the terrible drawbacks of static typing.

They don't understand what static typing does to code verbosity and development times.

Take Turborepo going from Go's typing light system (designed to emulate duck typing) to Rust's heavy typing system (true static typing). Originally the code was 20,000 lines and was coded by 1 developer in 3 months. When moved into the typing style you like so much, the same code is now 80,000 lines and was coded by a team of developers in 14 months.

ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
rurban · 4 days ago
Nonsense. You get the simplification and faster development times of knowing some variable types statically, plus the performance improvements for the compiler which can move the type checks from runtime to compile-time. Plus all the new optimization possibilities.

Common Lisp showed you the way. But almost none looked at it. Only PHP did.

ReflectedImage · 2 days ago
Absolutely not. Duck type based development results in working code out of the door 3x faster than static type based development. It always has since ancient times.

If performance wasn't an issue, then the static type based developers would all be fired. Either directly or by the businesses who relied on them getting driven into bankruptcy by their competitors. You would still get some niche jobs in it where they like to do formal verification of the code.

Your problem is just that your development skills from static type based development don't transfer to duck type based development. Different style of codebases needs to be handed completely differently.

ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
jaapz · 3 days ago
Have you actually used this in a real codebase? Because it is the opposite of my experience in gradually adding types to a large python codebase. There's no extra complexity or slower development. It's not like you need to suddenly move to a different coding paradigm with FactoryBeanFactoryBeans... You just keep writing python like you did, but add types here and there to help clarify things and make your LSP (like ty) work better.

If anything, it speeds up development. Plus it helps give more confidence in the correctness of your code.

ReflectedImage · 2 days ago
Yep, the software development slows down to crawl. Yes, you can still code at the same speed as you were coding in a language like Java or C# but that is considerably slower then what's possible in languages like Ruby and Python.

To give you a roughly idea, you should always expect a 3x slow down when using static typing.

An recent example is Turborepo that went from basic types in Go to proper static typing in Rust. Just adding in the proper typing caused the codebase to grow from 20,000 lines to 80,000 lines and from 3 developer months to 14 developer months.

The stronger your typing system, the slower you will develop code. Whether you realise it or not.

ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
blandflakes · 2 days ago
> Static typing doesn't have much value if there are proper unit tests

Wasteful unit tests that assert your types are right don't have much value if there is a proper type system.

> It's called ratting yourself out.

Quit being childish.

ReflectedImage · 2 days ago
"Wasteful unit tests that assert your types are right"

You don't test whether the types are right, you test if your code actually does the right thing. That's what's important to your customers.

The types getting tested is incidental.

ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
blandflakes · 3 days ago
This always feels like a bad faith argument. Nobody says that with static types, you don't need any unit tests.

And your suggestion that people who like static types "don't know how to write unit tests" is further bad faith.

Perhaps it's dynamic typing programmers who don't know how to write sound programs? Except I'm not making that claim, because I'm giving you all some benefit of the doubt, a degree of respect you are not giving others.

ReflectedImage · 2 days ago
Static typing doesn't have much value if there are proper unit tests. So it's fairly obvious that if people think there is value in static typing then they are shipping broken code to their customers.

It's called ratting yourself out.

ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
blandflakes · 3 days ago
Elsewhere in this thread, dynamic typing advocates malign the hassle of maintaining types, and it is always coupled with strong advocacy for an entire class of unit tests I don't have to write in statically typed languages.
ReflectedImage · 3 days ago
And that's the problem, if you want your code to actually work you do need to write those unit tests. A program not crashing doesn't mean it does the right thing.

With experience you will learn to either write unit tests or spend the same amount of time doing manual testing.

Once you start doing that then the unit tests just replace the static typing and you start shipping better code to your customers.

ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
t-writescode · 4 days ago
Nah. 99.9% of the people who wanted the addition of DryStructs to a codebase I worked on wanted it because they'd been bit, repeatedly, by someone sending one kind of object into a function rather than what the function accepted and it just not getting caught.

A robust type system allows you to make "compiler errors" out of runtime errors. One of these takes *way more tests to catch* than the other. I'll let you guess which.

ReflectedImage · 4 days ago
Nah that's just a lack of understanding in the role of unit tests in dynamically typed languages.
ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
matteotom · 4 days ago
At least for Python (since I'm more familiar with Python code and the Python ecosystem): progressive typing lets you incrementally add typing to an existing Python codebase. So you can have at least some of the benefits of typing for new or updated code without needing to re-write in a new language.
ReflectedImage · 4 days ago
Gradual typing is the worse of both worlds.

You get the complexity and slower development times of using statically typed languages along with the bad performance of using dynamically typed languages.

ReflectedImage commented on T-Ruby is Ruby with syntax for types   type-ruby.github.io/... · Posted by u/thunderbong
pie_flavor · 4 days ago
This is junk. Writing a type annotation takes basically zero time, then saves you time by preventing the runtime error because you forgot which variable was which, then saves you more time by autocompleting the correct list of valid methods when you hit dot.

Acting like Go is comparable to JS is ridiculous; Go's type system is the only kind of type system needed in Ruby. Rust is a staggering outlier in complexity. And the Turborepo port took a long time specifically because they tried to port one module at a time with C interop between the old and new codebases, which massively slows down development in any language, especially Go. This is just about the most dishonest 'example' you could have picked.

Either that or you are saying 'weakly typed' to mean type inference in `var := value`, in which case (a) Rust has that too and (b) that's not what the debate is about, nobody is against that

ReflectedImage · 4 days ago
Making the type annotations pass restricts you to writing more bloated and verbose programs in general.

Stating that A is an integer isn't much of a issue but once you get a reasonably complex program and A now has a compound type made of 5 parts, it really does slow you down and it really does make you write considerably worse programs for the sake of passing a type checker.

Any commercial code will need to be unit tested so there is no time saving from finding runtime errors earlier and an any good IDE will detect the same errors and provide you with the same auto complete automatically for free without any type annotations at all. These are problems which exist solely in your head.

1 developer vs a whole team of developers. I think you need to face the facts.

There are studies comparing old dynamically types languages against statically type languages. They always show approximately 1/3 of the lines of code being used with 3x faster development times in the dynamically types languages. This isn't some new discovery.

Well even Python is strongly typed but for the sake of this we are discussing type complexity.

u/ReflectedImage

KarmaCake day405May 12, 2020View Original