News for hackers. Stuff that matters.
Re:Announcing TypeScript 2.0 by jeremiep on Thursday September 22, 2016 @03:56PM (#12559809)
I feel this is just a myth.

I'm constantly looking at the source even with static types. Unless you're having a Haskell-like type-system the function's signature will still miss most of what the function is actually doing.

How do I know if a function does a network call? Saves a file? Changes the DOM? These are really important things to know when calling code and the type-system is completely oblivious about them.

What I usually see however is that projects using static types frequently have at least twice the team size as the equivalent projects using dynamic types. Communication overhead follows, ownership fades and debt creeps in quickly. After a few month they usually have no traces of agility left.

Re:Announcing TypeScript 2.0 by spion on Thursday September 22, 2016 @07:41PM (#12561261)
> How do I know if a function does a network call? Saves a file?

It returns Promise<T>

> Changes the DOM?

It doesn't. React does that. ;)

Basically, TypeScript + React + a mostly purely functional style with a sprinkle of side-effecting IO is a really, really good combination.

Also, I find the argument a bit silly. "This cycling helmet doesn't protect your knees and elbows and spine, so its completely useless and you can remove it!"

Re:Announcing TypeScript 2.0 by jeremiep on Friday September 23, 2016 @09:54AM (#12564602)
> It returns Promise<T>

That still doesn't say anything; is the action referentially transparent? is that a delay? a network call? All a Promise tells me is that the result will come at a later point in time.

> It doesn't. React does that. ;)

My point was about side-effects and complexity in general which the static type-system is generally very clueless about. React is a runtime and dynamic solution to that problem; types aren't really useful here :)

Besides, you're most likely using React with Immutable.js and having some pattern like Redux on top. Which is basically choosing immutability and hostility to state over static types :)

> "This cycling helmet doesn't protect your knees and elbows and spine, so its completely useless and you can remove it!"

That's not what I meant, its more like "why wear winter clothes in the summer?"

Re:Announcing TypeScript 2.0 by spion on Friday September 23, 2016 @02:43PM (#12566979)
> That still doesn't say anything; is the action referentially transparent? is that a delay? a network call? All a Promise tells me is that the result will come at a later point in time.

Promise<T> is like Haskell's IO<T> in terms of what it says. In short, "anything goes"

> My point was about side-effects and complexity in general which the static type-system is generally very clueless about. React is a runtime and dynamic solution to that problem; types aren't really useful here

> Besides, you're most likely using React with Immutable.js and having some pattern like Redux on top. Which is basically choosing immutability and hostility to state over static types :)

Why is everyone always making it an "either or" thing? The usefulness of types is in them describing the input/output dependencies in your code. Change the nature of your inputs, and it tells you what dependencies, or dependencies of dependencies (etc) will be affected. Change the nature of your output, and you get the same for your dependants. This is mainly what TypeScript gives you: it tells you how your modules are connected.

Immutability wont help you with the above. If in the return result of the exported function `f` from module `A`, I change this attribute from "firstName" to "name", who will be affected? TypeScript can tell you things like: `A.f` is called by `g` from module B, which then passes the data unmodified to `C.h` which then tries to access the `firstName` attribute. Voila, now you know. Now, how will immutability, hostility to state or unit testing help you with this question?

Re:Announcing TypeScript 2.0 by jeremiep on Friday September 23, 2016 @03:40PM (#12567378)
> The usefulness of types is in them describing the input/output dependencies in your code.

I agree, but I find types way too weak in that respect. Its not enough to know a function accepts ints; I want to know its range as well.

I spent so many weeks hunting down overflow and out-of-range errors and null pointer exceptions that types feel like an illusion of robustness at best.

> Now, how will immutability, hostility to state or unit testing help you with this question?

Not that much, I'll give you that. But the same is true for a function whose range was 1-20 being refactored into a range of 1-10; types won't catch that.

I used to like types, then testing, now I'm looking at specifications I can write once, compose and then generate assertions, documentation, test data and everything else from. Its by far the best ROI of the three.

Re:Announcing TypeScript 2.0 by spion on Saturday September 24, 2016 @01:54PM (#12571846)
> Its not enough to know a function accepts ints; I want to know its range as well.

Types actually help with this too. Instead of changing the possible range of a thing, change its name too: the compiler will quickly let you know of all the places that depend on it. Now you know what to check.

Re:Announcing TypeScript 2.0 by Too on Friday September 23, 2016 @12:51PM (#12566025)
Because winter is coming.

It's easy to read code you wrote yourself 5 minutes ago, try again in 6 months.

Re:Announcing TypeScript 2.0 by jeremiep on Friday September 23, 2016 @01:06PM (#12566158)
Simplicity will help me understand my code 6 months down the road; everything else is superficial and noise in comparison.

You can't hold more than ~7 things at once in your head; once things are that simple you can see bugs a mile away, types or not.

The inverse is not true; types won't help you juggle 15 things at once and bugs will happily slide through the cracks. You're going to forget your codebase, types or not, and when you come back to it only simplicity will help you quickly figure out what you were doing with it.

Re:Announcing TypeScript 2.0 by spion on Saturday September 24, 2016 @04:59PM (#12572619)
I used to think like this, and I was wrong. As you add code to a software project, some of this code will be written when the problem is not well understood; thats inevitable. The solution will then need to be refactored or rewritten, the first of which is extremely painful in a dynamic language, even if you keep things simple.

For example: if you implement a store that only sells electronic books will have a lot of assumptions regarding the selling and delivery process. Later the business wants to start selling physical things and needs to handle stuff like shipping costs, tracking and so on.

For problems like online stores, the possible directions in which they can develop are well understood and its easier to plan ahead. For most other things, its not, and the ability to reorganise code to be usable in different ways is invaluable.

Re:Announcing TypeScript 2.0 by leshow on Thursday September 22, 2016 @11:55PM (#12562198)
React is not "functional". You extend the Component type just to make a view, you can encapsulate local state, you can inherit functions, yadda yadda. Calling it a "component" doesnt make it any less OO
Re:Announcing TypeScript 2.0 by spion on Friday September 23, 2016 @05:38AM (#12563375)
In terms of DOM manipulation, yes it is. The render function is pure.
Re:Announcing TypeScript 2.0 by leshow on Friday September 23, 2016 @10:03AM (#12564667)
No, you can choose to write it purely, but it's not pure by default.

You can see that here: https://facebook.github.io/react/docs/pure-render-mixin.html

"IF your React component's render function is "pure""

nothing stops you from writing impure rendering functions. You can delete and manipulate elements at will.

Re:Announcing TypeScript 2.0 by spion on Friday September 23, 2016 @01:28PM (#12566362)
Yes, but thats not how the render function is supposed to work. Its a function from state/props to a VDOM tree. In contrast, direct DOM manipulation is meant to be stateful.

For some reason, everyone always likes dealing with absolutes. Thats not how things work

* "Tests wont exhaustively check everything!"

Yes but they exercise the common cases, and the cases where the code will trip-up in real use are rare if the code is decently covered with tests.

Yes, its still possible to encounter edge cases. If it looks like that might be the case, add fuzz testing and property testing too. Pick the tool.

* "Types wont detect all errors!" -

Yes but detecting some errors is still useful. They mostly track dependencies between parts of the codebase: they determine how modules talk to eachother. This is useful, especially when I'm reorganizing code.

Also, its exactly where unit test fail to help, due to mocks: if I change module M, i don't know whether its dependencies are affected or not without looking at all of them and checking their mocks of module M. The situation gets even worse for second-level dependencies, and so on.

* "Unsound type systems are useless!" - No they are not. Not if its possible to isolate unsound usage and "hand-prove" it by carefully checking it. There is still value there: you can write things that the type system doesn't know are sound and hand-check them (by paying with more effort), or you can write things that it does know are sound, and enjoy the type system's ability to help you avoid errors.

* "Soundness isn't very important" - It depends. Is this unsoundness pervasive, like the null/undefined unsoundness? Maybe its useful to fix it then.

There are no absolutes.

Re:Announcing TypeScript 2.0 by leshow on Tuesday September 27, 2016 @10:11AM (#12589678)
> Yes, but thats not how the render function is supposed to work.

If you weren't supposed to do it they wouldn't give you functions to do it.

I'm not 'dealing in absolutes' I'm applying the definition of pure to what React is, and it isn't pure.

The rest of your post I don't follow, you're just talking to yourself, I haven't made any of these claims.

Re:Announcing TypeScript 2.0 by spion on Tuesday October 04, 2016 @03:02PM (#12638317)
Yeah I suppose I am talking to myself. I'll try to stay on topic.

With the browser DOM model, end-users perform the DOM mutations. This generally means that they must keep the application state in sync with the DOM state, manually.

React's VDOM model encourages pure render functions, since a new VDOM is constructed every time and mutations are performed by React itself.

Also, nothing stops you from writing impure functions in PureScript either. You could define FFI functions that claim to be pure but aren't. I guess PureScript isn't pure then? Oh, and Haskell isn't pure due to unsafePerformIO. So nothing is absolutely pure; the question is what style is generally encouraged by the design of the framework/language, and to what degree. (there are no absolutes)

And PureRenderMixin isn't default because it does a shallow reference comparison on props/state, which only works reliably for immutable data structures. If all JS datastructures were immutable, it would've been used everywhere. However thats unrelated to whether `render` is pure.

Re:Announcing TypeScript 2.0 by qwertyuiop924 on Friday September 23, 2016 @01:22PM (#12566312)
Well, yes, but it's commonly written in the functional style.
Re:Announcing TypeScript 2.0 by mschulze on Thursday September 22, 2016 @04:02PM (#12559861)
I agree (from my experience). That's mostly the fault that even with static types interface design (e.g. in Java: public methods and public classes) is still hard and most developers are not good at it.

For me, a lot of the Spring classes are designed very well. When working with them I don't often need to look into the source code. Very often just looking at the methods (by using autocompletion) is enough.

Re:Announcing TypeScript 2.0 by LeanderK on Thursday September 22, 2016 @04:25PM (#12560064)
maybe its just what your used to. Most of my time I code in Java (and a bit of Scala) and i only look at the source code as a last resort. This is not really possible with JS. But i imagine with a lot of background in dynamic languages you instinctively look at the source-code and therefore not use the types that much.
Re:Announcing TypeScript 2.0 by jeremiep on Thursday September 22, 2016 @04:35PM (#12560145)
I looked at SO much Java sources because the method signatures weren't complete enough.

I would never have been able to integrate netty into our game servers that optimally with only the docs as reference for one. Yet its documentation is really, really good. I still wanted to know its internals in order to hit the fast paths.

Whether you're using static or dynamic types, the very same holds true to build robust software: understand what you're doing.

Managing complexity and reducing state will always be the biggest factors to quality, regardless or type systems.

Re:Announcing TypeScript 2.0 by mercurial on Friday September 23, 2016 @12:25AM (#12562302)
Well, considering the number of dependencies a typical web project has, I can tell that I'm far from understanding the internals of every library used in our codebase. I mean, of course you'll want to do that in some cases where performance is really important, but generally speaking type signatures and docs should be enough.
Re:Announcing TypeScript 2.0 by LeanderK on Saturday September 24, 2016 @06:46AM (#12570399)
i din't say that i don't look at source code, but not intuitively. I look at it when the method is very confusing, or i have to optimise one path, it is undocumented and important etc. What i wanted to say is that types give you a pretty good first intuition to what the method does and how (including exceptions). They help me navigate my way through the code, especially with DSL like the excellent jooq (http://www.jooq.org)
Re:Announcing TypeScript 2.0 by qwertyuiop924 on Thursday September 22, 2016 @05:26PM (#12560504)
...And I hate java (for perverting OO, and being annoyongly verbose), and come from a highly dynamic background.

It's ultimately a matter of preference, though.

Re:Announcing TypeScript 2.0 by LeanderK on Saturday September 24, 2016 @06:50AM (#12570406)
not that java is my favourite language, i would even say that i despise it. But its here to stay and the discussion was about shitty static type-systems where Java is the poster-boy ;)
Re:Announcing TypeScript 2.0 by qwertyuiop924 on Saturday September 24, 2016 @03:10PM (#12572123)
It's not even the shitty type system: C's is arguably even worse.

No, it's the fact that it's effectively the new COBOL.

Re:Announcing TypeScript 2.0 by Roboprog on Sunday September 25, 2016 @01:17PM (#12576216)
Java: the language so ugly it has to wear a (IDE plugin) bag over its face while you're doing it.

Yes, I'll go have that talk with H/R now...

Re:Announcing TypeScript 2.0 by tqkxzugoaupvwqr on Thursday September 22, 2016 @04:03PM (#12559874)
I think mschulze means he cannot even be sure what the function returns without having to read the source code. There could be comments but they may be outdated or incomplete. In statically typed languages you can look at the function signature or rely on the compiler errors.
Re:Announcing TypeScript 2.0 by jeremiep on Thursday September 22, 2016 @04:12PM (#12559948)
Yes but my point was that this is very incomplete information to do engineering with. You're still going to look at the source to learn what side-effects are present or how your arguments are used.

Not taking these details into account will be the source of most bugs :)

Re:Announcing TypeScript 2.0 by trobertson on Thursday September 22, 2016 @04:56PM (#12560308)
A good type system will expose the existence of side effects. However, it is true that good type systems are very rare in industry.