|
I don't get it ! ! !
Why must you 'not kill'?
It seems justified.
|
|
|
|
|
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[^])
string name = "Mark";
var date = DateTime.Now;
Console.WriteLine("Hello, {0}! Today is {1}, it's {2:HH:mm} now.", name, date.DayOfWeek, date);
Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} 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.
JavaScript calls them template literals.
The very odd thing is that you have to use back-ticks to get them to work.
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.
It is a bit nicer than concatenating strings and vars with all those + signs though.
Previously you had to do something like:
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:
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.
string finalAnswer = @$"this is the answer to the question: {40+2}";
Console.WriteLine(finalAnswer);
|
|
|
|
|
Quote: if you place the verbatim string operator before the interpolated string operator you will get a syntax error. That's because the verbatim operator is tightly couple to the string and suppresses interpolation of the string - therefore the interpolation operator needs to come after the resulting string from the "non-interpolation" operator.
...erm, or maybe the other way around? Whatevs!
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
Yeah, the way I saw it explained was :
$ then @ because you are saying, "interpolate this verbatim string..."
Instead of
@ then $ "Give me verbatim of this interpolated string..."
Kind of makes sense, I guess.
|
|
|
|
|
raddevus wrote: Kind of makes sense, I guess.
I promise to quote you verbatim without interpolation.
Latest Article - A Concise Overview of Threads
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
|
|
|
|
|
Marc Clifton wrote: I promise to quote you verbatim without interpolation.
|
|
|
|
|
|
Richard Deeming wrote: Looks like that should be "fixed" in C# 8:
Thanks for the update and links.
|
|
|
|
|
(Yes, I meant to put this here, no real reason.)
I discovered this this week. Unsure anyone else has noticed it or has any idea of how to avoid it.
I'm working on a command-line program which will require XML in a parameter.
I stored an example XML parameter in VS (2010 and 2015) for debugging.
It seemed OK the first day, but things went awry when I ran it the following day.
This evening I whipped up a little demonstration.
I set the debug parameter such:
"<ArgTest><Parameter>Value</Parameter></ArgTest>"
In ArgTest.csproj.user, it looks good:
<StartArguments>"<ArgTest><Parameter>Value</Parameter></ArgTest>"</StartArguments>
And on first run, the output is good:
<ArgTest><Parameter>Value</Parameter></ArgTest>
Value
"c:\Project\ArgTest\bin\Debug\ArgTest.exe" "<ArgTest><Parameter>Value</Parameter></ArgTest>"
Value
But, save, close, and re-open the solution, and the parameter somehow gains a default namespace which then gets mangled by the system:
"<ArgTest xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><Parameter>Value</Parameter></ArgTest>"
<ArgTest xmlns=http://schemas.microsoft.com/developer/msbuild/2003><Parameter>Value</Parameter></ArgTest>
'http' is an unexpected token. The expected token is '"' or '''. Line 1, position 16.
"c:\Project\ArgTest\bin\Debug\ArgTest.exe" "<ArgTest xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><Parameter>Value</Parameter></ArgTest>"
Not found
Some of you will be surprised by the "Not found", but I'm not, I expected it once I saw the problem.
Obviously, Visual Studio saves the .user file inappropriately, but that doesn't explain the addition of the namespace.
Very weird.
namespace CP
{
public static partial class ArgTest
{
static int
Main
(
string[] args
)
{
int result = 0 ;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
try
{
System.Console.WriteLine ( args [ 0 ] ) ;
doc.LoadXml ( args [ 0 ] ) ;
System.Xml.XmlNode val = doc.DocumentElement.SelectSingleNode ( "Parameter" ) ;
if ( val == null )
{
System.Console.WriteLine ( "Not found" ) ;
}
else
{
System.Console.WriteLine ( val.InnerText ) ;
}
}
catch ( System.Exception err )
{
System.Console.WriteLine ( err.Message ) ;
}
try
{
System.Console.WriteLine ( System.Environment.CommandLine ) ;
int s = System.Environment.CommandLine.IndexOf ( "\"<" ) + 1 ;
int e = System.Environment.CommandLine.IndexOf ( ">\"" ) + 1;
doc.LoadXml ( System.Environment.CommandLine.Substring ( s , e - s ) ) ;
System.Xml.XmlNode val = doc.DocumentElement.SelectSingleNode ( "Parameter" ) ;
if ( val == null )
{
System.Console.WriteLine ( "Not found" ) ;
}
else
{
System.Console.WriteLine ( val.InnerText ) ;
}
}
catch ( System.Exception err )
{
System.Console.WriteLine ( err.Message ) ;
}
return ( result ) ;
}
}
}
|
|
|
|
|
Seems like you need to manually edit the .csproj.user file to wrap the arguments in a CDATA section:
Visual Studio changes debug xml Command line arguments - Stack Overflow[^]
Unfortunately, you'll have to repeat that every time you change a project setting.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This program doesn't warrant that amount of effort.
I'll have to ensure that my command line parser can remove the namespace when present, but this program doesn't use that anyway.
|
|
|
|
|
|
Nice idea - shame it's so limited. Once you get to the rock - "I need a tool to get past this" - that seems to be the end, since there isn't a tool anywhere.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: since there isn't a tool anywhere.
You can get the pick. I found it. I can give you the first hint and then more if you need them.
I' thinking you got stuck on the part I got stuck on....
The elevators do go down but you click below the down arrow.
This is your HINT : You have to go down the elevator to find the pick and bring it back up.
|
|
|
|
|
raddevus wrote: The elevators do go down but you click below the down arrow.
Sounds like a bug to me.
I've now been through every bit it will let me get to, and clicked on everything it will let me click, and there doesn't seem to be any way to progress. Time to give up and get some sleep.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Aaaargh! Finally worked out what the notes meant.
It didn't help that the spinners for the combination didn't seem to be working in FF62.
Shenanigans indeed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Glad you got it.
It is a fairly nice extended example of what can be done with CSS3.
|
|
|
|
|
Richard Deeming wrote: shame it's so limited. If only there were a way to make changes to it.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
If I had a few weeks to study Jamie's code, I might be able to work out how to do that.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
switch (str)
{
case "4":
if (str != "5") ...
Ah, the joys of outsourcing with no code reviews.
Latest Article - A Concise Overview of Threads
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
|
|
|
|
|
The naming of str bugs me just as much. Ok, I know it's a string. But what is it? Calling it something like invoiceTypeCode indicates it is a string and lets me know what I am looking at.
|
|
|
|
|
gardnerp wrote: The naming of str bugs me just as much.
It had a real name. I sanitized it.
Latest Article - A Concise Overview of Threads
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
|
|
|
|
|
I was guessing that the programmer had a Fortran background. Fortran has no reserved words (at least it didn't up to F77 - I haven't used more recent versions) so you could define INTEGER to be a REAL variable and COMPLEX to be an INTEGER variable, The result of multiplying INTEGER and COMPLEX could be REAL value stored in the REAL variable REAL. Spaces had no significance, so REALREAL and COMPLEXFUNCTION were perfectly valid variable declarations. (I am really happy that I never had to write a Fortran parser!)
When learning Fortran coding at the university, we made up lots of programming exercises for our own fun. One of them was to print out Pascal's triangle using predefined words only, and no literals. Our compiler allowed recursion, which was an extension to Fortran IV, but without it, I doubt that we would have succeeded. The code was completely unreadable. Maybe I should dig it up from the basement and post it here!
|
|
|
|
|
I recently inherited a load of "code" (it's VBA so I don't want to it ideas above its station ) ... during the "handover" (apparently that's what it was) the original "programmer" explained with great pride, that they didn't Quote: waste their time using long variable names... Yep! Every single one of them was a single character. Every. Single. One.
(Except where he copied code snippets off the internet)
|
|
|
|
|
CHill60 wrote: waste their time using long variable names It's likely they spent more time trying to remember and figure out what each single character variable actually was.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|