4 ms·
Yes, some programming languages take this approach but I don't think that prototyping is as easy in such languages as it is in a dynamically typed language (e.g
by amelius 7y ago
Yes, some programming languages take this approach but I don't think that prototyping is as easy in such languages as it is in a dynamically typed language (e.g. Haskell vs Python).
- rwmj 7y agoWhen writing OCaml, if I'm unsure of the type I set the type to some impossible value, compile it, and the compiler tells me what the type really is.
- hnra 7y agoI Haskell you simply put a "_" in the annotation and the compiler suggests the correct type.
- dllthomas 7y agoYou can also do this with values, asking "what goes here?" - it's great.
- andrepd 7y agoAlternatively, merlin can tell you the type of the expression under your cursor, besides also flagging type mismatches like your situation.
- yakshaving_jgt 7y agoIn my experience (currently writing Haskell professionally, previously writing Ruby professionally) prototyping is easier in Haskell. How many systems have you prototyped in Haskell?
- dllthomas 7y ago> prototyping is easier in Haskell That's very much my experience, as well. Assuming - and it's a very big assumption - that your use case has equivalent library support.
- zitterbewegung 7y agoWhat would be neat is if you could take a Python program and run type inference on the program and it would output a type annotated version of the code.
- duckerude 7y agoI don't have experience with it, but pytype can do that: https://github.com/google/pytype https://github.com/google/pytype After typechecking it leaves provisional stubs in .pytype/pyi/, and it has a tool to merge them into the original code. mypy has stubgen: https://mypy.readthedocs.io/en/latest/stubgen.html https://mypy.readthedocs.io/en/latest/stubgen.html As far as I know it's less powerful since mypy isn't really built for unannotated code and pytype is.
- hopia 7y agoProductivity can be really subjective. Those that are used to modeling the problem domain with the type system find that their most productive approach, even with prototyping.
- dllthomas 7y agoRight, and the type system is such a big help in refactoring - especially in small projects - that you don't have to be all that right in your first N cuts at the model. You can write code and find out where you're wrong, and fix it fast.
- pwm 7y agoIt’s even more help in larger projects :) The dividends of type-checher aid refactoring really start paying off once the project is above a a certain size/age.
- dllthomas 7y agoYeah, I think I was unclear. Given a need to refactor, it's a bigger help on a bigger refactor. But a large refactor on a large project is still a pain. By the time you get there, you still want your model stable and/or flexible enough that you don't need to do that much. On a small enough project, every refactor is easy enough that you can lean into it. Make a bunch of assumptions you're not confident about, setting up the types so you're sure you'll know what needs fixing when they're wrong. Then you test those assumptions as you write - and run - more code.