Tech Off Thread

131 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Ideas for C# 5.0

Back to Forum: Tech Off
  • User profile image
    exoteric

    What would you like to see in C# 5.0?

     

    For Reference

  • User profile image
    exoteric

    I'll start out -

     

    Tuple Syntax 
    a la (precise parenthesization not so important here)

    (1,2,3)

    Tuple Enumeration

    Not a language feature but allow tuple to be enumerated (IEnumerable<T>) for both homogeneous and heterogeneous tuples, meaning these two cases would both be legal

    foreach (var x in (1,2,3))
      Console.WriteLine(x);
    foreach (var x in (1,"WTF",3))
      Console.WriteLine(x);

    Where in the first case the tuple would be IEnumerable<int> and in the second case the tuple would be either IEnumerable<IDynamic> or IEnumerable<Object>.

  • User profile image
    Bass

    exoteric said:

    I'll start out -

     

    Tuple Syntax 
    a la (precise parenthesization not so important here)

    (1,2,3)

    Tuple Enumeration

    Not a language feature but allow tuple to be enumerated (IEnumerable<T>) for both homogeneous and heterogeneous tuples, meaning these two cases would both be legal

    foreach (var x in (1,2,3))
      Console.WriteLine(x);
    foreach (var x in (1,"WTF",3))
      Console.WriteLine(x);

    Where in the first case the tuple would be IEnumerable<int> and in the second case the tuple would be either IEnumerable<IDynamic> or IEnumerable<Object>.

    BigInt literals

     

    var bigint = 349438474346346348348346734634634892390139328234746546348349349347237236465483932948565623893832932932737;

  • User profile image
    staceyw

    Bass said:
    exoteric said:
    *snip*

    BigInt literals

     

    var bigint = 349438474346346348348346734634634892390139328234746546348349349347237236465483932948565623893832932932737;

    Not sure that would make the cut without a suffix literal.  But something like a "B" suffix would seem to fit.

  • User profile image
    joechung

    Range literals, e.g., 1..10 instead of Enumerable.Range(1, 10)

  • User profile image
    ManipUni

    Bass said:
    exoteric said:
    *snip*

    BigInt literals

     

    var bigint = 349438474346346348348346734634634892390139328234746546348349349347237236465483932948565623893832932932737;

    I cannot tell if this is sarcasm... Sad

  • User profile image
    TommyCarlier

    exoteric said:

    I'll start out -

     

    Tuple Syntax 
    a la (precise parenthesization not so important here)

    (1,2,3)

    Tuple Enumeration

    Not a language feature but allow tuple to be enumerated (IEnumerable<T>) for both homogeneous and heterogeneous tuples, meaning these two cases would both be legal

    foreach (var x in (1,2,3))
      Console.WriteLine(x);
    foreach (var x in (1,"WTF",3))
      Console.WriteLine(x);

    Where in the first case the tuple would be IEnumerable<int> and in the second case the tuple would be either IEnumerable<IDynamic> or IEnumerable<Object>.

    I would be against tuple enumeration. A tuple is not a collection and should not be considered as such. If you really want that feature, you could build it yourself:

    public static class TupleExtensions
    {
      public static IEnumerable<T> ToCollection<T>(this Tuple<T, T> tuple)
      {
        yield return tuple.Item1;
        yield return tuple.Item2;
      }
      
      public static IEnumerable<object> ToCollection<T1, T2>(this Tuple<T1, T2> tuple)
      {
        yield return tuple.Item1;
        yield return tuple.Item2;
      }
    
      public static IEnumerable<T> ToCollection<T>(this Tuple<T, T, T> tuple)
      {
        yield return tuple.Item1;
        yield return tuple.Item2;
        yield return tuple.Item3;
      }
      
      public static IEnumerable<object> ToCollection<T1, T2, T3>(this Tuple<T1, T2, T3> tuple)
      {
        yield return tuple.Item1;
        yield return tuple.Item2;
        yield return tuple.Item3;
      }
      
      ...
    }

  • User profile image
    exoteric

    TommyCarlier said:
    exoteric said:
    *snip*

    I would be against tuple enumeration. A tuple is not a collection and should not be considered as such. If you really want that feature, you could build it yourself:

    public static class TupleExtensions
    {
      public static IEnumerable<T> ToCollection<T>(this Tuple<T, T> tuple)
      {
        yield return tuple.Item1;
        yield return tuple.Item2;
      }
      
      public static IEnumerable<object> ToCollection<T1, T2>(this Tuple<T1, T2> tuple)
      {
        yield return tuple.Item1;
        yield return tuple.Item2;
      }
    
      public static IEnumerable<T> ToCollection<T>(this Tuple<T, T, T> tuple)
      {
        yield return tuple.Item1;
        yield return tuple.Item2;
        yield return tuple.Item3;
      }
      
      public static IEnumerable<object> ToCollection<T1, T2, T3>(this Tuple<T1, T2, T3> tuple)
      {
        yield return tuple.Item1;
        yield return tuple.Item2;
        yield return tuple.Item3;
      }
      
      ...
    }

    A tuple is a collection. It's just a heterogeneous collection where elements do not always have the same type. That said, using extension methods for tuple enumeration could be a pretty good midpoint between no support and built-in support.

  • User profile image
    SlackmasterK

    REPLs.  The demo just left me wanting for the days of BASIC on my TRS-80 when the command-line (if you can call it that) and the code felt interchangeable.  Doesn't seem all that useful, but really fun.

  • User profile image
    stevo_

    I think first class tuples would be useful, I would imagine extension properties make it in as its been noted that they actually agreed on a specification for how to do it, just had to cut it for 4.0 in order to shipit.

     

    Not sure about enumeration, a tuple is only a sequence in a syntactic sense, theres plenty of contexts for how you can iterate something, and I think there needs to be proper thought into what should be considered a native sequence to the language.. best bet is, does it really add anything? no, then its not worth introducing additional behavior.

  • User profile image
    wkempf

    exoteric said:

    I'll start out -

     

    Tuple Syntax 
    a la (precise parenthesization not so important here)

    (1,2,3)

    Tuple Enumeration

    Not a language feature but allow tuple to be enumerated (IEnumerable<T>) for both homogeneous and heterogeneous tuples, meaning these two cases would both be legal

    foreach (var x in (1,2,3))
      Console.WriteLine(x);
    foreach (var x in (1,"WTF",3))
      Console.WriteLine(x);

    Where in the first case the tuple would be IEnumerable<int> and in the second case the tuple would be either IEnumerable<IDynamic> or IEnumerable<Object>.

    I'll agree with tuple syntax, but the (1, 2, 3) stuff isn't the important part. What's much more important is tuple assignment.

     

    int a, b, c;

    (a, b, c) = TupleReturningMethod();

  • User profile image
    exoteric

    wkempf said:
    exoteric said:
    *snip*

    I'll agree with tuple syntax, but the (1, 2, 3) stuff isn't the important part. What's much more important is tuple assignment.

     

    int a, b, c;

    (a, b, c) = TupleReturningMethod();

    I'll buy that for a dollar. I really liked that way of "decomposing" a tuple when using SML. Both are ways to make programs shorter because ultimately you don't need it, just as you don't need foreach.

  • User profile image
    TechChaser

    I Would love to have partial publishing facility in website model applications, if there is an ASP.Net release

  • User profile image
    stevo_

    TechChaser said:

    I Would love to have partial publishing facility in website model applications, if there is an ASP.Net release

    I think this thread is specifically about language features, in terms of .net features, I'd love to see some work put into making compilation more extensible (like postsharp for example)..

  • User profile image
    daxfohl

    stevo_ said:
    TechChaser said:
    *snip*

    I think this thread is specifically about language features, in terms of .net features, I'd love to see some work put into making compilation more extensible (like postsharp for example)..

    Yeah, it would be interesting to see an application go through some programatic transform before compilation.  Something a bit more powerful than the simple #if(DEBUG) ugliness.  Maybe along the lines of a Linq to Parse Tree, or Linq to Assembly, or Linq to Attributes.  ie, you could have your precompiler set up with a set of Linq expressions, and if you wanted to do a core compile, you would choose the one that removed all the [UI]-decorated classes and methods.

     

    That would also allow a lot more flexibility for encapsulation and information hiding than the current five access specifiers, and would enable things like friend classes without explicitly adding friend classes.  ie, the Linq code could specify that classes decorated with [Tester] would have access to all methods decorated [Testable], but that no other classes would be able to see it.  That would allow the "architects" to create the attributes and write the Linq code to determine what is visible to what, while the application programmers simply create classes to work within those boundaries.

     

    Something like a formal, compilable version of a standards document.

     

    Another nice thing about doing things this way is that you gain the power of doing macro-type stuff, but since everything is just a Linq-to-Parse-Tree, it would be analyzable realtime to the editor and intellisense (just like the #if(DEBUG) is now).

  • User profile image
    Minh

    I want to have "endif"

  • User profile image
    Bass

    staceyw said:
    Bass said:
    *snip*

    Not sure that would make the cut without a suffix literal.  But something like a "B" suffix would seem to fit.

    There is no suffix literal for Int32 and Int64, try doing a var on a literal over 3 billion in value, the compiler will automatically define it as an Int64.

  • User profile image
    TommyCarlier

    Bass said:
    staceyw said:
    *snip*

    There is no suffix literal for Int32 and Int64, try doing a var on a literal over 3 billion in value, the compiler will automatically define it as an Int64.

    var i = 123L; // the type of i is long/Int64

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.