4 ms·
The problem with keywords is the compiler can know nothing of intent with them - consider: CopyFile(from: loaded_file, to: report_file) Now, somewhere else
by XorNot 7y ago
The problem with keywords is the compiler can know nothing of intent with them - consider:
CopyFile(from: loaded_file, to: report_file)
Now, somewhere else off in the code someone does something like:
// loaded_file is now the report - so no worries.
loaded_file = report_file
And the compiler then happily propagates that. At no time does it throw an error saying something which would be quite informative such as "Cannot assign report_file (type: outputFile) to loaded_file (type: sourceFile).
Which is really what we want to have happen because - at the very least it forces the developer to go inspect the usage sites to figure out if what they're doing makes sense.
- EdwardDiego 7y agoLanguages that prefer immutable variables by default would be a better solution for that than introducing two new types, surely. Reassignment of a variable should be a code smell in nearly all contexts that don't involve a loop.
- theemathas 7y agoAt least that can be determined to be buggy without checking the documentation of CopyFile
- tom_mellior 7y ago> At no time does it throw an error saying something which would be quite informative such as "Cannot assign report_file (type: outputFile) to loaded_file (type: sourceFile). Java has InputStream/OutputStream. C++ has istream/ostream. If you use a statically typed language that doesn't have this distinction, blame that specific language's library design. This is orthogonal to keywords.
- XorNot 7y agoIs it? Until you open the file as a stream, the data to do so is kicking around your code as a string type with compiler checks on usage. You're making my point: a compile time check is much more helpful.
- tom_mellior 7y agoFrom your example it looked to me like the types in question were "file" types. You're right that "file name" types are not checked by these languages.