Click here to Skip to main content
15,889,216 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: 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 
Eddy Vluggen wrote:
Like a decorator..

cue Madonna
...touched for the very first time...
Laugh | :laugh: I could not pass that up.

Ignoring the bad joke (if possible) I think your point is really interesting, because it is like a decorator.

Also, in an effort to completely beat this dead horse, how about the following addition?
If, nothing else, the added method has a great name : see SpaceOut.

C#
public static class Helper{
	public static T Tee<T>(
	this T @inVal,
	Action<T> act){
		act(@inVal);
		return @inVal;
	}
	
	public static Byte[] GetBytes( this String @inVal){
		Byte [] outBytes = new Byte[@inVal.Length];
		int loopCount = 0;
		foreach (Char c in @inVal){
			outBytes[loopCount] = Convert.ToByte(c);
			loopCount++;
		}
		return outBytes;
	}
	
	public static String DisplayBytes(this byte[] inBytes){
		String outVal = String.Empty;
		foreach (Byte b in inBytes){
			outVal += Convert.ToString($"{b:D3} ");
		}
		return outVal;
	}
	
	public static String SpaceOut(this string @inVal){
		StringBuilder spacedItem = new StringBuilder();

		foreach (Char c in @inVal){
			spacedItem.Append($" {c}    ");
		}
		Console.WriteLine(spacedItem.ToString());
		return @inVal;
	}
}


Now you can do this:
C#
"What up!"
		.Tee(Console.WriteLine)
		.SpaceOut()
		.GetBytes()
		.DisplayBytes()
		.Tee(Console.WriteLine);


And you will get the following:

What up!
 W     h     a     t           u     p     !    
087   104   097   116   032   117   112   033 


Additionally interesting (or not) is that SpaceOut simply passes the input string along with no change since you only want the input to be printed with the extra spaces but don't want the output altered in this case.

I got a million of 'em! Laugh | :laugh:
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 6:16
professionalEddy Vluggen19-Mar-18 6:16 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 7:23
mvaraddevus19-Mar-18 7:23 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 8:03
professionalEddy Vluggen19-Mar-18 8:03 
GeneralOFFTOPIC Pin
Nelek19-Mar-18 7:00
protectorNelek19-Mar-18 7:00 
GeneralRe: OFFTOPIC Pin
raddevus19-Mar-18 7:21
mvaraddevus19-Mar-18 7:21 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel20-Mar-18 5:52
professionalSander Rossel20-Mar-18 5:52 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus20-Mar-18 7:24
mvaraddevus20-Mar-18 7:24 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming20-Mar-18 7:32
mveRichard Deeming20-Mar-18 7:32 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus20-Mar-18 8:24
mvaraddevus20-Mar-18 8:24 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel21-Mar-18 1:38
professionalSander Rossel21-Mar-18 1:38 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus21-Mar-18 2:40
mvaraddevus21-Mar-18 2:40 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming19-Mar-18 8:26
mveRichard Deeming19-Mar-18 8:26 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 8:40
mvaraddevus19-Mar-18 8:40 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
icemanind19-Mar-18 7:18
icemanind19-Mar-18 7:18 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 7:27
mvaraddevus19-Mar-18 7:27 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
icemanind19-Mar-18 7:39
icemanind19-Mar-18 7:39 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 7:44
mvaraddevus19-Mar-18 7:44 

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.