4 ms·
>when not to use static typing I'll bite. When should static typing not be used? (Note: I agree with your general point)
by macspoofing 6y ago
>when not to use static typing
I'll bite. When should static typing not be used?
(Note: I agree with your general point)
- yashap 6y agoWhen I’m throwing together a quick script, or maybe some minor piece of automation, Python is my go-to language. For any decently large project, though, I prefer static typing.
- karatestomp 6y agoI'd kinda prefer it then, too. If it's short and I'm just scripting stuff up it's probably mostly calls to existing code (libraries) so almost all the static typing would do is tell me when I'm screwing up and give me hints for valid arguments with types and names, with little or no added overhead. It'd be very nice.
- MaulingMonkey 6y agoConsuming types in that context is nice, defining them is what's generally a PITA / extra boilerplate / overhead. To take a concrete example that could go both ways: Say you want to parse a JSON blob for some task. On the one end, you could access it through dynamic typing, or tools like jq, that don't need a schema for the entire data format. At the other extreme, you could make typescript definitions defining a schema for the entire format. The more the same data gets (re)used, the more worthwhile taking the time to define a full schema is. But to download and add type definitions (often out of date and in need of further tweaking) for every once-off API request? Way more effort than it's worth.
- seer 6y agoMost static type systems do not force you to say what’s the entire shape of the data, just what the shape of the data you need is. In fact its a good practice to do in general. So that when processing the json blob you tell what only your processing requires. What you get is that if for example you do your validation, but then by chance you touch more data that you’ve checked for, the types will tell you you are dangerous waters, and you can go update the validations. This is especially useful if you’re not the original author or if you’ve written it several months back and don’t remember the details. Static types are really cool that way, and can be treated as just a faster to write and faster to run and always up to date unit test.
- ergothus 6y agoWhen the communication loss (visual noise) from the added static typing info is of bigger impact than benefit type safety offers you. All of which depends on a lot of variables.
- hedora 6y agoMy heuristic is that if anyone else will ever read the code, it should be statically typed (or be written in a language like shell where the language is essentially limited to one type). Most people disagree, but then they end up writing giant python monoliths with layers of implementation inheritance, dependency injection and functional programming paradigms. In the end, they try to port it to pretty much any other language, but at that point it’s too late.
- empthought 6y agoPython has a pretty good type checker.
- jbreiding 6y agoFor me it's where I'm developing a task to do stream processing and classify the data by an arbitrary subset of the data and don't want to model the entire structure to avoid losing/changing the original data structure. I'm sure there's better ways to do this, but that's an example I'll throw in.
- kobalsky 6y agoMany AAA games implement their engines in C++ but use something like Lua for game logic.