Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best Proposals c# 7.0 #11537

Closed
luciedefraiteur opened this issue May 24, 2016 · 13 comments
Closed

Best Proposals c# 7.0 #11537

luciedefraiteur opened this issue May 24, 2016 · 13 comments
Labels
Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. Discussion Feature Request
Milestone

Comments

@luciedefraiteur
Copy link

luciedefraiteur commented May 24, 2016

My Proposals for c# 7.0

1: REFLECTION ON PURE DYNAMIC INSTANCE

  1. make a class in a dll loaded at runtime
  2. use an instance of the class with reflection to list class members

Expected Behavior:
list members

Actual Behavior:
error

2: CLASS SERIALIZATION
`
// NOTHING IN THIS CLASS IS MADE FOR SERIALIZATION PURPOSE
public class SmthgVeryComplicatedThatIDontKnowWithManyProperties
{
//...
}

public class SerializationTest
{
public byte[] Serialize(object smthg)
{

}

[System.UniversalFunction]
float someCoolFunctionWithoutClass()
{
}

public static int Main()
{
var smthg = new SmthgVeryComplicatedThatIDontKnowWithManyProperties();
// would be so cool if whatever the object is, we could just serialize the memory of it and unwrap it
//back later. Would be greater as well working with dynamic things loaded at runtime.
var serialized = Serialize(smthg);
string serializedUniversalFunction = SerializeFunction(someCoolFunctionWithoutClass);
console.WriteLine(serializedUniversalFunction);
// output idk some nicely arranged data describing function that is easy to parse and eval in another
// language, and bindings in many languages.
// function should not contains types that dont have [System.UniversalClass] attribute
// Generics have universal bindings, if Element Type has System.UniversalClass attribute, and
// int, float, etc.. have universal bindings too.
// for, while, etc... have universal binding too.
// lot of things not usable but would be so cool if we could just send a function to a javascript
// server/client, unpack it and use it.

}
}
`

3: MORE REFLECTION TOOLS
`
public class HasManyMethods
{
public void Method1(){return;};
public void Method2(int smthg, float smthgelse){return;};
public int Method3(int smthg)
{
return (smthg * 2);
}
}

public class Program
{

public static int Main()
{
HasManyMethods test = new HasManyMethods();
MethodInfo[] methods = test.GetType().GetMethods();
MethodInfo method = methods[0];
** Console.WriteLine(method.name + method.lineNumber + method.fileName + method.text); **

}
}

`

@AlgorithmsAreCool
Copy link

  1. This is possible today with lightweight code generation in the System.Reflection.Emit namespace.
  2. What does it mean to serialize a type? If it is not value types all the way down you end up needing to serialize the object graph or worse yet trying to store object references persistently. Which is a very bad idea.

@luciedefraiteur
Copy link
Author

yea but if c# has native things to serialize root binary data of object graph would be cool.

its a bad idea right now, of course, but for example, javascript can serialize a whole object without knowing a shit about it.

@luciedefraiteur
Copy link
Author

bad ideas are only bad ideas until they run well with correct implementation. Store each references persistently if needed, maybe a parameter of compilation would do it, idk, so peoples arent forced to use it.

Why not save references persistently? Maybe some binary file used with programs targetting that type of things.

Also, ability to make dump of a whole program would be cool too.

@luciedefraiteur
Copy link
Author

luciedefraiteur commented May 24, 2016

maybe add maps of object graphs from the begining and know a reference is only a reference of object having refs... value type members...

i talked about ref 512254... we serialize ref 512254, he talk about ref 521424, we allready spoke about ref 521424...

and add options to not serialize references, not serialize references of type, not serialize until that lvl of deepness in ref

edit: and graphs maps automatically generate protocol buffer templates used later for serializations/deserialization

edit1: that would be cool for user side scripts use, like in game engines, modelization engines/tools etc... that i love to do.

edit2: add a big math/physic/graphic/pathfinding/self learning library to System, that'd support either opengl or latest direct x (just a boolean to change), with really high lvl bindings. (And, make use of graphic card for most calculations, when possible)

edit3: also add direct support for socket.io(client AND server)

edit4: do all that and i think c# become the best language ever, and i think world technology/games/tools explose from everywhere.

@AlgorithmsAreCool
Copy link

Whoa, whoa slow down a bit.

bad ideas are only bad ideas until they run well with correct implementation. Store each references persistently if needed, maybe a parameter of compilation would do it, idk, so peoples arent forced to use it.

The reason it is bad difficult is because ref 1234 in my machine right will not be the same as any of these:

  • ref 1234 on your machine
  • ref 1234 in another process instance (or app domain) on my machine
  • ref 1234 5 minutes from now after the object has been nulled and garbage collected

You would need to store persistent copies of every object that was referenced by a serialized object. This is not impossible, in fact it is very common. But it involves a database that lives outside of the process, which turns this from a serialization technique into an ORM

Another concern with this is what about objects that need initialization or special setup. Some objects require certain constructors or init methods to make them valid according to business rules. Also what about objects that look like this:

class myAnnoyingType
{
    private readonly string MyMachineName = System.Diagnostics.Process.Current.Id;
...
}

This type holds data that assumes it the PID will not change, and moving it out of process could violate that assumption.

I am assuming that when the .Net BCL design team was looking at serialization, they assumed that it was only really safe to serialize types you had control over (and therefore could mark them ISerializable) and a few simple primitives and collections.

Also, ability to make dump of a whole program would be cool too.

It would hypothetically be powerful and useful to dump a whole program and send it to another machine, but i think real world objects that could depend on machine/process local data would not always be safe to freeze and ship anywhere in this manner.

maybe add maps of object graphs from the beginning and know a reference is only a reference of object having refs... value type members... i talked about ref 512254... we serialize ref 512254, he talk about ref 521424, we already spoke about ref 521424...

This is a common pattern today, except instead of moving the objects directly, the reference is a Primary Key in a database that is passed around. Now purely for the sake of argument i could imagine a type of shared memory space where you can call objects across the wire transparently and i think it would-.

Wait a minute, that is .Net remoting. You're asking basically for .Net remoting i think.

@AlgorithmsAreCool
Copy link

edit2: add a big math/physic/graphic/pathfinding/self learning library to System, that'd support either opengl or latest direct x (just a boolean to change), with really high lvl bindings. (And, make use of graphic card for most calculations, when possible)

This kind of request should be in dotnet/CoreFX. But is probably best left as 3rd party libraries and NuGet packages.

edit3: also add direct support for socket.io(client AND server)

Does System.Net.Sockets not work well enough for your usecase? Or what about the super fast libuv based socket work in aspnet/Kestrel

edit4: do all that and i think c# become the best language ever, and i think world technology/games/tools explode from everywhere.

C# is many things to many people, but it cannot be everything to everyone and nobody is completely happy with it i would imagine. Picking the correct set of features is very very difficult and needs to balance a lot of things, most notably time and resources. Eric Lippert has written a lot about these problems.

As a contrast I wanted Destructible Types and Move to make C# 7 awesome but...well...it didn't make it.

@HaloFour
Copy link

C# 7.0 is pretty much locked up right now. You can feel free to propose stuff for future versions. You might want to start by breaking this up into multiple separate proposals and target them specifically as what components would be effected. Include use cases. You'll also be expected to actually provide implementation details.

I don't see much here that has anything to do with C# or the Roslyn compiler.

1 is already handled by dynamic modules and reflection. It's pretty easy to emit completely dynamic types with dynamically constructed methods. And you can reflect over those methods just like you could any other assembly.

2 sounds like it belongs in the corefx repo, although it is fairly vague. Most of it sounds like it would be covered by binary serialization, which has always existed in the full framework but doesn't currently exist in the core framework.

3 sounds like it could apply to Roslyn, but it could probably be covered by generators by emitting replacement methods which have attributes to the original source file locations. Or corefx could add helpers which can correlate assemblies with their debugging symbol databases. As for the original function text, why exactly do you think that would be useful? What if the assembly is compiled in one of the other several dozen BCL-targeting languages?

@luciedefraiteur
Copy link
Author

@HaloFour
1: yea but use that emit things is damn boring. (but i ll look at it for more arguments, just using .GetType().GetProperties() would be better.

2: yea, but i think serializations apis are really boring right now, even the ones from the framework.
If serialization fail, exception, and cant set parameters or what to tell to just ignore them.
I dont know maybe im wrong but i had very bad experiences trying to make user scripts serialized well without asking them to put attributes over each things.

3: if the assembly is compiled in one of the other several dozen BCL-targeting languages, so it would not work to get the function text, no problem.
why i think it would be useful: i write actually a typescript/nodejs server, with logic frames, to work with Unity3D.

  • i wanted to make types generated from the serialization function of the components overriding my base networked component, i did it, so types are generated to server automatically (and once) from the data sent in JSON.
  • i think its very boring to write functions related only to networked game logic twice, one time on server typescript, one time on client c# (logicframes need server to eventually evaluate game at a given time, just like clients would have done, to verify wich player gave corrupted data, and eventually ban him for cheating). So if at least i would have a way to find methods implemenations when they have special attributes [TempestNetwork.NetworkedMethod],
    so i would have parsed and made those methods turn to typescript code when it can be done, and throw exception in unity editor if not. (Actually i found a workaround, but could be cool to get a method/function text for other networked things in other kind of contexts)

@gafter gafter added Concept-API This issue involves adding, removing, clarification, or modification of an API. Discussion Area-Compilers Feature Request labels May 26, 2016
@AlgorithmsAreCool
Copy link

AlgorithmsAreCool commented May 26, 2016

@gdefraiteur I reformatted your original post

1: REFLECTION ON PURE DYNAMIC INSTANCE

make a class in a dll loaded at runtime
use an instance of the class with reflection to list class members

Expected Behavior:
list members

Actual Behavior:
error

2: CLASS SERIALIZATION

// NOTHING IN THIS CLASS IS MADE FOR SERIALIZATION PURPOSE
public class SmthgVeryComplicatedThatIDontKnowWithManyProperties
{
    //...
}

public class SerializationTest
{
    public byte[] Serialize(object smthg)
    {

    }

    [System.UniversalFunction]
    float someCoolFunctionWithoutClass()
    {
    }

    public static int Main()
    {
    var smthg = new SmthgVeryComplicatedThatIDontKnowWithManyProperties();
    // would be so cool if whatever the object is, we could just serialize the memory of it and unwrap it 
    //back later. Would be greater as well working with dynamic things loaded at runtime.
    var serialized = Serialize(smthg);
    string serializedUniversalFunction = SerializeFunction(someCoolFunctionWithoutClass);
    Console.WriteLine(serializedUniversalFunction); 
    // output idk some nicely arranged data describing function that is easy to parse and eval in another 
    // language, and bindings in many languages.
    // function should not contains types that dont have [System.UniversalClass] attribute
    // Generics have universal bindings, if Element Type has System.UniversalClass attribute, and 
    // int, float, etc.. have universal bindings too.
    // for, while, etc... have universal binding too.
    // lot of things not usable but would be so cool if we could just send a function to a javascript 
    // server/client, unpack it and use it.

    }
}

3: MORE REFLECTION TOOLS

public class HasManyMethods
{
    public void Method1(){return;};
    public void Method2(int smthg, float smthgelse){ return; }
    public int Method3(int smthg)
    {
         return (smthg * 2);
    }
}

public class Program
{
    public static int Main()
    {
        HasManyMethods test = new HasManyMethods();
        MethodInfo[] methods = test.GetType().GetMethods();
        MethodInfo method = methods[0];

        Console.WriteLine(method.name + method.lineNumber + method.fileName + method.text); 
    }
}

@AlgorithmsAreCool
Copy link

Also @gdefraiteur,

For runtime code generation, have you looked at the Sigil Library?

And for the reflection helpers, do the newish Caller Info Attributes?

@gafter
Copy link
Member

gafter commented Jul 18, 2016

@amcasey Would some of the interactive facilities satisfy this request?

@gafter gafter added this to the Unknown milestone Jul 18, 2016
@amcasey
Copy link
Member

amcasey commented Jul 18, 2016

@gafter, @tmat might have a more up-to-date understanding of the implementation and goals of the interactive facilities.

@gafter
Copy link
Member

gafter commented Jan 3, 2017

C# 7 is now closed to additional features. If there are specific features that you would like included in future versions, please open a separate issue for each.

@gafter gafter closed this as completed Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. Discussion Feature Request
Projects
None yet
Development

No branches or pull requests

5 participants