Click here to Skip to main content
15,887,596 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Why use the correct exception type? Pin
Christiaan van Bergen3-Apr-18 13:28
professionalChristiaan van Bergen3-Apr-18 13:28 
GeneralInteresting / strange code picked up from pluralsight training (functional programming) Pin
raddevus18-Mar-18 13:19
mvaraddevus18-Mar-18 13:19 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel18-Mar-18 21:15
professionalSander Rossel18-Mar-18 21:15 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 2:27
mvaraddevus19-Mar-18 2:27 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming19-Mar-18 2:46
mveRichard Deeming19-Mar-18 2:46 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 3:00
mvaraddevus19-Mar-18 3:00 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 3:08
mvaraddevus19-Mar-18 3:08 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel19-Mar-18 7:17
professionalSander Rossel19-Mar-18 7:17 
Like Richard, I was thinking of an extension method.
What you have there is pretty hard to read, took me a while to figure out what it does (due to the nested Tee, which is not a very helpful name either).
I'm all for chaining though, that's what LINQ does too (which is pretty functional).
Applying functional principles (but remembering C# is not a functional language) really helped me write cleaner and more succinct code.
Although not everyone agrees with me, some people prefer their foreach loops and can't read lambda's Sigh | :sigh:

One thing I've learned, and taken to heart, a function has input and predictable output (no side-effects or state!).
At some point you're going to have state and output, of course, but that's reserved for special classes.
To give an example (from the top of my head, ignore bad practices such as public fields):
C#
public class BadClass
{
   public string s;
   public void BadClass(string s)
   {
      this.s = s;
   }

   public void DoubleString()
   {
      s = s + s;
   }
}

// Usage
var bc = new BadClass("Hello");
bs.DoubleString();
Console.WriteLine(bc.s); // HelloHello

public class GoodClass
{
   public void DoubleString(string s)
   {
      return s + s;
   }
}

// Usage
var gc = new GoodClass();
var s = gc.DoubleString("Hello");
Console.WriteLine(s); // HelloHello
It's a bit contrived, but you'd be amazed at how often I've seen the BadClass implementation (equivalent) of this.
People just love their state and side effects.
But then again, I've worked on old VB applications with old VB programmers...

As coincidence would have it Packt offers a free Functional C#[^] eBook today, may be interesting (haven't read it myself).

GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
BillWoodruff19-Mar-18 17:54
professionalBillWoodruff19-Mar-18 17:54 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel19-Mar-18 21:28
professionalSander Rossel19-Mar-18 21:28 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sentenryu29-Mar-18 1:41
Sentenryu29-Mar-18 1:41 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Dr.Walt Fair, PE12-Apr-18 9:44
professionalDr.Walt Fair, PE12-Apr-18 9:44 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Bernhard Hiller18-Mar-18 22:42
Bernhard Hiller18-Mar-18 22:42 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 2:31
mvaraddevus19-Mar-18 2:31 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Super Lloyd19-Mar-18 2:29
Super Lloyd19-Mar-18 2:29 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 2:32
mvaraddevus19-Mar-18 2:32 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Super Lloyd19-Mar-18 2:42
Super Lloyd19-Mar-18 2:42 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming19-Mar-18 2:44
mveRichard Deeming19-Mar-18 2:44 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Super Lloyd19-Mar-18 2:48
Super Lloyd19-Mar-18 2:48 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 3:56
mvaraddevus19-Mar-18 3:56 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 4:09
professionalEddy Vluggen19-Mar-18 4:09 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 4:13
mvaraddevus19-Mar-18 4:13 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 4:18
professionalEddy Vluggen19-Mar-18 4:18 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 5:46
mvaraddevus19-Mar-18 5:46 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 6:16
professionalEddy Vluggen19-Mar-18 6:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.