News for hackers. Stuff that matters.
Re:Stripe is building a Ruby typechecker by pg_bot on Sunday June 03, 2018 @05:04PM (#17222032)
I don't understand the appeal of static typing. It always feels like I'm adding overhead without receiving any benefits. I've worked in some fairly large dynamically typed codebases and have never run into issues with type errors. Static typing does not alleviate the need to test your code, which is a more effective way of reducing bugs in your system than annotating your methods/functions.
Re:Stripe is building a Ruby typechecker by matchbok on Sunday June 03, 2018 @05:10PM (#17222086)
Not sure I've ever heard anyone say static typing removes the need for testing.

Types are self-documenting. Onboarding new devs in a large static codebase will be 10x easier than a dynamic one.

Coding is actually faster in statically typed projects - autocomplete works every single time and you never have to dig into another source file to see what objects/methods you have.

And, most modern type systems (Typescript, Swift, etc) don't have much overhead at all with their impressive type inference.

Re:Stripe is building a Ruby typechecker by mping on Sunday June 03, 2018 @05:38PM (#17222373)
It's a double edged sword - onboard some devs on "advanced" scala code and let me know how the 10x is working for ya. I also feel that sometimes types cause additional congitive load - you have to mentally model the types and what they do. OTOH I'm pretty sure most people can onboard a js project that's well written.

I think exploratory, debug-based onboarding can be easier with poorly written static lang codebases that dynamic, but then again depends on what convetions are used. I don't care much about autocomplete unless I have to type ReallyLongClassNamesThatAreSupposedToBeMeaningful; besides coding is mostly about avoiding errors, not typing faster.

In the end, whatever floats your boat but dyn langs surely have their place.

Re:Stripe is building a Ruby typechecker by matchbok on Sunday June 03, 2018 @07:04PM (#17222957)
I've heard the "mentally model" argument a few times, and tbh I don't quite understand it. You have to model the object regardless, either with types or tons of extra checks to make sure that object has what you need. I've seen so much javascript code do exactly that because the methods had no idea what they were going to be given. The contract of static typing eases that load, I think.
Re:Stripe is building a Ruby typechecker by mmartinson on Monday June 04, 2018 @02:00AM (#17225031)
Ya for sure. Without getting a debugger into the application code, it sometimes seems completely impossible to look at a piece of dynamic code you're not already familiar with and decide if it's going to work. I've found this especially tough during code reviews for new stuff that make heavy use of abstractions, even when the abstractions are good.
Re:Stripe is building a Ruby typechecker by mping on Monday June 04, 2018 @08:27AM (#17227066)
Personally I feel that my mind is registering what each type does, kinda like building a mental dictionary. Dynlangs also have types but in terms of reading code it feels you can just skim through and skip the details. I guess there is a difference in the cognitive load of reading code and writing code.
Re:Stripe is building a Ruby typechecker by pmontra on Monday June 04, 2018 @04:11AM (#17225565)
Actually the only language I used autocomplete was Java, mainly because it's almost impossible to work in Java without a IDE. However sometimes I turned autocomplete off because those long menus are a pain to see. I don't use a real autocomplete in Emacs with Ruby, Python, Elixir, JavaScript. I use pabbrev which remembers the words I type. It's usually enough not to make typos and it helps to remember the methods/functions.
Re:Stripe is building a Ruby typechecker by jrs95 on Sunday June 03, 2018 @08:41PM (#17223514)
At this point I don’t think anyone sane is seriously advocating for the adoption of Scala.
Re:Stripe is building a Ruby typechecker by hderms on Tuesday June 05, 2018 @10:22AM (#17237831)
What alternatives are there to what Scala provides? What newer language would a 'sane' person advocate?
Re:Stripe is building a Ruby typechecker by jrs95 on Tuesday June 05, 2018 @11:38PM (#17244191)
Unless you really need it for a platform like Spark where there aren't many other options, pretty much any other statically typed language is likely to be more productive in the long run, once you account for the costs of Scala's complexity. Java, Kotlin, C#, whatever. And if you don't need or want the benefits of statically typed languages, then the same is also true for most major dynamic languages. It's difficult to be more specific than that because I don't think there's a very compelling case to use Scala to begin with.
Re:Stripe is building a Ruby typechecker by markmark on Sunday June 03, 2018 @07:19PM (#17223043)
When using a dynamic language you need to know what properties are on an object right? So you can work with them, access them, whatever. So just write it down so everyone else knows too. There, that was easy.
Re:Stripe is building a Ruby typechecker by wtetzner on Sunday June 03, 2018 @10:15PM (#17224019)
If that’s the case, then why not have the compiler check them as well?
Re:Stripe is building a Ruby typechecker by markmark on Sunday June 03, 2018 @10:29PM (#17224081)
Yes, that's exactly my point. Right them down in your program so that the compiler can check them rather than holding them in your head.
Re:Stripe is building a Ruby typechecker by wtetzner on Friday June 08, 2018 @09:20AM (#17264985)
Sorry, I misunderstood your comment.
Re:Stripe is building a Ruby typechecker by pg_bot on Sunday June 03, 2018 @05:28PM (#17222273)
I would disagree with the statement that coding is faster in statically typed projects. The ease of onboarding new devs is solely based on the code quality of the project. Well written programs are easy to understand regardless of typing. Terribly written programs are opaque regardless of typing.
Re:Stripe is building a Ruby typechecker by eropple on Sunday June 03, 2018 @07:35PM (#17223153)
Those Scotsmen are pretty untrue, huh?

The claim is pretty facially silly at a glance besides, though. You literally don't know the fields and methods, to say nothing of what they actually give you, on a Ruby object without opening either the code or pulling up Pry and doing `ls`. Which I have done, often enough, to fail rather stunningly to miss doing so when in Kotlin or when using TypeScript. Checked that one? Good news--now you get to drill down into the next one, and the next one. I hope that isn't coming from another library, too, 'cause jumping from library to library in Ruby or Python is a chore. And even if not? God help you if you're using ActiveRecord, I hope you enjoy scanning your database migrations or describing tables just to learn method names.

It is a bad scene. And don't get me wrong; I like Ruby quite a lot. But I won't make excuses for it.

Personally, with the actual tooling available to modern systems, I write TypeScript much, much faster--we're talking probably twice as fast--than I do even ES6, which I otherwise quite like. And TypeScript can't even assert whether something is a whole number or not, unlike better languages. It has replaced Ruby for me on the strength of that alone.

Re:Stripe is building a Ruby typechecker by Tehnix on Sunday June 03, 2018 @06:25PM (#17222689)
Sure, any code base can be horrible to learn, but two equally well written code bases, types can help significantly. When your new employee can be confident that changes something in one place, won't invisibly break something in another place, they are more prone to start making changes.

Vimal Kumaar touches on how it has helped them get employees contributing to the code a lot quicker, after they moved to PureScript https://www.youtube.com/watch?v=HLEwYghBjo8 (I think around 24+ minutes in, but I recommend the whole talk).

Re:Stripe is building a Ruby typechecker by matchbok on Sunday June 03, 2018 @07:07PM (#17222974)
If I have to connect a couple classes in separate files with a few objects/stuff inside of them, I'd bet good money that a statically typed language will provide a faster coding experience. Especially if you have leveraging third party libraries. Working in huge libs in JS (Sequelize comes to mind) is a horrible development experience that requires you to have the documentation open.
Re:Stripe is building a Ruby typechecker by Tehnix on Sunday June 03, 2018 @06:21PM (#17222653)
What languages have you worked with before, with static types?

If it's something like Java, C, C++, etc, then I can see your point, but if you pick any of the languages with type inference (like Elm, Haskell, PureScript, OCaml, F#, etc), then you rarely actually have to write types.

Working with the type system is a different way of working. It's more beneficial to see the compiler as a helping friend, instead of an adversary that is just there to complain.

Some interesting reads might be:

- http://elm-lang.org/blog/compilers-as-assistants

- https://matthew.brecknell.net/post/hole-driven-haskell/

- http://bitemyapp.com/posts/2017-09-23-please-stop-using-type...

Personally, I honestly hate every time I don't have a time system to rely on. I don't make any false pretenses that I have the whole program in my head 100% of the time. I don't want to have to think about things that a computer can solve for me, hence I like my compiler to do as much work as possible.

As for unit testing, a type system is never supposed to remove the need for unit testing, and if you see anyone promote a language because of this, they are probably (hopefully) over simplifying. What it does do though, is significantly cut down the need for certain types of tests, since you can model so much more logic via types (ADTs, Union types, etc), and get it checked by the compiler.

As an aside: I simply do not believe you've never run into a type error, unless you've only written projects that 100 lines of code, and even then it's quite easy to run into type errors.

Re:Stripe is building a Ruby typechecker by pg_bot on Monday June 04, 2018 @05:58AM (#17226203)
The languages that I've used with static typing are Java and Objective-C so perhaps those languages have negatively impacted my perception of type systems. I can do more research on other languages to see what they have to offer.

I used to run into type errors when I first started programming but I've learned how to eliminate them by changing my programming style. I add a lot of constraints to how I program, and follow a system of naming conventions that make it obvious what type something is.

I take a lot of pride in my work and try my best to build maintainable systems that can be extended easily or run forever without changes. I typically write around 250K-350K lines of code per year in mission critical and highly regulated industries. If you want to learn how to write systems that have zero defects research companies that are known for quality design and apply their principles to your own work. I would suggest Netflix, and Toyota as the two companies that I would emulate.

Re:Stripe is building a Ruby typechecker by emodendroket on Monday June 04, 2018 @10:38AM (#17228139)
> I add a lot of constraints to how I program, and follow a system of naming conventions that make it obvious what type something is.

And you find it unbelievable that someone would prefer that the compiler simply enforce these conventions?

Re:Stripe is building a Ruby typechecker by pg_bot on Monday June 04, 2018 @11:05AM (#17228423)
I don't find it unbelievable, I just personally don't get the appeal because you have to do that work when you name things anyway. e.g. I would never expect a variable named "first_name" to be anything other than a string. It's also fairly easy to handle most type conversions so I would rather be permissive in what I accept (to a reasonable point) than be rigid.
Re:Stripe is building a Ruby typechecker by emodendroket on Monday June 04, 2018 @11:32AM (#17228746)
Well what are the properties of config_options or app_user or objects like these? Is it even documented, or am I forced to scan the entire method trying to figure out?
Re:Stripe is building a Ruby typechecker by pg_bot on Monday June 04, 2018 @12:51PM (#17229710)
Typically I would initialize an AppUser object and print out its default representation. You can quickly find info on an object by doing something like:

    AppUser.new 
      => prints all properties of the object with nil values 

    AppUser.instance_methods - ActiveRecord::Base.instance_methods 
    => prints all unique instance methods on that class
values

config_options is extremely generic but I would expect that it is a Hash of key/value pairs. Given the fact that it has options in the name you are likely going to have to look it up regardless as you have multiple choices when using it. I'd expect some documentation if it is truly configurable, or you can transparently look at the method signature if it uses keyword args. (say for a library that handles formatting currency)

Quickly reading other people's code is a definite skill. While it can be a pain to do, it is worthwhile since the code is the only real source of truth.

Re:Stripe is building a Ruby typechecker by emodendroket on Monday June 04, 2018 @12:54PM (#17229743)
Yeah, of course there are ways of doing it. But if you define types you can in a second be looking at all the possible values. The tools help you be more productive and make fewer mistakes.
Re:Stripe is building a Ruby typechecker by veebat on Sunday June 03, 2018 @06:31PM (#17222741)
Well, what kind of projects? And what order of magnitude big?

Whether dynamic type errors become an issue depends a lot on how often all codepaths are run.

If what you're running is a batch processing script, it's likely to crash out as quickly as a type-checking compiler, and then static types have no direct appeal.

On the other hand, if it's a long-running server with a lot of finite state machines(maybe it's running a multiplayer game or something) it's really hard to reach type errors without an extensive manual test.

This becomes a relatively bigger issue as the codebase gets bigger, again depending on the type of code. If the main way the system expands is by handling a more diverse set of data types, dynamic types allow less code to be written, but also make it harder to verify.

In practice what I tend to see happening is that a glue layer appears that needs dynamic behavior, while the codepaths underneath that benefit more from static typing.

Re:Stripe is building a Ruby typechecker by rickyc091 on Sunday June 03, 2018 @07:19PM (#17223046)
The usefulness really depends on the team. If you're working with another engineer or two and they're all senior engineers that you've coded with for a while, then it's probably not necessary since you'll understand each other.

However, if you work with a junior team or you have to inherit a project, then I've found static typing to be extremely useful. One might argue that code review is suppose to solve for that, and while you can catch some of the problems, you won't catch all.

It's definitely helped to make refactoring faster. Specs will help to some degree, but static typing will traverse through every function to ensure the parameter you're passing is as expected.

No more is this suppose to be a nil, a blank value? You can specifically define what you expect. While some people hate optionals with Swift, I've found it to be an interesting concept.

Re:Stripe is building a Ruby typechecker by bastawhiz on Sunday June 03, 2018 @07:50PM (#17223243)
I started working with TypeScript over vanilla JS a year or so ago. It's completely changed the way I work. Having autocomplete, pointing out silly errors (forgetting to return a value, forgetting to set a prop on a React component, forgetting to add a member to an object) before I refresh the page, and being able to pick up old code without having to reread through it to figure out what the hell it actually spits back out is a godsend. The latter has sped up my productivity significantly; being able to get the output from a library, hover over the variable, and see the exact shape of the output saves an incredible amount of time when doing mundane day-to-day tasks.
Re:Stripe is building a Ruby typechecker by kjeetgill on Monday June 04, 2018 @03:17AM (#17225325)
You've gotten a lot of responses but let me throw one more idea at you: bad or mediocre code bases. Or old codebases that have the scars of years of tweaks, fixes, and hacks. Thats where I think static types shine the most.

Comparing my Python and Java experience, jumping into the middle of a codebase and correctly untangling a few particularly problematic spots or reworking and refactoring packages without introducing errors is dramatically easier with static typing.

It's feels like the difference between untangling actual wet noodles vs solving a sliding block puzzle. It's just more mechanical.

Even BEFORE running tests there is a lot of confidence that you haven't overlooked something. Hell, you can't catch typos in python without 100% code coverage. The sanity bar is just that much higher before you even get to unit tests.

Re:Stripe is building a Ruby typechecker by zxcvhjkl on Monday June 04, 2018 @03:39AM (#17225423)
For me, static typing actually makes it easier and faster to write code. It’s like someone looking continuously over my shoulder for mistakes.

I am the least efficient when I write code in JS.

On the other hand with Ruby, and meta programming, I can do stuff that would be impossible to express in the most popular type systems.