[dba-VS] C#, monads - must read - don't get mad with them while reading :)

Gustav Brock gustav at cactus.dk
Thu Jul 9 11:46:59 CDT 2015


Hi Shamil

Uh, moving to assembly would be to exaggerate well beyond readability! I never did much in that area except for some small keyboard utilities programmed with Debug(?). I managed to get hold of the original Microsoft Assembly linker/compiler (in the plastic box with the manual) but I never used it.

But, as you do, the author mentioned IEnumerable as a real-life example of a Monad, and that is a good example because how to live without that? So I think - to make sense - Monad should be though of for a more complicated scenarios - not very simple ones as in his tutorial.

/gustav

-----Oprindelig meddelelse-----
Fra: dba-VS [mailto:dba-vs-bounces at databaseadvisors.com] På vegne af Salakhetdinov Shamil
Sendt: 8. juli 2015 19:16
Til: Development in Visual Studio
Emne: Re: [dba-VS] C#, monads - must read - don't get mad with them while reading :)

 Hi Gustav --

Well, then one should better use assembly language, shouldn't they? :) (I have programmed on IBM 360/370 and PDP 11 macro assemblers for more than ten years - I still think IBM 360/370 macro assembler is the best programming language I've ever used - all the system was in my control:) )

Using "bloated" version wouldn't work, I suppose, if the parts of your "bloated" expression would return IEnumerable<T> and would use 

yield return ...

to return enumerable values as soon as they are becoming actual...

So. it's time to get accustomed to use higher level programming concepts? - without them smooth scaling and (automatic) code execution parallelization wouldn't  work.

-- Shamil

>Wednesday, July  8, 2015 4:14 PM UTC from Gustav Brock <gustav at cactus.dk>:
>
>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