3 ms·
Do you also use one letter variables and parameters? If not, what is different about generics? Even in your example, I'd rather read this: map<IN,OUT>(fn:(el
by MrPatan 6y ago
Do you also use one letter variables and parameters? If not, what is different about generics?
Even in your example, I'd rather read this:
map<IN,OUT>(fn:(el:IN)=>OUT):OUT[]
Plus, it really is a habit. If you stop doing it for these kind of examples that really are very generic, maybe people wouldn't also use only one letter for cases where there is more of a difference between them.
- SmellyPotato22 6y agoKinda gets a little hairy if you start to add more types. Example: `//fork :: [a] ->((a -> b ), (a -> c)) -> ([b] ,[c])` `fork<A,B,C>(fn1:(el:Iterator<A>)=>B,fn2:(el:Iterator<A>)=>C)`
- MrPatan 6y agoWhat would be the opposite of "fork", something like "zip" that gets two lists and combines them into one? Would it have a signature also starting like this: `zip<A, B, C>(...`
- SmellyPotato22 6y agoI think that about right. Although I think this is slightly different than regular zip which is [a] -> [b] -> [(a,b)] and instead would be ([a],[b]) -> [c] or if I remember currying right [a] -> [b] -> [c].
- legerdemain 6y ago> Do you also use one letter variables and parameters? A question in response to your question... Do you ever give an ALL CAPS name to a class? Why not? Maybe it's the set of conventions I'm used to, but I find T, U, V familiar and IN, OUT jarring and dramatically less readable at a glance.
- MrPatan 6y agoI use ALL_CAPS in generics so they are easy to tell apart from functionNames and ClassNames
- Dylan16807 6y agoIt might be 'jarring' but looking over the original line I didn't parse what those types were doing at all, and T/U/V wouldn't be any better, while IN/OUT I can understand without explicitly thinking about it.
- Kranar 6y agoSometimes I do, sometimes I don't. If it's an iterator I often use one letter names such as i, j, k. Similarly if it's a generic unbounded type I also give it a one letter name.