News for hackers. Stuff that matters.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tptacek on Thursday June 20, 2019 @05:44PM (#20237705)
For whatever it's worth and without wanting to start a language war (I like Python just fine), I think Python/Ruby-style typing is a false economy for prototyping. There are a lot of things that make Go slower to write than Ruby, but mandatory typing isn't one of them. Rather, Ruby's total lack of typing makes it harder to write: you effectively end up having to write unit tests just to catch typos.

I wonder whether the perception that type safety slows down Ruby (or ES6) development comes from the fact that the type systems are bolted on after the fact.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by pcr910303 on Thursday June 20, 2019 @08:46PM (#20238907)
I would say that dynamically-typed languages are great to prototype as they do not emphasize on being correct too much.

Being correct from day one will cause too much unnecessary friction. You (usually) don't know the entire program architecture until you make a full prototype, and even if you have a plan, there will always be some part where some unexpected consequences force you to rearchitect some parts. And since you don't know the entire program architecture you architect your program bottom-up, and most of the dynamically-typed languages allow an interactive development environment at a flexibility that typed languages can't provide.

Think about developing Python inside a Jupyter notebook, or Common Lisp inside a REPL. You turn on a REPL, open up a file, write a function, send the function to the REPL, test the function you just wrote, and when I find a mistake I can just redefine any function I would like to change. This process allows fixing mistakes on-the-fly. Typed languages don't allow this (even ones that have a so-called REPL) at this flexibility, (since they emphasize on being correct all the time), and cause too much unnecessary friction while prototyping.

Thus a need for a dynamically-typed language that can enforce types after prototyping.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jonnytran on Friday June 21, 2019 @02:24AM (#20240316)
Yes, it's this flexibility that allows you to experiment. Static typing proponents often say, since a type-error means that the code doesn't make sense, why would you ever want to run code that doesn't typecheck? But I find that when I'm experimenting, I want to do this all the time.

I ran into this recently when I was working with Rust. And don't get me wrong; I love Rust. But I was experimenting with a new way of doing things in my codebase and was adding a new kind of statistical analysis, and I wanted to run a test case to see what the result was... However, I couldn't because the compiler's typechecking refused to even compile my code, when I knew for a fact that the type errors had nothing to do with the code path of my test case.

I get that that's the whole point of static checking. I can change a large codebase and know exactly when/where I've broken something even if I'm not familiar with all the code, and it will barf at me. But the fact that I can outsmart it, even some of the time, leads me to believe that there will always be a place for dynamic languages.

If 99% of my code has type errors, but there is one code path that is true, who is the compiler to say that that isn't the one code path that I want to take? When experimenting, I build my code dozens of times. The vast majority of the time, I am the only one who consumes the build result. Once in a rare while, I will reach a steady state and build a release. It's really only then that I want the compiler to barf at me and refuse a broken build.

I must not be the only person on the planet who wants to do this sort of thing.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by usrusr on Friday June 21, 2019 @04:04AM (#20240767)
The eclipse java compiler can be instructed to substitute (most) compile errors with runtime exceptions for those intermediate builds. You still get all the compile time error messages, but the code is ready to run, right up to the point where the compiler complained.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jonnytran on Friday June 21, 2019 @03:58PM (#20245836)
That's a cool feature. I'd like to see this in other languages and become the norm.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by hamilyon2 on Friday June 21, 2019 @09:55AM (#20242491)
Yes, eclipse java compiler definitely stretches the definition of possible.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by teyc on Friday June 21, 2019 @06:15AM (#20241248)
that's clever, but how does it work?
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by usrusr on Friday June 21, 2019 @11:52AM (#20243589)
It doesn't when the error is in something clever you did with the type system (e.g. wildly interdependent generics pretending to be scala).

But for many simpler cases (e.g. the majority of idiomatic java), it can be as simple as substituting an offending imperative line with a throw RuntimeException statement that parrots the compiler error message. I'm sue that they are doing a lot more than that.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by astrobe_ on Friday June 21, 2019 @07:35AM (#20241561)
It looks like what you want is type-mismatch as warnings. I'm not sure it would be viable though, because dynamic languages can throw an exception in this case, while static languages will segfault. Unless the compiler inserts instrumentation code where it saw a type mismatch?
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by DougBTX on Friday June 21, 2019 @02:42AM (#20240400)
Yea, that seems like a use-case I’ve felt like I wanted before. TypeScript supports this, as the JS output can be produced even if type checking fails, though in practice I have it turned off so that I don’t accidentally end up with type errors I’ve not fixed.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by pwm on Friday June 21, 2019 @04:54AM (#20240941)
Statically typed languages that employ type inference (eg. Hindley–Milner) do exactly this, ie. you just write your function definition and the inference engine figures out its type. Doing this in the repl gives you comparable flow to doing it in dynamic langs but with full type safety.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by wglb on Friday June 21, 2019 @05:57PM (#20246614)
If you are thinking Lisp is not typed, that is not true. I am caught with type errors all the time.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by steveklabnik on Thursday June 20, 2019 @06:07PM (#20237879)
I think about this a lot, as someone who loves Ruby and loves Rust. I think it’s because we do a bad job of looking at the total costs. It feels like you can knock something out really quickly in Ruby. And in some sense, you can! But the time you spend debugging later doesn’t get factored into the way that it feels when you’re just cranking out features.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tptacek on Thursday June 20, 2019 @06:24PM (#20238013)
Yes, and, just to keep this clear: that debugging (or unit-testing-for-typos) time is coming out of your prototyping budget. Your Ruby program will fail to run for stupid reasons the first time you run it, which is not the experience Java and Go and Rust programmers have. I just remember when I first picked up Go, after about 5 years writing Ruby exclusively, how amazing it was that all my Go programs "worked" the first time I ran them. Obviously, they had bugs. But they didn't blow up for stupid reasons.

I'd been a C/C++ programmer for about 10 years! I guess I just forgot that compilers can catch typos if you let them.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by losvedir on Thursday June 20, 2019 @07:53PM (#20238644)
> Your Ruby program will fail to run for stupid reasons the first time you run it, which is not the experience Java and Go and Rust programmers have.

I know exactly the feeling, but I don't think it's just the types that give it but that it's compiled. I similarly moved on from ruby after 5 years but to Elixir and was similarly surprised to (re-) learn that a simple compile step catches so many braindead typos, misnamed variables, not imported function calls, and the like.

Types go above and beyond this, but I think there's a huge step up just going from interpreted to compiled.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by smw on Thursday June 20, 2019 @07:37PM (#20238541)
I know a lot of people in the Ruby community tend to believe in using text editors with limited (or no) semantic understanding of the code. I've found that using, for instance, JetBrains Rubymine tends to make typos and related bugs apparent as they happen. Not to mention providing autocomplete that usually feels like using a statically typed language.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by cbetti on Thursday June 20, 2019 @11:00PM (#20239519)
New to Ruby, veteran Java/C++, while I'm liking what RubyMine adds, it's nowhere near what I get from a simple language with a simple type system like Java.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by MaxBarraclough on Friday June 21, 2019 @05:06PM (#20246301)
The ability to refactor, for one.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jacobolus on Friday June 21, 2019 @06:08PM (#20246667)
I think this is a Ruby thing more than a dynamic languages thing. (Not exclusively a Ruby thing mind; Javascript code is also always full of weird edge cases and gotchas.)

I wouldn’t necessarily recommend it, but I have written 500-line Python programs without executing/testing any functions along the way, that “just worked” the first time I ran them with no serious bugs. And not because I am especially clever or have an amazing memory or unusual attention to detail, but just because the code is easy to make clear and straightforward.

(But this was just with basic data types and a few standard library modules; dealing with other people’s poorly documented / confusing APIs makes this gets a lot harder.)

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by go_ruby on Thursday June 20, 2019 @09:38PM (#20239147)
You never had a go program fail to compile, only to fix the problem then try to compile again? Replace 'run' with 'compile' and you could still type a bunch of go code and have to make changes before you deploy or no?
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by ncphillips on Thursday June 20, 2019 @11:33PM (#20239671)
Tooling makes this argument moot. I use Ruby and TypeScript, both with VSCode. The experiences are vastly different. Ruby is slow and difficult to work with, and TypeScript is a breeze. I don’t have to wait for my TypeScript to compile before it tells me about the typo I have, the editor tells me immediately after typing the word.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by nitrogen on Thursday June 20, 2019 @08:03PM (#20238697)
It's odd to complain about the first run not working, when the first run is significantly earlier. I'd also say the interactivity of Pry and binding.pry more than compensates for anything lost by not having a compilation step.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by koolba on Thursday June 20, 2019 @08:09PM (#20238732)
I’d argue that type checking combined with editor auto completion leads to faster development.

The feedback loop is within your editor, that’s a step before the app console!

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by ncphillips on Thursday June 20, 2019 @11:38PM (#20239697)
100% going from Java+IntelliJ to Ruby+VSCode was shocking. In regards to tooling, the developer experience is way behind with Ruby. Sure there’s a lot more boilerplate to look at, but with tolls you don’t actually end up writing much. And then you get refactoring tools that are actually super useful and robust.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by cbetti on Thursday June 20, 2019 @11:04PM (#20239536)
Prototyping in Java is as fast as prototyping in Ruby once you understand how to use the tools equivalent to Pry in Java, and standard types instead of rolling your own types. JIT isso fast today the 20ms required to JIT what you type is immaterial.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by pjmlp on Friday June 21, 2019 @01:57AM (#20240204)
More so now with better type inference and repl integration.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by nitrogen on Friday June 21, 2019 @03:27AM (#20240625)
What REPL do you use on the JVM? I've added JRuby to Java projects in the past just to get a REPL.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by pjmlp on Friday June 21, 2019 @03:42AM (#20240679)
The one that comes with it, starting with Java 9, jshell.

Before that, there was the Rhino and Nashorn ones, which although JavaScript based, did the job.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by signal11 on Friday June 21, 2019 @02:53AM (#20240462)
Not strictly Java, but Groovy is a great environment to prototype on the JVM. Prototyping was lightning fast and turning it into Java code was pretty quick too. There’s great IDE support for it too (IntelliJ’s Groovy scratches).

These days Kotlin is also pretty good. Perhaps not quite as fast to prototype but there’s little need for converting afterwards.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by zmmmmm on Friday June 21, 2019 @05:52PM (#20246581)
Yes, add an environment like BeakerX [1] (essentially, Jupyter notebooks) and it's quite amazingly good to figure out your approach even if you intend to write Java.

[1] http://beakerx.com/

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by ggregoire on Thursday June 20, 2019 @08:38PM (#20238851)
This.

I inherited legacy Python projects at work and I'm shocked by the time I'm wasting fighting with the lack of types. Most of the time I have no idea (and my IDE neither) what methods and properties are available on variables and function parameters. And what's the most insane to me: I'm sitting next to people with LOT of experience in Python and I see them losing as much time as me when maintaining and debugging some basic piece of code they have written not even 2 weeks ago.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by bhaak on Friday June 21, 2019 @05:29AM (#20241079)
> Most of the time I have no idea (and my IDE neither) what methods and properties are available on variables and function parameters.

If I am really this lost with a piece of code in Python or Ruby, I usually start an integration test with an added line to call the debugger.

With introspection you can then easily see what methods a given object has.

> And what's the most insane to me: I'm sitting next to people with LOT of experience in Python and I see them losing as much time as me when maintaining and debugging some basic piece of code they have written not even 2 weeks ago.

That is insane. What kind of code coverage do you have and what kind of tests?

It is true that you have to write more tests in a dynamic language than in a static typed language but as tests often convey the information of what was intended to be done much better than code, I don't consider this a drawback.

But if the tests are lacking, you are at a much greater loss than with static typed languages.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by Gene_Parmesan on Friday June 21, 2019 @02:28PM (#20245125)
> With introspection you can then easily see what methods a given object has.

With VS and C#, I can hit ctrl+space and get a list of absolutely everything that's in the contextually relevant public API. So much faster than introspection. If I'm using an object initializer to instantiate something, I can hit ctrl+space inside the object initializer to get a list of all the available public properties -- no typing the names required. No having to remember the order of arguments of methods, or even their types. Autocomplete means I can usually get away with somewhere between zero and three keypresses to get exactly what I want highlighted in the intellisense.

Forget efficiency via vim/emacs keybindings. Static typing + a strong intellisense/intellisense clone lets me code literally at the speed of my thoughts most of the time. I end up feeling like I'm stuck in molasses the few times I have to write some JS.

> It is true that you have to write more tests in a dynamic language than in a static typed language but as tests often convey the information of what was intended to be done much better than code, I don't consider this a drawback.

I understand your point, but for me, the extra tests I write in dynamic langs just end up making me feel like I've duplicated the work of the static checker in other languages, and in a non-reusable way.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by baroffoos on Thursday June 20, 2019 @09:04PM (#20238994)
I am a ruby developer who tried rust. I don't think its the language thats the issue, its the libraries and tooling. I tried rust with rocket and I spent a week trying to get the rust app to connect to postgres because of having to deal with so many things like connection pools and setting up the ORM. I eventually just gave up and used rails where you just tell it the username and password for your database and you are pretty much good to go.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by steveklabnik on Thursday June 20, 2019 @09:49PM (#20239186)
Ouch, that seems like a long time. It is true that Rust isn’t as integrated here. I’d love a rails too. Which ORM did you try?
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by go_ruby on Thursday June 20, 2019 @09:40PM (#20239154)
You actually spent 40+ hours trying to connect to a db with rust? Please tell me that's a gross exageration...
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by baroffoos on Thursday June 20, 2019 @09:56PM (#20239220)
It was a free time project so I probably spent about 4-5 hours spread over a week or two
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by hrktb on Friday June 21, 2019 @05:16AM (#20241032)
This is an advantage depending on the projects and organisation.

For instance if features need to be demonstrated or prototyped on a test env. for some time before they are green lighted to be fully baked, loosely typed languages are ideal. You get the speed of prototyping, and all the heavy cost comes after the main parts have been validated.

It's less painful than having to do prototypes after prototypes in a more rigid language.

But of course this advantage disappears when working more in small waterfall iterations, where everything is basically set in stone from the start.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by zapzupnz on Thursday June 20, 2019 @06:23PM (#20238007)
I've never quite understood the notion that languages like Python and Ruby are amenable to fast prototyping. Ultimately, you wind up just having to carry complicated type information in your head rather than write it all down in your code, all whilst the compiler utterly fails to help you in any way in case your memory ain't what it used to be.

I'm sure those languages and their ilk have advantages for prototyping, but I agree, mandatory typing in other languages isn't a burden. If you already have to reason about what arguments are acceptable in functions, what objects can receive what messages and what those messages should contain, you already have typing — just inefficiently stored in short term memory.

Those who are the biggest proponents of these languages as useful for prototyping are also not the ones who rewrite their code in type-safe languages, so being able to add type annotations for the sake of their colleagues who eventually have to turn these prototypes into code upon which a team can collaborate can only be a useful thing.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by nemothekid on Thursday June 20, 2019 @06:46PM (#20238155)
>I've never quite understood the notion that languages like Python and Ruby are amenable to fast prototyping.

I've thought about this for a while and I think the "fast prototyping" reputation is an accidental feature that sticks because of history.

Python and Ruby were just better languages than Java 1.4, C++, Perl and PHP were at the time. They were so much better for not only prototyping, but writing - it was easier to get something working and iterate in Python than it was in Java. And not only were they better, they were better at the right time when the internet exploded.

Now, it largely feels like languages like Java and newer languages like Go have caught up, but Python and friends still enjoy the feature of "fast prototyping." Now I think this is because since they had gotten so popular, they now have a massive ecosystem of libraries and idioms that makes it so easy build applications.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by kyllo on Thursday June 20, 2019 @07:35PM (#20238528)
Java and Go today are much better to work with than Java was in, say, the early 2000s, but to realize the productivity boost of a dynamic language within a statically typechecked language, you need type inference and a REPL.

You still don't get this with Java or Go, but you certainly do with ML-like languages (Haskell, SML, OCaml, F# etc.)

A lot of Haskell developers will tell you that writing Haskell feels a lot like a functional Python, and they use Haskell for scripting as well as application development.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by cutler on Thursday June 20, 2019 @08:24PM (#20238790)
Until Java gets data classes it will make you miserable. Lambdas are clunky in Java at best. "Much better to work with" than Java 1.3 is setting a pretty low bar.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by philwelch on Saturday June 22, 2019 @12:03PM (#20250279)
> Until Java gets data classes it will make you miserable.

https://projectlombok.org/features/Data

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by pjmlp on Friday June 21, 2019 @02:00AM (#20240213)
Java has repl support since Java 9 and before that there were interactive sheets like Eclipse scratch pad, which alongside incremental compilation were already quite good.

And while Java's type inference is not the same has having HM around, it is already q89te friendly.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by fouc on Thursday June 20, 2019 @07:35PM (#20238531)
I think ruby has a reputation for "fast prototyping" for a few reasons

1) readable (somewhat english-like syntax) 2) terse (short and to the point, no extra setup code needed) 3) meta-programming/DSLs

It still remains unbeatable for readability and terseness..

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by cutler on Thursday June 20, 2019 @08:21PM (#20238777)
Yes, and it's for this reason that adding a type system will to it will alienate a lot of its users. You can say "optional" or "gradual" as much as you like but adding types will split the community which is the last thing Ruby needs right now. The trouble with tech is we just can't let something be and stop fiddling with it. Ruby is fine just as it is.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by bhaak on Friday June 21, 2019 @05:34AM (#20241098)
> Ruby is fine just as it is.

Which Ruby do you mean? 1.8, 1.9, or a more current one?

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by nitrogen on Thursday June 20, 2019 @08:04PM (#20238706)
Don't forget 4) no compilation/ultra fast test cycle and 5) REPL (IRB or Pry)
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by zapzupnz on Thursday June 20, 2019 @07:36PM (#20238536)
This response makes sense to me.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jonnytran on Friday June 21, 2019 @01:44AM (#20240148)
This is a straw man argument. Sure, if your types are simple like int, string, or float, you might as well write them down rather than keep them in your head. They double as documentation. However, the other cases are where it matters.

1. When the types are complicated enough, people no longer read them. They skim over them and don't bother to ever "load" them into short term memory. Sometimes it makes sense to make a type alias for the subcomponents, but many times they're one-off types and it wouldn't make sense. As the person writing the code, figuring out what the types actually are and writing them down doesn't actually help anyone. It's just busy work that the compiler or interpreter could have inferred. For example, if I have a hash nested in an array, nested in a set, you can access them all with brackets chained together. I don't actually need to know the full type in order to use it. So why bother figuring out the exact type that it is? Which brings us to...

2. When the types are abstract, with type variables and type constraints, someone has to put in the work to come up with the most sensible type signature. Sometimes that is the most general type that the code satisfies (using a Rust trait, Haskell typeclass, or a Java interface), but sometimes it's not. It really depends on the context. Should I abstract over this type and introduce a type parameter to the function? Or should the type parameter be for the entire struct/class? These are oftentimes complicated questions, with no clear answer. Weighing your options and choosing is real work. If I now say that this function will accept different sized ints, I may no longer be able to just call i64::something(). I literally need to change how I write my code or even import a new helper library to do it. (I have had to do that in Rust. And I love Rust, BTW.)

OTOH, in a dynamic language, all of that work is just gone.

What I'm saying is that types for a compiler must be precise and general. But types that you keep in short term memory are oftentimes vague (something that I can index, or some kind of number) or specific to a test case. And it doesn't matter.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by zapzupnz on Friday June 21, 2019 @04:48AM (#20240924)
> This is a straw man argument.

That would imply ill intent on my part, and there was nothing of the sort. All I said was that I couldn't see the sense in certain things and, without further explanation, I didn't. Other comments helpfully pointed out the context for why the assertion is so often made and I was happy with it.

On the other hand, I think I'd need to see some hard evidence for the following assertions:

> When the types are complicated enough, people no longer read them

What is a complicated type?

> As the person writing the code, figuring out what the types actually are and writing them down doesn't actually help anyone.

Citation needed. I find static typing tremendously helpful in my own code, especially if it's code I haven't worked on in a long while.

> It's just busy work that the compiler or interpreter could have inferred

… such that I only notice errors when the code is running, not beforehand. Without type annotations, interpreted languages like Python and Ruby are happy to let wrong types in function calls and message passes slide — which is why frameworks like Sorbet exist, to help eliminate that class of error.

> 2.

All of that is language-specific, surely, not really anything to do with static or dynamic typing. That whole mechanism is quite straight-forward and has a well-prescribed mechanism in Swift, for instance, with protocols, extensions, and conditional conformance.

> OTOH, in a dynamic language, all of that work is just gone.

I mean, it's not just gone. There are trade-offs, of course there are; but the assertion that the work is gone also implies the potential associated errors are gone seems a bit ingenuous to my eyes.

Yeah, types can be a bit constraining — but at the same time, if you reason about them properly and according to the language's prescribed mechanism rather than fight them, it can and does become second nature. At that point, using types becomes as simple for some as not using types is for others.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jonnytran on Friday June 21, 2019 @01:41PM (#20244699)
A better example of a complicated type that no one ever loads into their short term memory is the type of a parsed JSON object from an API response. No one ever bothers to figure out or reason about the type. They have documentation or an example response that they just navigate.

If you want to advocate something like protobufs, that's a separate issue from static vs. dynamic typing. The point is that in a dynamic language you literally _don't have to_ reason about many types at all. Or you do it in a completely different way that doesn't involve holding the type in your short term memory.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by philwelch on Saturday June 22, 2019 @12:10PM (#20250316)
In most statically typed languages you end up with a class/struct type that encapsulates the API response you are either generating or parsing. When you don’t have this, you have to either assume or defensively program around the presence or absence of certain fields in certain contexts. “Everything is a hash/dict/JSobject” doesn’t absolve you of having to reason about which fields an API payload contains, it just forces you to do it all by hand rather than simply defining a data type and telling your serializer/deserializer “this is what I want” (and then operating on a strongly typed object rather than an arbitrary hash table).
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tomp on Friday June 21, 2019 @06:39AM (#20241331)
I am an "expert" in static type systems (I'm familiar with Java, Scala, OCaml, Haskell, Rust, Go, TypeScript, C++ ... and keep up to date with latest type systems research like 1ML, MLsub, Liquid Haskell, ...), but I have a really hard time imagining how one would develop a statically typed library that would even approximate the usefulness and convenience (for rapid prototyping and interactive data analysis) of Python's Pandas (although if I was a betting man, I'd wager the best language to implement it in would be Scala, with it's advanced macros & almost-dependent type system).
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by adambard on Thursday June 20, 2019 @07:01PM (#20238273)
I think it has less to do with the languages themselves, and more to do with the frameworks available, and the metaprogram-y things those frameworks are free to do without a type system stopping them.

I've yet to see the equivalent of Django or Rails when it comes to rapidly assembling a database-backed CRUD app in a statically typed language.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by chessturk on Thursday June 20, 2019 @07:18PM (#20238414)
My job has internal tool that reads MySQL schemas and outputs a CRUD golang api and json-based form uis to interact with them.

I think it could be it's own product, but leadership doesn't care.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by haimez on Thursday June 20, 2019 @08:37PM (#20238846)
I assure you, it could not be its own product- but it could be its own open source project.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by chessturk on Thursday June 20, 2019 @11:46PM (#20239726)
That is what I meant, don't know why I put product. Too many meetings.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by vinceve on Friday June 21, 2019 @01:16AM (#20240048)
I am working as a java developer now for about 3 years. Before I worked 5 years with rails. You are completely right, a spring boot application with Lombok doesn’t come near a rails application. Also what people tend to oversee is that the recompilation step really takes a lot of time.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by neetdeth on Thursday June 20, 2019 @07:39PM (#20238551)
Their reputation for fast prototyping was established before type inference became a widely available language feature.

Duck typing is also a minor win for "do what I mean" generics - you never have to worry about the type specification being too narrow, just pass an object with the necessary methods and it'll work until it breaks.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by nine_k on Thursday June 20, 2019 @10:51PM (#20239468)
Python and Ruby are extremely malleable, like Smalltalk and lisp before them. You can inspect anything, you can override / replace / proxy anything. You can use a few built-in collection types for nearly anything.

This is by design. This is great for prototyping.

These languages are to programming what breadboards and wires are for electronics.

Of course, as your system grows, you start to want static checks, or having your schematics on a PCB. But at the very start, tweaking a piece of Python code, or a breadboard, is easiest. Then, of course, you may not want to afford a a rewrite to rust, or would put your breadboard in a box and ship it :)

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by crdoconnor on Friday June 21, 2019 @12:49AM (#20239952)
>Of course, as your system grows, you start to want static checks

I've been working on large scale python systems for about 10 years. For me, the most cost effective checks as a system grew have been asserts.

They allow extremely sophisticated pre/post condition checking (partly helped by pythons flexibility), they're cheap to write, they don't take up much space, they catch a shit ton of bugs, they clearly highlight the source of the bug, they work together really well with higher level tests and I've almost never had them trigger in prod (so the fact that they technically could, as static type fans keep reminding me, doesn't really bother me).

For me, asserts and integration tests are what make large scale python systems a pleasure to write.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by kazinator on Thursday June 20, 2019 @11:14PM (#20239582)
Funny; I'm a Lisp programmer, not to mention implementor, but whenever I do electronics, even something simple, I go straight to PCB. I can make those things at home with a quick turnaround time. I prefer manipulating traces in the PCB routing program than messing around with flaky wire connections on a breadboard. If it's worth doing, it's worth doing well. After I made my first PCB, there was no going back. I'm confident my circuits will work because I calculate and simulate; and in any case, usually even if the circuit won't work initially, the printed circuit topology will, modulo adjustment of component values. You can anticipate experimentation in a printed circuit, too.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by hippich on Friday June 21, 2019 @01:06AM (#20240009)
I think you just replaced breadboard with simulation. It makes sense, but kinda supports the point :)
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by loxs on Friday June 21, 2019 @02:32AM (#20240355)
My experience with writing prototypes in Python is that one week later I have difficulties understanding it and one year later (yeah "temporary, my ass" kind of thing) it's completely alien to me.

It's absolutely not the same with OCaml, F# and lately, TypeScript. And I don't think I write the prototype in more time in this languages (if we are talking about something that takes up days, not minutes, of course). But the experience some months down the road is completely different.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by dragonwriter on Thursday June 20, 2019 @07:29PM (#20238490)
> There are a lot of things that make Go slower to write than Ruby, but mandatory typing isn't one of them. Rather, Ruby's total lack of typing makes it harder to write: you effectively end up having to write unit tests just to catch typos.

No, you don't. You need unit tests to verify behavior (values) whether or not you have static typing (except for output types with only zero or one values). Now, it's true, that having such tests also verifies, at no extra charge, things that Go’s type system would verify, but without the additional effort of type annotations. But there's no added cost there, it's a net savings.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by earleybird on Thursday June 20, 2019 @07:58PM (#20238674)
To abuse Greenspun's 10th - Every untyped codebase contains ad-hoc, informally specified, bug-ridden, slow implementation of types (written as unit tests).

edit: as pointed out - I need type checking on my words

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by crdoconnor on Friday June 21, 2019 @01:06AM (#20240007)
This "unit tests substitute for static types" is a common straw man. Asserts catch similar kinds of bugs to static type checkers with a similar level of effectiveness and cost.

Moreover, they're typically able to do more sophisticated checks than most languages (e.g. similar to the kind of sophistication of Haskell's type system).

(yes, I know what is going to be replied... IME, they actually fail in prod vanishingly rarely)

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jolmg on Thursday June 20, 2019 @08:03PM (#20238700)
I think you meant "types as unit tests", not the other way around.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by quickthrower2 on Thursday June 20, 2019 @07:43PM (#20238580)
Tests don't catch all bugs, even well written ones. Infact if tests could catch all bugs, you'd be able to write a test to determine if any program halts (!).

Now let's look at the nature of programmers. What mistakes are they most likely to make on a regular basis? Well they are human, and they are whacking these big fingers at a keyboard. Maybe typos? Also programmers are bad at spelling, from the source code I've read.

Now could a unit test catch all typo-led mistakes? Well I doubt it. Not for a big program with 10's of KLCs.

Does typing help? Yes - and I'd say typing speeds up programming by allowing autocomplete of code (because of less er... typing as in the finger kind). Since the IDE knows the type it can help you find the write method.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by dragonwriter on Friday June 21, 2019 @04:26AM (#20240849)
> Yes - and I'd say typing speeds up programming by allowing autocomplete of code

Autocompletion is available in numerous IDEs and editor plugins for many popular dynamic languages (and some dynamic language REPLs, too); static typing certainly can provide a source of data for autocompletion, but it's not necessary for it.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by heartbreak on Thursday June 20, 2019 @10:49PM (#20239460)
> you'd be able to write a test to determine if any program halts

Halt != bug, so this problem doesn't really apply.

You can write provably correct software, even if we still haven't solved the halting problem.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by ehaliewicz2 on Friday June 21, 2019 @12:08AM (#20239794)
In most languages you can definitely introduce a bug which causes a program to not halt.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by owl57 on Saturday June 22, 2019 @06:15AM (#20248878)
Yes, but do you often need to automatically determine if a bug causes a program to run indefinitely or only much longer than expected? That would be the halting problem, yes (strictly speaking, some subset of it, and for many programs a decidable one).
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tptacek on Thursday June 20, 2019 @07:56PM (#20238657)
You’ve misconstrued my argument. I’m not arguing that unit tests are unnecessary in typed languages.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jonnytran on Friday June 21, 2019 @01:20AM (#20240067)
If you admit that tests are necessary in statically typed languages (which I agree with), then why does having to write tests in dynamic languages make them harder to use? Presumably, you were going to write them in the statically typed language anyway.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by apsdsm on Thursday June 20, 2019 @07:40PM (#20238559)
Yes and no. It’s true that cleverly written tests encompass bad input, but this also means you need to add an additional layer to your test thinking, which depending on who is writing those tests might might yield results of varying quality... Or you could try fuzzing?
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by dragonwriter on Friday June 21, 2019 @04:57AM (#20240963)
> It’s true that cleverly written tests encompass bad input, but this also means you need to add an additional layer to your test thinking

Sure, you have to deal with more cases in running code if they aren't foreclosed by static guarantees, but you are either adding the thinking to code static guarantees and you are doing the thinking to code tests, and I've seen overpermissive types from too-shallow thought on that (even when it's not due to insufficient expressiveness in the type system) plenty of times to not think its substantially less of a risk than inadequate testing.

I'm not against static typing; I definitely think it has an important place in the toolbox, butnmy experience doesn't align with the idea that static typing is universally better for rapid prototyping.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by dnautics on Friday June 21, 2019 @01:25PM (#20244569)
fuzzing is kind of crude, you should go for a more sophisticated type of test, like property testing, which is "fuzzing" plus "shrinking"
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by danmaz74 on Thursday June 20, 2019 @06:49PM (#20238183)
Nowadays I write unit tests for any nontrivial code I create. It takes a little more time than writing type declarations, but IMHO they offer much more value.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tptacek on Thursday June 20, 2019 @07:04PM (#20238304)
Unit tests are great, but they're a stupid way to catch typos.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by danmaz74 on Friday June 21, 2019 @03:17AM (#20240576)
I agree that writing them only to catch typos would be stupid. But if you're going to write them regardless, catching typos comes for free.

Ps and luckily, even with dynamic languages any decent IDE will catch most typos

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by dragonwriter on Thursday June 20, 2019 @07:50PM (#20238626)
> Unit tests are great, but they're a stupid way to catch typos.

Catching typos is an important part of what unit tests do with statically typed code, since typos result in value errors at least as often as type errors.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tptacek on Thursday June 20, 2019 @07:57PM (#20238668)
That’s obviously true, but it’s equally obvious that there’s a whole (large) class of typos that types eliminate.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tarsinge on Thursday June 20, 2019 @08:48PM (#20238917)
For prototyping sure, because the prototype might grow, but otherwise it depends on the type and scope of the project I think. For the kind of CRUD web app projects I pick Ruby for I still fail to see how I could benefits from types instead of slowing me down. I may be missing something, so I’m interested if you have any resources with concrete examples for common errors.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by smt88 on Thursday June 20, 2019 @08:59PM (#20238973)
I've found strict typing, along with type inference and a good IDE, to be much faster than a dynamic language.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tarsinge on Thursday June 20, 2019 @10:50PM (#20239467)
My point is that in my experience it depends on the project, and that dynamic languages still have their places. For example if I have to code a few web pages with some data visualisations in D3 I found that going straight with vanilla JS in a text editor is the best tradeoff. Any bug that would have been catched with typing will obviously be catched visually.

I don't challenge the benefits of static typing for more ambitious projects with a constantly updated codebase and multiple developers, or the usefulness of IDE with large codebases or frameworks.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by smt88 on Friday June 21, 2019 @10:27AM (#20242752)
> dynamic languages still have their places

I wasn't disputing this in my previous comment, but I do actually disagree with it at this point. I haven't found a use-case for a dynamic language in many years. I cringe at the thought of working with them now.

> vanilla JS in a text editor is the best tradeoff

This defies my understanding of the word "tradeoff". It costs nothing to fire up a full IDE instead of a text editor, so why not use one? It comes with autocomplete at the very least, but also static analysis of JS.

If something costs nothing and has a benefit, it must be the best tradeoff, right?

> Any bug that would have been catched with typing will obviously be catched visually.

Catching bugs at runtime is slower by definition than catching them while you're writing the code in the first place. Why make things harder when great tooling is a few clicks away?

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tarsinge on Friday June 21, 2019 @02:29PM (#20245136)
You are focusing on the IDE aspect which I do not necessarily disagree with, honestly I haven’t tried the recent offerings for Ruby or JS so maybe it’s 0 cost now.

> I haven't found a use-case for a dynamic language in many years.

That’s actually my initial point. The use case is small scope projects, where you get the benefits of dynamic languages (faster and easier write and easier to read) without the maintainability cost and where you’re unlikely to ever get a type error.

Edit: concrete example: Standalone web page with a GET request to get some data, create a chart, and some user events like mouseover. No build tool chain, plain JS. I don’t see how I could benefit from types and what kind of errors would be prevented, but maybe the overhead is now very low with recent tooling and I should re-evaluate.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jhayward on Saturday June 22, 2019 @09:38AM (#20249500)
> I haven't found a use-case for a dynamic language in many years

This seems like a rather extreme statement given the number of people in the mathematics and science communities that find plenty of use cases for Python/Scipy/Numpy/Pandas/Tensorflow, etc.

What language ecosystem would you suggest for those people?

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by jchw on Friday June 21, 2019 @01:49AM (#20240171)
I agree: I think most people that look at typechecking as a serious friction are thinking about it wrong; the problem is probably languages with bad ergonomics. Many people who use TypeScript actually end up using it with strict defaults for even new or toy projects - it’s too valuable to not, honestly.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by zmmmmm on Friday June 21, 2019 @06:12PM (#20246705)
I agree about the ergonomics.

Another aspect of that which I have noticed is that so many fans of dynamic languages refuse to use IDEs. They'll even state it simply as "I don't want to use a language that makes me use an IDE". For me, the IDE is like a second part of my brain. I use Eclipse which does incremental compile at every keystroke and I see errors, warnings, autocompletes, hints etc in real time. This removes a huge amount of the ergonomic barrier they are talking about (having to save your file, run a compiler, only then see the errors, then find that line in the file, etc ...). But they are stuck at "I don't want to use an IDE" ....

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by pvg on Friday June 21, 2019 @05:00AM (#20240977)
Wasn't that perception around long before the 'bolted on' type systems appeared? To me, it seems like some of the clunkiness and sharp edges of the type systems of commonly-used typed languages at the time - C++ and Java had a lot to do with it along with RoR enthusiasts portraying static typing as some sort of tool of oppression.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tptacek on Friday June 21, 2019 @09:15PM (#20247426)
Yes, it was; I wrote imprecisely, I'm referring to the perception of systems like Typescript being clunky for prototyping.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by pvg on Saturday June 22, 2019 @02:48AM (#20248361)
Oh I see what you meant now - I've mostly seen people being super-excited about their new typesystem JATO rockets.

My own theory is that we likely underestimate how much of this might just be fashion. I don't mean this dismissively or to suggest that the mood swings over typing in the last 20-odd years have been without technical basis or impetus. Just that, you know, at some point people liked bellbottoms or Members Only jackets and later they didn't.

Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by shay_ker on Thursday June 20, 2019 @07:03PM (#20238290)
I think it's mostly the REPL that allows for quickly spiking out things, with quick feedback. Elixir has a similar experience, but less of the warts you get with Ruby (like monkeypatching).
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by tptacek on Thursday June 20, 2019 @07:04PM (#20238300)
Absolutely. Ruby is faster to write than Go, and the REPL is a big part of that. I'm saying: it would be even faster to write if it had static types.
Re:Open-sourcing Sorbet: a fast, powerful type checker for Ruby by nerpderp82 on Thursday June 20, 2019 @07:14PM (#20238373)
If it had static inferred types a la Ocaml.