|
15 years ago I tried to read a book by him, but I fell asleep when I got to:
"Lippma
... such stuff as dreams are made on
|
|
|
|
|
I don't understand your complaint. His verbiage is perfectly clear and discrete.
|
|
|
|
|
Take a look at this code
static int test()
{
int \u0066\u006F\u006F;
return \u0066\u006F\u006F;
}
Did you know you could do that? I didn't - I knew you could use unicode identifiers (though I never see them in real code), but this is a whole other level of madness.
Obviously that variable is being used but is uninitialized. Try to guess what the compile error will be.
It's not "Use of unassigned local variable '\u0066\u006F\u006F'".
At least it is consistent though, it seems that identifiers written in that style are considered to be identical to the decoded version, so you can mix it with simplify writing it down, and it shows up in intellisense in decoded form and so on.
It gets better. int is a keyword, so it's blue and you can't use it as a name for a local variable except with the @-prefix. So, this works:
int \u0069\u006E\u0074 = 0;
@int++;
That second line can be typed with intellisense auto-completion! That clever bastard knows about the variable called "int" and knows it had better put the @-prefix in front too, just typing "i" calls it up in the pop-up menu. On the other hand, the tool tip for the "int" entry also shows "(local variable) int int", but this is an entry with the value type icon. (this was all in VS2010, it may have changed since then)
In total, I'm not sure whether to feel impressed or disgusted, or a bit of both.
|
|
|
|
|
I added the static method test() to a LINQPad script and it showed a squiggly line on the return statement.
When I floated over it the error message is:
CS0165 Use of unassiged local variable 'foo'
That makes sense.
I set the value to 34 on the first line and it works. Wow. Never knew.
|
|
|
|
|
I'm considering the option to write such a variable name as a bug... and wonder how the rest of the code looks like...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
That makes sense, in an odd sort of way.
And this works:
static int test()
{
int \u0066\u006F\u006F;
foo = 6;
return \u0066\u006F\u006F;
} No compiler errors, just as you'd expect.
I'd guess it's there to allow Chinese, Katakana, Persian, ... variable names and just happens to work in English as well.
But whoever found that out and used it at the coalface should be taken out and shot...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: I'd guess it's there to allow Chinese, Katakana, Persian, ... variable names and just happens to work in English as well. Maybe? I don't see much point though, since they can be used without this hexadecimal encoding step. For example, there's no problem here:
static int test()
{
int 変数 = 1;
int 整数 = 2;
return 変数 + 整数;
}
|
|
|
|
|
Yes, but I couldn't type them - they all look too similar to me. So I'd need the Unicode values or copy'n'paste to modify that code.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
sequences of underscores are also valid variable names
|
|
|
|
|
This looks like it has been written by a decompiler. At least I've seen dotPeek from JetBrains show me code like this a few times, but I don't remember the version.
Maybe someone decompiled another library to extract one (or a few) methods out of it without actually modifying the copied code?
|
|
|
|
|
And I just thought of this...
int \u0066\u006F\u006F = 34;
Console.WriteLine(nameof( \u0066\u006F\u006F));
// writes out foo
Works in C# 6.0 and above
|
|
|
|
|
Could be worse.
You'll be happy to know that I tried to assign a value to int \u263a and the IDE kvetched.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
You just need an extra 0 :
int \u0263a = 42;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sure, but that's not an emoticon.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
strText2 = WeekdayName(myCurrentDate.DayOfWeek, False, Microsoft.VisualBasic.FirstDayOfWeek.Monday)
I just found and fixed this in a half-dozen places whilst reviewing event logs for an Azure web app. TBF, this web app is for a strictly M-F organization, so there should be no activity at all on a Sunday...but it does seem to be happening from time to time.
btw, yes the datetime variable is a utc tz and dst adjusted datetime for the client. This code was basically just for display. I'm sure there are better ways to do it, but i'm not asking.
"Go forth into the source" - Neal Morse
|
|
|
|
|
Quote: VisualBasic.FirstDayOfWeek.Monday
That's the International Standard. I don't understand what the problem was.
|
|
|
|
|
The problem happens when the myCurrentDate variable represents a Sunday where myCurrentDate.DayOfWeek returns a 0. The WeekdayName function expects the first parameter to be between 1 and 7...0 throws an exception.
The corrected code is:
rText2 = WeekdayName(myCurrentDate.DayOfWeek + 1, False, Microsoft.VisualBasic.FirstDayOfWeek.Sunday)
"Go forth into the source" - Neal Morse
|
|
|
|
|
No, the real corrected code is:
rText2 = myCurrentDate.ToString("dddd")
Custom Date and Time Format Strings | Microsoft Docs[^]
Or, if you really want to pad the code out:
rText2 = System.Globalization.DateTimeFormatInfo.CurrentInfo.GetDayName(myCurrentDate.DayOfWeek)
The vast majority of the Microsoft.VisualBasic assembly is just there for backwards-compatibility with VB6, and should be avoided wherever possible.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you Richard! Helpful as always...I knew there had to be a better way!
"Go forth into the source" - Neal Morse
|
|
|
|
|
string isValidArticle(string article) - The Daily WTF[^]
A Zero-Day exploit in the .NET framework through the WSDL parser.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
We need a new icon for "coding horror". Perhaps a WTF with its hair standing on end?
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
I've always had this standard of code that I thought was "Microsoft quality". Granted, given the number of bugs and "features over fix" commonly found in Microsoft products, this bar was not set high.
This ... "sample", for lack of a sufficiently derogatory term, just jumps on that bar and smashes it into the ground.
How the that code ever made it past review, let alone testing, is beyond my too-early-in-the-morning-on-a-weekend comprehension.
|
|
|
|
|
It's a shame the article doesn't quite explain the problem properly.
The code is generating a verbatim string literal, so newlines in the string don't need to be encoded or escaped.
Source:
This is a perfectly valid
verbatim string literal
across multiple lines. Output:
string foo = @"This is a perfectly valid
verbatim string literal
across multiple lines.";
Unfortunately, that string literal ends up being placed in a single-line comment, which only comments out the first line.
Source:
This is a commented-out verbatim string literal.
System.Diagnostics.Process.Start("evil-code.exe");
// Output:
System.Diagnostics.Process.Start("evil-code.exe");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Good find by the hackers, just reading the code made me really cringe, mainly because I'm nowhere near awake enough to parse it correctly. Whether it's a gross missnaming or the devs not checking what isValidURL() actually validates one can be certain oversights were made.
I'm in the middle of refactoring some css to make it clear and this article is yet another validation to striving to name things to the best of ones ability. My issue is naturally trivial in comparison and there is zero possibility of failing in such an impactful way, but clear code speaks for itself.
|
|
|
|