Click here to Skip to main content
15,886,026 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: Must....not....kill.... Pin
Marc Clifton1-Nov-18 3:28
mvaMarc Clifton1-Nov-18 3:28 
GeneralRe: Must....not....kill.... Pin
Tomaž Štih1-Nov-18 23:37
Tomaž Štih1-Nov-18 23:37 
GeneralRe: Must....not....kill.... Pin
englebart1-Nov-18 3:42
professionalenglebart1-Nov-18 3:42 
GeneralRe: Must....not....kill.... Pin
agolddog1-Nov-18 3:42
agolddog1-Nov-18 3:42 
GeneralRe: Must....not....kill.... Pin
KBZX50004-Nov-18 23:36
KBZX50004-Nov-18 23:36 
GeneralRe: Must....not....kill.... Pin
irneb8-Nov-18 22:52
irneb8-Nov-18 22:52 
GeneralRe: Must....not....kill.... Pin
C Pottinger5-Dec-18 13:51
C Pottinger5-Dec-18 13:51 
GeneralC# interpolated string, JavaScript template literal Pin
raddevus29-Oct-18 2:58
mvaraddevus29-Oct-18 2:58 
You probably know about C# String interpolation and the new(er) (C# 6, via .NET 4.6) string operator $.
Here's the explanation and sample from ($ - string interpolation (C# Reference) | Microsoft Docs[^])
C#
string name = "Mark";
var date = DateTime.Now;

// Composite formatting:
Console.WriteLine("Hello, {0}! Today is {1}, it's {2:HH:mm} now.", name, date.DayOfWeek, date);
// String interpolation:
Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now.");
// Both calls produce the same output that is similar to:
// Hello, Mark! Today is Wednesday, it's 19:40 now.

The new formatting is very nice, much more straight forward and obvious about which values are included in the string.

JavaScript Analog
But, did you know about the JavaScript equivalent that entered in JavaScript 2015?
I just saw this for the first time -- only three years late. Laugh | :laugh:
JavaScript calls them template literals.
The very odd thing is that you have to use back-ticks to get them to work.
JavaScript
var who = "world";
console.log(`hello, ${who}`);

That produces an output of :
hello, world

If you use double or single quotes instead of back-ticks it doesn't work.
The back-ticks kind of make me shudder. Hmmm | :|
It is a bit nicer than concatenating strings and vars with all those + signs though.
Previously you had to do something like:
JavaScript
var who = "world";
console.log("hello, " + who);

You can read more about template literals here[^].

It's interesting to see a concept emerge and then how different language developers implement it.

C# Bonus Weirdness
You can use the verbatim string operator with the interpolated string operator like the following:
C#
string finalAnswer = $@"this is the answer to the question: {40+2}";
Console.WriteLine(finalAnswer);

But if you place the verbatim string operator before the interpolated string operator you will get a syntax error.
C#
string finalAnswer = @$"this is the answer to the question: {40+2}";  // syntax error
Console.WriteLine(finalAnswer);

GeneralRe: C# interpolated string, JavaScript template literal Pin
  Forogar  29-Oct-18 3:08
professional  Forogar  29-Oct-18 3:08 
GeneralRe: C# interpolated string, JavaScript template literal Pin
raddevus29-Oct-18 3:21
mvaraddevus29-Oct-18 3:21 
GeneralRe: C# interpolated string, JavaScript template literal Pin
Marc Clifton29-Oct-18 4:22
mvaMarc Clifton29-Oct-18 4:22 
GeneralRe: C# interpolated string, JavaScript template literal Pin
raddevus29-Oct-18 4:52
mvaraddevus29-Oct-18 4:52 
GeneralRe: C# interpolated string, JavaScript template literal Pin
Richard Deeming29-Oct-18 8:52
mveRichard Deeming29-Oct-18 8:52 
GeneralRe: C# interpolated string, JavaScript template literal Pin
raddevus29-Oct-18 10:00
mvaraddevus29-Oct-18 10:00 
GeneralVisual Studio and XML command line parameters Pin
PIEBALDconsult25-Oct-18 19:20
mvePIEBALDconsult25-Oct-18 19:20 
GeneralRe: Visual Studio and XML command line parameters Pin
Richard Deeming26-Oct-18 1:05
mveRichard Deeming26-Oct-18 1:05 
GeneralRe: Visual Studio and XML command line parameters Pin
PIEBALDconsult26-Oct-18 4:58
mvePIEBALDconsult26-Oct-18 4:58 
GeneralCodePen: Adventure Game only CSS & HTML (no JS) Pin
raddevus23-Oct-18 5:18
mvaraddevus23-Oct-18 5:18 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
Richard Deeming23-Oct-18 7:38
mveRichard Deeming23-Oct-18 7:38 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
raddevus23-Oct-18 9:00
mvaraddevus23-Oct-18 9:00 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
Richard Deeming23-Oct-18 11:40
mveRichard Deeming23-Oct-18 11:40 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
Richard Deeming25-Oct-18 4:16
mveRichard Deeming25-Oct-18 4:16 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
raddevus25-Oct-18 7:40
mvaraddevus25-Oct-18 7:40 
AnswerRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
ZurdoDev25-Oct-18 8:26
professionalZurdoDev25-Oct-18 8:26 
GeneralRe: CodePen: Adventure Game only CSS & HTML (no JS) Pin
Richard Deeming25-Oct-18 8:31
mveRichard Deeming25-Oct-18 8:31 

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.