by snarfy · 9y ago · 0 comments
p.GetCoordinates(out int x, out int y);
vs var coordinates = p.GetCoordinates();
out parameters should be deprecated, not enhanced.Patterns are OK, but switch statement with patterns...why? I'd much rather do something like this:
class ShapeHandler()
{
public void Handle(Circle c)
{
...
}
public void Handle(Rectangle s)
{
...
}
}
The argument for Tuples:> Custom-built transport type for every method: A lot of code overhead for a type whose purpose is just to temporarily group a few values.
I disagree. Before you know it, that 'temporary group' becomes a first class citizen and deserves its own type. If it's code overhead, I'd rather the IDE/tooling help me with it than it be built into the language.
Overall these changes make the language more expressive which is good. I just fear they will be abused more often than not.
public static Dictionary<(long id, string firstName, string lastName), (string shippingAddress, DateTime date, List<(long itemId, string itemName, decimal price)> items)> LoadCustomerOrders()
{
// ...
}
in your codebase :) using System;
class Foo { }
class Bar { }
static class Program {
static void Example(Foo l, Foo r) { Console.WriteLine("Foo Foo"); }
static void Example(Foo l, Bar r) { Console.WriteLine("Foo Bar"); }
static void Example(Bar l, Foo r) { Console.WriteLine("Bar Foo"); }
static void Example(Bar l, Bar r) { Console.WriteLine("Bar Bar"); }
static object Create(string arg) { return arg == "Foo" ? (object)new Foo() : new Bar(); }
static void Main(string[] args) {
dynamic l = Create(args.Length > 0 ? args[0] : "Foo");
dynamic r = Create(args.Length > 1 ? args[1] : "Bar");
Example(l, r);
}
} var x, y;
p.DoSomething(out x, out y);
Where this becomes useful, I think, are places where you can't avoid using an out parameter. Now, you can choose to throw away or use the out parameter without explicitly declaring it. var isNumber = Int32.TryParse(number, out x); public static class Parse
{
public static Option<int> TryInt(string str)
{
int value;
return Int32.TryParse(str, out value)
? Some(value)
: None;
}
}
var x = Parse.Int("123").IfNone(0);
var x = Parse.Int("456").Match(
Some: x => x * 2,
None: () => 0
);
Parse.Int("456").Iter(Console.WriteLine);
https://github.com/louthy/language-ext/blob/e6ff382a1752c7de...