3 ms·
> Or you're now generating the wrong filenames. Having a no-overhead Filename type would make this impossible.
by copperx 10y ago
> Or you're now generating the wrong filenames.
Having a no-overhead Filename type would make this impossible.
- jeremiep 10y agoHow so? That type would be a glorified string at best. Types can't check the ranges of their values in most languages. And definitely can't do so at runtime.
- rpeden 10y agoI can see it working in a statically types language with macros - maybe Scala or Template Haskell? I'm not 100% sure if their metaprogramming is capable of this. Ideally, you could define a type like FileNameString to be a string that has to match a certain regex. Though if you wanted to use the new type throughout your program, I suppose you'd need a String -> FileNameString function somewhere to handle instance of file names generated at runtime. I agree that the type systems in most mainstream languages fall somewhere short of awesome. I was putting together a small web app in Elm last week, and it was nice to work with a type system that felt like it was helping me design and write better code. That, plus it has the most helpful errors message I've ever seen from a compiler.
- Too 10y agoActually it's quite common. For example in .net you have a Uri class and a DirectoryInfo class which are basically just wrappers on top of strings with some validation and helper functions.