Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Further proof for my personal conviction that C# is a very interesting, progressive language which masquerades as a Java clone.

I once copied the style of a maybe monad using LINQ - the WinRT apis lack a "FileExists?" method, so I used LINQ to search a directory's contents for a filename. An IEnumerable of size of zero represented None, and size one represented Some.

Unfortunately, a simple try/catch around an attempt to open the desired file was more efficient and clearer to understand.



LINQ has an .Empty() extension method, and you should use that instead of .Count()==0 when determining if an expression is empty.


You should use try/catch; branching would imply a race condition in a multithreaded environment (what if another process deletes the file between the check and the use of the file?).




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

Search: