Git Product home page Git Product logo

Comments (5)

morganbr avatar morganbr commented on June 8, 2024

If it doesn't hurt size/perf (which it shouldn't with inlining), C# conventions are to never expose public fields. What do you think of get-only properties (and sometimes primary constructors) from C# 6.0? The syntax looks like:

struct LocalDefinition (TypeDesc type, bool isPinned) // constructor parameters go next to the struct delcaration
{
    public int SomeReadOnlyInt { get; } = Math.Max(3, 4); // Can do some logic here
    public TypeDesc Type { get; } = type; // Can read constructor parameters here
    public bool IsPinned { get; } = isPinned;
}

from corert.

MichalStrehovsky avatar MichalStrehovsky commented on June 8, 2024

That C# 6 syntax is disgusting.

Although I do admit that in this case it has a nice side effect of making something that becomes de facto read only.

Not sure if we build with Roslyn on OSX and Linux though.

from corert.

stephentoub avatar stephentoub commented on June 8, 2024

FYI, the primary constructors feature was cut from C# 6

from corert.

jkotas avatar jkotas commented on June 8, 2024

C# conventions are to never expose public fields

This convention is for public types in frameworks. It was invented so that the type implementation can change without breaking the framework public surface.

The type system is not designed to be public framework. It is our internal implementation detail. We do not need to follow the guidelines for public frameworks in the implementation. We should prefer concise tight code instead - that the guidelines for public frameworks are often in conflict with.

from corert.

janvorli avatar janvorli commented on June 8, 2024

I'd also prefer public read-only fields.

from corert.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.