8 ms·
> unimaginable I imagine adding types gradually as a design solidifies, rather than slow velocity early on. Best not to be dogmatic on these things.
by mixmastamyk 8y ago
> unimaginable
I imagine adding types gradually as a design solidifies, rather than slow velocity early on. Best not to be dogmatic on these things.
- echelon 8y agoYou'll find that the more you work with types, the less this becomes an issue. You begin to think in types as a first class construct. Types don't slow me down, and I can't imagine working without them.
- mixmastamyk 8y agoYou also have to type, refactor, and test them. I work in multiple languages and the typed are definitely slower at the beginning, but pay off later. The strategy I outlined is the way to get the best out of both.
- Normal_gaussian 8y agoAlso working in both I don't have this issue. I generally find types make refactors faster - I have less bugs from the refactor.
- mixmastamyk 8y agoA mature refactor yes, a change in design often not.
- lopatin 8y ago> types as a first class construct A wild Idris programmer appears
- marcosdumay 8y agoWell, imagine type-first programming, where you design your system first just by writing the types, look how it works, and only when satisfied go bother with implementation. I'm not sure TypeScript is good enough for doing that (I don't know TypeScript that well), but it's simply much better than starting with code.
- _bxg1 8y agoTypeScript works reasonably well for this approach; it's how I tend to do things. It has some gaps when you want to do really advanced stuff, but it gives you tools like typecasting for crossing those gaps. One of the great benefits of JavaScript type systems is that since they're overlaid on a dynamic language, you can just "turn them off" as needed (when the type system fails to understand that what you're doing is safe). You can comment out type checking for a particular line, or even let your whole project successfully build while type errors remain. The type system then becomes purely a tool, and never a roadblock.
- wincy 8y agoI recently had to write a tool to output a Swagger file from a proprietary api testing format, and writing all the interfaces for Swagger based on the Swagger specification was hugely helpful. I’m not sure I would have been capable of completing the project without TypeScript. Also coming from JavaScript development first, TypeScript made learning C# and templates a breeze.
- z3t4 8y agoWhat if the specification changes ? Being static is has both advantages and disadvantages. You can do the checks without running the code, but it doesn't guarantee run-time correctness. I think a better strategy is to type check the actual code via inference, maybe adding some doctype comments to help the static analyzer, then add run-time checks where things are likely to break. And you can make your API easier to use by checking the parameters, throwing helpful and descriptive errors, allowing several different types as input, so the user doesn't have to convert his/her model to your model.
- rspeele 8y agoThe spec changing is the best part! (Or conversely, the worst part when you are 100% dynamic). You change your types to match the new spec (eg adding a case to a discriminated union) and you immediately get feedback on places in your code that are definitely wrong/incomplete now. It won’t find every change you need to make but it’s a big load off and frees up some cognitive capacity for what’s left.
- mattmanser 8y agoIt doesn't as you've already made that decision when adding a property. Almost always you get rid of the property entirely and replace it with a new one (and the type), you extremely rarely change the type. And you will almost always know what type a property needs to be. Name? string. IsActive? boolean. Last modified? Date. Etc. Also typescript just has number, so you're not even faffing around thinking "int, float, long, double, decimal, unsigned, signed" when adding a number. Although this is ultimately a bad thing.
- mixmastamyk 8y agoIt does, I’m talking more about module/system architecture than properties. I might go through three designs on a brand new project and futzing with types and tests while factoring it is an inefficient use of time. Waiting until satisfied with design is my advantage.
- Retozi 8y agoI have never understood why typed languages make you slower at any point in time (early, late etc.). Because you have to hit more keystrokes to write your program? That doesn't compute. typing is the thing you do the least amount of when programming. In all best practices we are taught to not save keystrokes. Name your variables expressively. write small functions. document code. Write tests. All ""excess"" keystrokes nobody questions. But when you have to type " ... : number" it's slow velocity? In my opinion people vastly over-estimate productivity boosts of saving keystrokes. It's the tedious, boring part of the work that you would like to skip entirely, hence excess keystrokes feel way more "slowing you down" than they acutally are. Although it doesn't matter, you actualy save keystrokes: autocomplete, auto-refactors and less low level unit-tests compensate the couple of type annotations easily.
- williamdclt 8y agoI completely agree with you, but the criticism isn't usually with typing number, it's typing complex higher-order functions or this kind of things. Where the time lost isn't in typing out the code, but in understanding what the type should be or (worse) what does this cryptic typing error means
- weberc2 8y agoI don’t tend to write or encounter many complex higher order functions in other languages. Are they common in JS?
- nurettin 8y agoIt is not the typing per se. Anecdotally, I started adding types to my python code and it is somewhat useful. That usefulness is diminished when you are fighting the type system instead of getting things done. Like when you have to make exceptions in typescript by using Any. Like when an interface for a js library is missing and you don't want to do all that work. Or when an API returns a field with a different type in between two calls and you have to make exceptions in the code when parsing with jackson in java.
- 8y ago
- weberc2 8y agoWhy do you imagine types slow velocity? My experience is the opposite. I occasionally prototype in Go and then backport to Python (to integrate with our application) because I can iterate so much more quickly (yes, Python has type annotations, but the ergonomics are poor and the type checker is immature).
- mixmastamyk 8y agoExperience. Again, not talking about a mature project, but a new one in the design phase. Types (like unit tests) are extra work at this point until a good design is discovered. Which takes time to think about.