Hacker News new | ask | show | jobs
by spenrose 2760 days ago
Why would a programmer have an intent about types to express unless s/he had been trained to think of programming in terms of static typing?
3 comments

If your type system is powerful enough (like in Rust), then you can use it to express relations in your problem domain and have compiler enforce them for you before the code even runs.

Example: https://blog.chain.com/bulletproof-multi-party-computation-i...

I think you missed the "unless" in my question. I am well aware that having chosen to treat types as a first class problem, a coder can leverage that intent. My point is simply that there is a populous, productive world of software development in which typing is a humdrum issue for the coders. C.f. the last 30 years of Javascript and Python
What makes that an interesting question? That’s like saying “how would someone have an idea to tests their code unless they were trained to think about testing?” It feels like a tautology, and not particularly relevant.

(I love both dynamic and static typing. I think dynamic type systems are more useful than basic static type systems, but also really enjoy more expressive static type systems.)

Perhaps the programmer should be focused on the purpose the code serves, rather than the code as code object. Mental cycles devoted to thinking about types are, for most programs, overhead. It's perfectly reasonable to be a strong static-typing believer, though I am not. But it's also perfectly reasonable not to think about types when coding, as millions of useful programs have demonstrated.
FWIW, I've found many people new to programming expect something like types, even though they don't have the vocabulary for it yet. It really just depends on the individual.
Sure. And many people new to skiing expect something like gussets to keep the snow out of their underwear when they fall. Issue is whether skiing is about clothing or moving over the landscape. Some focus on your clothes is appropriate, and more in certain circumstances. Rust, which I see you are a proselytizer for (I was at Mozilla during Rust's ramp-up, FWIW), is a tool for writing code that is closely integrated with the operating system. In that context, a type-centric mindset is necessary and valuable. If you are writing code in other contexts: exploratory data analysis, a simple Android app, and on and on, then types are there, but programming is not type management
Sure, that's why both kinds are useful. I don't disagree at all.
What do you mean by types? Most modern languages have fairly extensive type systems.
Typing doesn't have to be static (or strong) to be there. When I write `a + b`, I intend `a` and `b` to be things such that the `+` operator makes sense for them. Might be two numbers, might be two strings, might be a string and a number if I'm using js/php, the point is that I always have an intention, implicit or explicit.
"When I walk to the store, I intend for the ground to hold me up. My intention might be implicit, but it is always there."