|
Inheritance is a useful tool for encapsulating state and/or behaviour. It can be overused, but at the moment in C# it doesn't introduce any contradictions or ambiguity. C# doesn't have multiple inheritance, so it doesn't suffer from the "diamond problem"[^].
I'm still struggling to see what problem you think your idea would solve. All I can see is code where I can't tell whether you meant this FooBar.Baz class, or that FooBar.Baz class, because they both have identical names.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Wiep Corbier wrote: It is a nice to have for me and probably someone else. Not really. Even if the feature were there, when you went back a day later and looked at your code you'd have no idea which class the code was referring to.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Richard Deeming wrote: There has to be some way to disambiguate the two people. I think the OP is asking for the computer to do that. In other words I write
SomeClass temp = new SomeClass();
and up pops some intellisense so that I can pick SomeClass from file1 or SomeClass from file2. Internally, C# would clearly have to track which one it is. Which makes this idea even worse because if you come back the next day to read your code you won't know which one it actually refers to.
It could be done, and probably not too hard with some sort of internal tracker in VS but a terrible idea regardless.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Wiep Corbier wrote: A person walkes in and asks for Richard. People will ask, which Richard? (popup intelli)
OK, how is the compiler going to "popup a dialog" to ask which version of the class you want when you try to "new it up"?
CandidateFunction newCandidate = new CandidateFunction()
WHICH "CandidateFunction" does the code "new up"? How is it going to know? There's no way for the compiler or the code to generate a prompt to ask. Even if it was possible, the UI type of the app comes into play. Is this a Console app? Windows Forms? WPF? ASP.NET? Each handles prompting the user is different ways, so how is the compiler to know which to use?
Oh, and how about apps with no user interface at all, like Window Services and WebAPI? How is that prompt supposed to show up?
This would have to be prompted for at compile-time. There's absolutely no way to do this at run-time.
On top of that, how is the compiler to know which type of object it is when you go to use that object elsewhere?
Did you really think about this before posting? If you want this, then it's your skill set that needs to be improved, not the compiler.
|
|
|
|
|
Wiep Corbier wrote: But imagine this. You work in a office room with a colleguea also called Richard.
A person walkes in and asks for Richard. People will ask, which Richard? (popup intelli)
Got it?
I think he got it at the very beginning.
But at which point do you want the intelli pop up to come?
At compiling time... ok, do you know with of the functions is needed in each 62 places where the name is used?
Maybe you do now... but then you go to another project and then you have to make some additions 3 or 4 years later... or you leave and another guy gets in your project... or the project is so big that there are several people working on the same area at the same time... good luck when compiling (and don't forget to start one hour before the test because you will need some time to click all popups).
At execution time... how will the user know, which class is the one needed? Ok, maybe your user knows it, but how will my user know it? Or the new customer's employee.
What are the consequences of a bad selection? Good if I see I have selected the wrong option soon enough, but what if they don't realize it? Are the differences between the classes compatible? Will you need plausibility checks? How can you choose which plausibility check is needed each time?
it is already difficult enough to get the exact result you (and they) want as it is, if you add ambiguity on top... I don't even want to imagine it.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
modified 22-Jun-20 12:30pm.
|
|
|
|
|
No.
Because - frankly - it's a dumb idea. Selecting class types at run time based on what the user decides is a recipe for convoluted, messy code that doesn;t work well in practice because users are not developers. That means that have no idea what a class is, or why they want to select one.
If you want users to decide what to create, ask them "Do you want a Candidate, or a Candidate with skills?" and explain what the difference is in their terms and what effect the decision will have. You cannot "leave that to the system" and get them to choose based on two similar names.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wiep Corbier wrote: Will this ever happen and if not, why not? I hope not. There is enough confusion in programming languages without adding to it.
|
|
|
|
|
What this, another Richard?
|
|
|
|
|
Yes, but if you check my full name you will find I am different from the other one (he knows much more than me).
|
|
|
|
|
So, it is possible to have more than one Richard.
Maybe this could be true for Classes. Not yet, in the future.
|
|
|
|
|
Wiep Corbier wrote: So, it is possible to have more than one Richard. Yes, but you can tell which is which by our full names.
Wiep Corbier wrote: Maybe this could be true for Classes. Not yet, in the future Not ever; as mentioned more than once, it's a dumb idea.
|
|
|
|
|
Like electric cars, dumb idea, petrol heads said.
Because, they don't know better.
|
|
|
|
|
Which has absolutely nothing to do with your question.
|
|
|
|
|
That is true. It has to do with the fact you call it dumb.
That isn't very constructive.
But don't waste your time on me.
|
|
|
|
|
Sometimes, the most constructive thing you can be told is "that is a dumb idea - don't waste any more of your time on it". And one of the hardest things we have to do as developers is recognise that fact about our own stuff and throw it away and start again.
We all do it: I had a brilliant scheme laid out - pages and page of design documents, using abstract classes to their full extent: everything was beautiful, it would be perfect. Except ... C# doesn't have abstract static methods . And for very, very good reasons.
So the whole lot: design, code, the whole idea was a pile of garbage, and I had to chuck it and start again.
That really is hard to do, but it's part of the job. Yes, I could have bodged round the problem, hacked it here, forced it there - but the result would be clumsy, hard to work with, and difficult to maintain; as well as having a lot of "holes" for bugs to hide.
Trust us: this is an idea you should drop!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That is what car makers told Elon Musk.
Trust us, your idea is never going to work.
They said: Where do you get electricity? How do you store your energy source? What will be the range? Etc.
No, the big shots told him: it will not work.
Tesla is today the biggest car builder.
If you think in unpossibilities you will never innovate.
|
|
|
|
|
Wiep Corbier wrote: It has to do with the fact you call it dumb. I don't call it dumb, it is dumb. And the argument re petrol or electric cars is not even remotely connected. Electric cars are all easily identified as different from their petrol counterparts.
Wiep Corbier wrote: don't waste your time on me. At last a sensible suggestion.
|
|
|
|
|
Ten years from now, kids will honestly believe that Elon Musk invented the electric car, and all later (and earlier) electric cars are derived from the Tesla series.
|
|
|
|
|
Well they have to teach them something in school.
|
|
|
|
|
Richard MacCutchan wrote: Well they have to teach tell them something in school. Teaching is slowly disappearing, specially quality teaching
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Invalid comparison. That's not even close to what your original post is about.
You're thinking of the problem you posted about in terms of people, not in terms of a computer. When building your car, which engine is the car supposed to get, gas, diesel, or electric, if they are a class called Engine? How is the computer supposed to know?
Change your mindset.
|
|
|
|
|
Asking questions is a skill
I will never ask a question on this platform again.
Thanks for your reply. Have a nice day.
|
|
|
|
|
Why is asking questions a skill? Because you have to think about your question before you ask it. Think about the context your question falls in.
All you said was "I want this, and it's up to the experts to solve it". Well, the experts just told you your idea isn't workable at all and you just stomped off.
But, actually, the idea is kind of workable, but it would involve converting C# to an interpreted language instead of compiled. It would also involve rewriting the type resolver to examine the code ahead to attempt to find the "best fit" at runtime based on insufficient information. This wouldn't even work in all cases as there isn't enough information at runtime to even "new up" an instance you haven't used yet.
This would also have the effect of destroying the performance of the language because of all of the overhead of trying to guess at which type you were talking about!
|
|
|
|
|
Wiep Corbier wrote: I will never ask a question on this platform again. That's not the right approach.
My observation is that you had a clever idea and wanted to share. That's great and awesome and thank you for doing that. I think where this went south is that you wanted everyone else to think it was clever and no one else has. That's fine. Don't take it personal. If you think it's a great idea pursue it and prove everyone wrong. Don't run away just because no one agreed with you.
Don't take these posts personal. No one is attacking you, they were just attacking the idea. But keep having ideas. That's how innovation happens.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I'm going to start by pointing out the most obvious thing. Your two POCO's have different implementations. Bear with me, because this is important for the rest of the discussion.
As these two POCO's have different properties, you have an immediate issue which is, what happens when you want to consume your code? You have Skills as a string in one, and a List of strings in the other. The code that calls this is going to have to conditionally choose the operations to perform on the Skills based on the "popup". Now, you might have additional operations that chain off those operations, so you might have a POCO Skill class that looks like this:
public class Skill
{
public int SkillId { get; set; }
public string SkillRange { get; set; }
} and another one that looks like this:
public class Skill
{
public int SkillId { get; set; }
public List<SkillRange> SkillRange { get; set; }
} And maybe you have another class that looks like this
public class Skill
{
public Guid SkillId { get; set; }
public string SkillRange { get; set; }
} For good measure, our codebase has this one thrown in
public class Skill
{
public Guid SkillId { get; set; }
public List<string> SkillRange { get; set; }
} We are creating a real mess of code here that we are expecting someone to be able to grok easily. The more we add to the code base, the harder it will be to keep these in line, and we have violated clear code principles. Why have we violated this? Suppose we have some consuming code that looks like this:
Skill skill = GetPopulatedSkill();
var id = skill.SkillId;
ValidateSkillRange(skill.SkillRange); What validation are you expecting ValidateSkillRange to be doing? Is it a string.IsNullOrWhiteSpace check? Perhaps you just want to ensure it's not an empty list. Perhaps you need to iterate over items in the list and check certain values in there. The problem is, unless you start covering all of the different combinations of cases, the compiler isn't going to have the last scooby of a clue how to fix this, even if the user, by luck, picks the correct one. Bear in mind that you may have different parts of your code needing different Skill implementations at different points; you're expecting the user to be able to guess which one needs to apply at each point in the chain. This is not a useful feature, and it's certainly not one you could test.
If you don't believe us, please raise it as a feature request against C# (the language is open source after all). Perhaps you'll believe them.
|
|
|
|
|