News for hackers. Stuff that matters.
Re:Fear, trust and JavaScript: When types and functional pro... by arcticbull on Saturday October 27, 2018 @05:53AM (#18315073)
I did Objective-C work for a decade under such conditions. It's never enough to have tests and code reviews. Static typing is strictly better.
Re:Fear, trust and JavaScript: When types and functional pro... by Tade0 on Saturday October 27, 2018 @06:04AM (#18315106)
I worked on a 150k LOC pure JS codebase for almost two years and my experience is different - if tests aren't enough then they're either not written well enough or there isn't enough of them.
Re:Fear, trust and JavaScript: When types and functional pro... by arcticbull on Saturday October 27, 2018 @02:00PM (#18316873)
Think of all the time you wasted writing unnecessary tests that the compiler could perform automatically on your behalf by you properly specifying your types. You'd be much more productive and confident, and have less LOC to maintain. Refactoring would be much easier too.
Re:Fear, trust and JavaScript: When types and functional pro... by Tade0 on Saturday October 27, 2018 @04:16PM (#18317467)
No type system would measurably help in this case since we necessarily had to deal with browser behaviour which wasn't exactly standardised and tended to change from version to version.
Re:Fear, trust and JavaScript: When types and functional pro... by tempodox on Saturday October 27, 2018 @06:43AM (#18315212)
You would never be able to write the infinite amount of tests necessary to supplant static typing, let alone run them.
Re:Fear, trust and JavaScript: When types and functional pro... by qwer on Saturday October 27, 2018 @12:02PM (#18316311)
Well don't lose sight of the goal. The goal is less bugs. Static typing is just for internal quality. Users don't give a rat's ass if your types are correct as long as the program works. Proof: Many wildly and massively successful programs are duck-typed.

Nobody ever cared to use tests to replicate what a type system does. That's a straw man. Tests go straight for the actual goal by testing actual values. Correct values are what are necessary. Types on the other hand are neither necessary nor sufficient.

Re:Fear, trust and JavaScript: When types and functional pro... by TimJYoung on Saturday October 27, 2018 @12:21PM (#18316397)
"Static typing is just for internal quality."

Frankly, I don't even know what to do with such a statement. What is your definition of "internal" ?

I just did a very large re-factor of a codebase a few days ago where I changed a lot of event handler (method) types in a codebase of around 200K lines of code (Object Pascal). This means that the method signature of every single event handler could have been wrong in some way if I made a mistake, and it would have introduced a pretty egregious, non-internal bug in every case. How would you test such a massive change without replicating every single thing that a static type system and compiler already do for you ?

Re:Fear, trust and JavaScript: When types and functional pro... by tom_ on Saturday October 27, 2018 @03:04PM (#18317202)
This has been my experience too. I've done a bunch of these sorts of changes over the years in C++. It's very straightforward: break code, fix errors, run code, fix remaining bugs (if there are any), commit code.

None of these projects had unit tests, but that's fine - you don't really need them for this sort of modification, just some patience, a tolerance for boredom (that, or the ability to suck it up anyway), and a complete lack of concern about messages such as 'ERROR: 0/1,577 file(s) built. NOTE: Error limit exceeded - only showing the first 99,999'.

Re:Fear, trust and JavaScript: When types and functional pro... by qwer on Saturday October 27, 2018 @03:59PM (#18317407)
Well let me first remind you that you're in a javascript thread. OO Pascal is strict enough that you're not going to get the opportunity to see things work when they get types that they didn't expect because the compiler is unforgiving. So that's going to be hard for you to imagine, but it happens in javascriptland. A function in javascript meant to take a number to output "X hours ago" could very easily get the string "3" and still do exactly what the user expects. That's what I mean by an incorrect type that is internal only, and not a user-facing bug. This is an overly simplified example too. With duck-typing you can often get away with all kinds of not-the-type-that-the-method-expected and live to tell the tale.

I haven't touched OO Pascal in 15 years, so I can't speak to how you would write tests for it, or if there's even a testing framework. I will tell you that I left the if-it-compiles-it-works attitude around that time too though.

Re:Fear, trust and JavaScript: When types and functional pro... by TimJYoung on Sunday October 28, 2018 @05:13AM (#18319802)
Yes, I understand how JS works. My company markets and sells a web development IDE that includes an Object Pascal->JS compiler.

Re: your definition of "internal": I suspected that this was what you meant. I also disagree with this particular version of "correctness". If the developer intended that a particular function accept an integer, then accepting anything else is essentially a bug, and the fact that it works at all is down to pure coincidence.

As for writing tests in OP: you write tests in the same manner that you do with Java, C++, C#, etc.

Re:Fear, trust and JavaScript: When types and functional pro... by arcticbull on Saturday October 27, 2018 @02:03PM (#18316884)
Internal quality is external quality haha. If your types are wrong your program is wrong, and if it just happens to work now wait until more people use it, or you refactor it, or you change the way it works. Your users are basically just fuzzing machines haha.

Your statement that "nobody ever cared to use tests to replicate what the type system does" is trivially false, have you ever tested what happens when you pass "null" into a function that probably shouldn't take null? If so, you just did. Some type systems allow you to even specify valid subranges of types, and combined with algebraic data types, it's effectively impossible to misuse.

Re:Fear, trust and JavaScript: When types and functional pro... by qwer on Saturday October 27, 2018 @03:46PM (#18317370)
> If your types are wrong your program is wrong

That's not necessarily true though is it? If the "1" in the "1 hour ago" message in the header of your reply wasn't the expected type of the writer of the output function but ultimately still shows up as "1 hour ago" to the user, there's no user-facing defect. I can promise you that this happens all the time in javascript. You're in a thread about Javascript.

> have you ever tested what happens when you pass "null" into a function

Not that I recall. Javascript will throw an appropriate error when it detects that your duck isn't quacking correctly. No one writes validation logic everywhere on internal units, so there's no functionality to verify with a test.

With that said, null is decidedly not "just a type". It's also a value. I generally avoid using null everywhere as much as possible too, because it's a pretty terrible concept.

> Some type systems allow you to even specify valid subranges of types, and combined with algebraic data types, it's effectively impossible to misuse.

Sure but you're in a thread about javascript and typescript. And let's be honest: the vast majority of type systems do not support that.

Re:Fear, trust and JavaScript: When types and functional pro... by qwer on Saturday October 27, 2018 @12:05PM (#18316322)
This sounds like an if-it-compiles-it-works argument.