The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
So C# has "as" which is like an attempted cast. If the cast fails no error is thrown, but the target value is set to null, such like:
string str = obj asstring;
A) It's faster than a cast
B) it lets you do two things in one - cast an object and check the object's type.
So it's more efficient than a cast, in .NET
However, it leads to code patterns like
var cc = obj as CodeComment;
if (null != cc)
var ccu = obj as CodeCompileUnit;
if (null != ccu)
var cd = obj as CodeDirective;
if (null != ccu)
_VisitDirective(cd, args, action);
C#8? introduced a switch style pattern for this but it's still ugly.
That's why I don't like it.
However,in Slang it is not supported, nor can it be, because the only way to emulate that particular operator (which resolves to a specific IL instruction) is using minor reflection (Type.IsAssignableFrom()), which is unacceptable here.
And so a lot of my code simply won't parse.
Curse the CodeDOM for being so sparse. I really wish it supported more operators. There are no unary operators, no try-cast (like above) and most of the assign operators are gone as are maybe half the binary expressions available in most languages. It's kind of a bad joke but there's nothing to be done about it now. Microsoft made the standard. Others adhere to it, broken as it is.
I mean, the CodeDOM is useful but it's bloody limited. I wish Roslyn had pluggable support for additional compilers like F# but as far as I know it's strictly C# and VB
Still, it might be useful eventually to make a Roslyn version of slang once it too can run on a phone. But for now I'm stuck with the stodgy old CodeDOM. Though working with Roslyn would mean most of what my code does wouldn't be necessary in the first place.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
Last Visit: 31-Mar-20 3:42 Last Update: 31-Mar-20 3:42