[dba-VS] C#, monads - must read - don't get mad with them while reading :)
Gustav Brock
gustav at cactus.dk
Wed Jul 8 11:14:49 CDT 2015
Hi Shamil
Yes, I read that Part 6 as well ... and I think I understand what he does but not how. I have a hard time "pictorial doing" it. You probably have to write an example for yourself - like your address/person example - from the ground and up to fully grasp the concept.
Often, I think, code as your address/person example would be easier to read and debug than a Monad equivalent. I mean, your "bloated" code you can both read and understand in a split second even though it goes for five lines, not to mention how easy it would be to debug and modify if needed.
If I one day should write a Monad, I'll be sure to include a lot of in-line documentation.
/gustav
-----Oprindelig meddelelse-----
Fra: dba-VS [mailto:dba-vs-bounces at databaseadvisors.com] På vegne af Salakhetdinov Shamil
Sendt: 8. juli 2015 17:48
Til: Development in Visual Studio
Emne: Re: [dba-VS] C#, monads - must read - don't get mad with them while reading :)
Hi Gustav --
My pleasure! :)
I have almost finished it - reached the 'parsers' part but then I have lost. The author tells it took him more than an year to get through this subject.
For me the most important is the following feature of monads:
<<<
Monads give us a way of dealing with these ‘amplified types’ and allow us to remove the boiler plate. They can help us write declarative programs where what we are trying to achieve is not obscured by the apparatus we need to achieve it. They help with our core problem as programmers, getting complexity under control so that we can reason effectively about our code.
>From < http://mikehadlow.blogspot.ru/2011/01/monads-in-c2-whats-point.html > >>>
When applied this feature should allow to write (in C#) the following:
public string getEmployeeStreetName()
{
return employee.getPerson().getAddress().getStreet().Name;
}
instead of the following:
public string getEmployeeStreetName()
{
if (employee != null &&
employee.getPerson() != null &&
employee.getPerson().getAddress() != null)
return employee.getPerson().getAddress().getStreet().Name;
return string.Empty;
} A very simple use case but you can check your C# to see how much cleaner it will become if you'll apply just one this "trick" provided by monads.
But I'm still to find out (in the articles I've referred) how to program this trick.
Thank you.
-- Shamil
>Wednesday, July 8, 2015 2:35 PM UTC from Gustav Brock <gustav at cactus.dk>:
>
>Hi Shamil
>
>I'm glad you included the last ("or first") link or I would have no idea of what a Monad is and is used.
>
>However, I must admit that this does not fill a whole for me - it soon gets messy or at least hard-to-read code, and I prefer clarity above brevity. But who knows? Suddenly you have a situation where Monads could be the optimum tool.
>
>Thanks! Learned something new today.
>
>/gustav
>
>-----Oprindelig meddelelse-----
>Fra: dba-VS [mailto:dba-vs-bounces at databaseadvisors.com] På vegne af Salakhetdinov Shamil
>Sendt: 8. juli 2015 13:04
>Til: Development in Visual Studio
>Emne: [dba-VS] C#, monads - must read - don't get mad with them while reading :)
>
>
>Hi All --
>
>Must read: http://ericlippert.com/2013/02/21/monads-part-one/ - ... - http://ericlippert.com/2013/04/03/monads-part-thirteen/
>
>See also: http://blogs.msdn.com/b/pfxteam/archive/2013/04/03/tasks-monads-and-linq.aspx
>
>See also (or first): http://mikehadlow.blogspot.ru/2011/01/monads-in-c1-introduction.html
>
>--
>Салахетдинов Шамиль
More information about the dba-VS
mailing list