Hacker News new | past | comments | ask | show | jobs | submit login

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.




Sometimes 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.


  > 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.


It 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.


I use ALL_CAPS in generics so they are easy to tell apart from functionNames and ClassNames


Kinda 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)`


What 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>(...`


I 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].




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: