When did syntax become so fussy?
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
Trying to save all the above, show how clever language designers can be, and burn out everyone else's brain cells trying to keep up with, and parse, all this shite.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
I really like that you mentioned that. Just yesterday during a live coding session another dev was showing me how to do a thing. He used a C# anonymous function / lambda expression and was trying to get it right (and this was his code) and he was typing, backspacing, typing, backspacing...waiting for intellisense, typing waiting for intellisense... I was like, "yeah, functional programming...no one can remember the syntax..." We both laughed. :rolleyes: I mean regular old OOP and structured programming is really easy to remember and type actually. *youngster waves fist and starts..."Old man...!!!" I know. :sigh:
-
I really like that you mentioned that. Just yesterday during a live coding session another dev was showing me how to do a thing. He used a C# anonymous function / lambda expression and was trying to get it right (and this was his code) and he was typing, backspacing, typing, backspacing...waiting for intellisense, typing waiting for intellisense... I was like, "yeah, functional programming...no one can remember the syntax..." We both laughed. :rolleyes: I mean regular old OOP and structured programming is really easy to remember and type actually. *youngster waves fist and starts..."Old man...!!!" I know. :sigh:
raddevus wrote:
*youngster waves fist and starts..."Old man...!!!"
... older man smiles silently: APL :-D
Mircea
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
Maybe I'm the odd one out but I don't see the issue. It's an expression syntax instead of a statement syntax. Not to mention this syntax forces an expression as the body of a case section so if your intent is to return something then that is enforced, whereas the statement syntax doesn't care. I feel like it's the same difference and motivations between the ternary operator ?: and if-else. Expression vs statement. Something simple that yields a value vs something possibly complex that may or may not. Also you save space. 6 lines vs 15 lines ;P
string x = "test";
int y = x switch {
"test" => 0,
"test1" => 1,
"test2" => 2,
_ => 3
};int z = -1;
switch (x) {
case "test":
z = 0;
break;
case "test1":
z = 1;
break;
case "test2":
z = 2;
break;
default:
z = 3;
break;
}; -
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
Because doing something guilelessly makes a person appear to be much cooler.
The less you need, the more you have. JaxCoder.com
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
Dennis Ritchie will haunt them.
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
looks like a candidate for the Strategy design pattern.
-
I used to feel the same way until IntelliJ IDEA showed me how to reduce a block of code to a single line using similar obscure syntax. (much to my surprise!) The Lounge[^]
Get me coffee and no one gets hurt!
Cp-Coder wrote:
Tonight I will have nightmares of vicious IDEs chasing after me to correct all my many mistakes!
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
ELI5 Anyone care to explain ? it looks like a switch.
CI/CD = Continuous Impediment/Continuous Despair
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
Personally I find that 1000x more readable than switch/case or if/else, and also tells me if I haven't implemented the default option, so more robust code.
Latest Articles:
Client-Side Type-Based Publisher/Subscriber, Exploring Synchronous, "Event-ed", and Worker Thread Subscriptions -
Trying to save all the above, show how clever language designers can be, and burn out everyone else's brain cells trying to keep up with, and parse, all this shite.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.Greg Utas wrote:
all this shite.
amen
Real programmers use butterflies
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
It's part of the "how much can I pack into one LINQ / SQL statement" school of obfuscation.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
Greg Utas wrote:
all this shite.
amen
Real programmers use butterflies
But you understand it! :laugh:
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
Chris Maunder wrote:
Are we really helping the Art with this type of syntax?
No. There seems to be a modern prejudice against classic iteration (
for
,while
) and conditionals (if
). Somehow writing these same constructs as imperative statements is "more robust" and "less error-prone". Any construct that introduces a nested scope seems subject to this prejudice. Those imperative statements are only syntactic sugar supplied by the compiler. I have a hard time liking the new features in the last couple of major versions of C#. Most if not all of them seem to be this sort of syntactic sugar, and they don't really add new functionality. The features that make the most sense to me are those that let you omit specifying a type where the compiler can figure it out from context. That saves typing (even with IntelliSense) and time.Software Zen:
delete this;
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
Since vendors wanted to lock you in to their development environment rather than using the competition. Most people rely on autocomplete and suggestions for their coding. If you would prefer to use vim or another editor that doesn't do that - it makes it just that little bit harder. . . and once you are hooked, much less easy to move away . . . I may be paranoid - but it doesn't make me wrong.
-
Paraphrased from Microsoft's own docs in order to make it readable
MyMethod(options => _ = provider switch
{
"option 1" => options.Method1(x => x.Prop),
"option 2" => options.Method2(x => x.Prop),
_ => throw new Exception($"Unsupported option: {option}")
});Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?
cheers Chris Maunder
This particular way of typing things doesn't make terribly much sense, but it demonstrates how you can save syntax. The one method it demonstrates is a lambda, the other (and I think that's the point here) is a Switch expression. I know I miss the latter in my C++ project.