Discussion : Name constructor with keyword instead of name #1928
-
I find it tedious to repeat the name of a class each time I declare a constructor. IDE helps but still, I see no added value to just repeat the class name. I propose the addition of "ctor" keyword to be used in place of the constructor name. Could also use "dtor" for finalizer. Even IL understands it. It already use that syntax. Anyone has an opinion on this? |
Beta Was this translation helpful? Give feedback.
Replies: 22 comments 40 replies
-
@ebfortin Can you please clarify? Are you talking about use of the type name when constructing an instance, or when declaring the constructor as a part of the definition? I thought it was the later, but the comment from @jnm2 has me questioning whether I read your proposal correctly. |
Beta Was this translation helpful? Give feedback.
-
It seems highly unlikely C# would change here. Having two ways to do something, where the new way provides only a tiny amount of marginal benefit, would likely not be desirable. |
Beta Was this translation helpful? Give feedback.
-
@theunrepentantgeek My mistake, they are talking about declaration. |
Beta Was this translation helpful? Give feedback.
-
When declaring. |
Beta Was this translation helpful? Give feedback.
-
@ebfortin Just type |
Beta Was this translation helpful? Give feedback.
-
Answers here, seem to be very DRY.
Same goes with arrow syntax method definitions... but everyone agrees they are much more brief. |
Beta Was this translation helpful? Give feedback.
-
That was a case where there wasn't a "tiny amount of marginal benefit".
See: https://blogs.msdn.microsoft.com/ericgu/2004/01/12/minus-100-points/ Or, as Eric Lippert mentioned:
This has never been the case.
You are mistaking 'haven't been actively working on' with 'not caring'. The C# LDM is interested in a wide variety of topics, and has been for decades. But features cost. It is literally zero sum. If you take time and effort to work on a certain set of features, that time and effort is not available for others. So what you see developed are the set of things that are felt to provide a great bang/buck ratio for the development ecosystem out there. |
Beta Was this translation helpful? Give feedback.
-
It is always something or the other. You can't have all the cake right? 🍰 So it makes sense with silly and expensive features, or great but also very expensive features to lay them in priority queue and wait until they probably die off. I don't buy it. I don't see clear way features got selected. |
Beta Was this translation helpful? Give feedback.
-
It's not anyone's job to get you to buy anything :) I'm simply explaining how language design is actually done. And i'm doing that through my actual experience on the LDM team :)
Yes. That's exactly right. Language design is highly opinionated. First, someone has to be opinionated enough to propose something. Then an LDM member has to be opinionated enough to champion it. Then, all hte opinions of the rest of the LDM are brought in during the design of the feature. 'Opinionated' is one hte best words i could come up with for the process :)
I don't see why the 'apart' part is relevant. It's like saying: apart from the reasons you did this, what were the reasons you did this? Brevity was the reason. in general the existing statement form added two additional lines, and four extra tokens. For the types of trivial, but common, methods that could use this feature this was a substantive overhead.
Ok. Don't get started on that :) |
Beta Was this translation helpful? Give feedback.
-
In not so far future...
|
Beta Was this translation helpful? Give feedback.
-
Yet you exhibit support for this which seems suffer from the same drawbacks: Another way of writing a switch that "provides only a tiny amount of marginal benefit" - or am I missing something? |
Beta Was this translation helpful? Give feedback.
-
Yes. As i mentioned in the other issue, the feature has already been championed. Meaning the cost of it has already been assessed to be less than the gain overall to the language. It's not the case of:
It's the case of:
-- Here's another way of thinking about it. Imagine any proposal has a fixed cost of 1000 LDM-bucks. That's expensive and needs to present a lot of end value to the user for the LDM to pay that much. Switch expressions are currently at having value of 10k LDM bucks. So upping that cost to 10,005 to support consistency here is not really that different. However, having to go and spend the 1k LDM-bucks just to do a new way of doing constructors is just not there. Maybe in the future if the LDM is doing a lot of constructor improvements, and the overall benefit is worth it, this could be rolled into that. But paying so much to get a tiny marginal benefit is non-sensical. |
Beta Was this translation helpful? Give feedback.
-
Of course I am in no position to even estimate cost so I can't comment on that, perhaps you could explain (if you have the time) the cost estimate for some of the proposals we make including this particular one? That can only help us going forward, to understand the true costs of some of the stuff we suggest here.
I'm gonna take some convincing to see the utility in the trailing comma support. Your increasing the scope for unintended errors to go undiagnosed. Right now if someone edits code, copies, pastes etc and in error either removes the true end element or inserts something not intended to be the end element they'll get told off by the compiler. With this change either scenario is regarded as valid and under the above user edit scenarios a potentially true error will go unreported and perhaps out into the production world. Any developer who claimed this was a real help to them in day to day work would also make me wonder about their skills. So my vote (if that means anything, which I doubt!) is to deny this. |
Beta Was this translation helpful? Give feedback.
-
Every new feature has a high fixed cost (it's like passing a bill). You have the meetings with everyone involved. The impls, the testing, the context switching, the doc'ing, the shipping. It's a huge fixed cost to even get a feature down this path and this is honestly close to zero-sum. If the time is spent on htat, it's not spent on other things that deliver more value. However, once you've decided to go down this path and you've paid the fixed costs, then changes/tweaks to something in flight is much less costly. You already hve someone working on the design/grammar/impl/tests/etc. so saying: can you just tweak things to support X is much less costly. Indeed, it basically just rolls into the normal cost that you've already accepted as being worth it to pay for this feature. Of course, if someone comes along and says "please tweak like so" and that tweaking doubles the cost, then it won't be considered the same as a tweak that basically takes 5 min of time. |
Beta Was this translation helpful? Give feedback.
-
The change was approved. The people who needed to be convinced were convinced :)
What unintended errors?
I don't know what this means. On hte other hand, we have ample experience that shows that supporting a trailing comma is not actually a problem in practice (i.e. all the other places in the language that allow this), and it makes for a definitely nicer experience across all editors. It's not uncommon for people to keep needing to add elements to the end of a list that are very similar to the previous element. Being able to just copy/paste that last element is a routine operation done by many devs across many IDEs/editors across many languages. This routine op has a roadbump in it today that is just being removed. Given the experience that shows this doesn't lead to problems, and given the nicer experience this provides, it's simple to roll this work into the already approved feature which is coming down the pipe. |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi |
Beta Was this translation helpful? Give feedback.
-
I'll confine my remarks about the trailing comma to that thread, I apologize for derailing this one! |
Beta Was this translation helpful? Give feedback.
-
Historically, by the LDM members using their expertise and experience to weight/order things. It's generally a continuous process, with certain points in product cycles being used to reasses/reorder things. It's the same way i can read a proposal on a suggested IDE feature and generally give a very precise assessment of the cost to do that feature (including what sort of design tweaks could be considered, and how they would vary the bang/buck outcome of the work). Because nearly all of the LDM has actually worked with the language for years,and have been involved directly with the both the impl and the end-to-end process to start with a proposal and take it all the way to a released product, it's pretty easy for them to come to consensus here. Note: not everything works out that way. For example, NRT was something known to simply be so humongous and so impacting across teh language that it was known that the only way to even get a sense of it was to just 'do it'. For something this large, this would then be a continual process of exploration/impl/assessment to see if the direction things were going, and the results that were being achieved would justify the costs involved. But most everything else can be assessed apriori without needing this sort of approach. Similarly, 'code generators' was felt to have absolutely staggering value to users. However, early explorations into this space also revealed such a huge amount of unforseen work that this was tabled until more adequate funding and a more appropriate time could be found for this. |
Beta Was this translation helpful? Give feedback.
-
Please can we re-review this? Clear violation of the DRY principle, and with probably millions of C# classes in existence, this is an impactful change. With regard to @CyrusNajmabadi last comment, how can you know if there is unseen work? This seems like an easy change to me. |
Beta Was this translation helpful? Give feedback.
-
I think a syntax for static constructors or destructors wouldn't be bad either. Currentstatic MyClassName() {}
~MyClassName() {} My ideastatic constructor { // I think these paratheses are in this case unnessecary because no static ctor or destructor can have parameters
}
destructor {
} |
Beta Was this translation helpful? Give feedback.
-
Would this be considered an |
Beta Was this translation helpful? Give feedback.
It seems highly unlikely C# would change here. Having two ways to do something, where the new way provides only a tiny amount of marginal benefit, would likely not be desirable.