|
|
|
|
|
by maxlybbert
3583 days ago
|
|
> if you consider:
>
> for (auto& p : wordCount) {
> ...
> But you have no idea what "word" or "count" *is*.
If you know what wordCount is, you'll know what types word and count are.I remember back when I was still a very new programmer I somehow got the syntax for an iterator-based loop wrong ("for std::vector<int>::iterator itor = v.begin(); itor != v.end(); ++itor)"). I don't remember my mistake. I probably missed a const somewhere. The compiler told me that "std::vector<int>::iterator" did not match the type of v.begin(), but it wouldn't tell me what would match. Even as a beginning programmer, I knew the compiler knew, but all it would say was "you got it wrong." And, of course, I didn't care what the type of v.begin() was. All I cared about was whether I could iterate over the elements of v. And I knew that v contained int's. Many programmers learned about strong typing ( https://en.wikipedia.org/wiki/Strong_and_weak_typing ) and static typing ( https://en.wikipedia.org/wiki/Type_system#STATIC ) in languages that require manifest typing ( https://en.wikipedia.org/wiki/Manifest_typing ), so they often don't realize those are three distinct ideas. You can write strongly typed programs in Haskell, Ocaml, Go and Rust without many type statements. |
|