I would have thought that all your points could equally be asked about generics themselves.
Printable View
I would have thought that all your points could equally be asked about generics themselves.
There are two ways to answer this question....Quote:
I would have thought that all your points could equally be asked about generics themselves.
1) If writing common, typesafe code is not a significant feature then the topic is immaterial to the language decision, and C++ has no advantage over C# because of this issue.
2) The ability to write code once that will work in a typesafe manner is significant from both a development and maintenance perspective. In this case, my argument is that generics provide sufficient capabilities compared to templates, that impact at the higher levels is insignificant.
Mmm.. but that isnt really the point of the question.. We arent looking at generic as a standalone.. The question calls for a demonstration of the difference between templates and generics in any case(s) of a/b/c/dQuote:
Originally Posted by Zaccheus
The question poses real-world hurdles run into during development, and basically asserts that both generics and templates, assist or detriment to the same degree with the process of clearing those hurdles. Ergo, the assertion is that generics and templates can be considered equivalent in a "real-world" scenario.
If the cap fits..
Non-generic C# is typesafe. If you cast a reference to the wrong type, you merely get an exception.
Now as far as I know, .net generics cannot operate on unknown types. For example, you cannot write a generic vector class which supports the usual 3D vector operations.
It may not be a commercial project, but for my Gravel hobby project I would have liked to implement the whole gravity simulation as a generic class, such that any number type can be used. I don't think this is possible.
I'm still kinda choosing, but I'm going for C#/C++
I've got some basic things down... If statements, hello world... That's about it :p
But yeah, I decided to jump into the deep end. I'll be looking for some source code first, it's so much easier to understand when you can read it easily :)
Nalk about a nonsensical statement. You can go for C# or C++/CLI, or even a combination of the two, but there is no such thing as "C#/C++" :rolleyes:Quote:
but I'm going for C#/C++
In general when talking about "typesafe" the discussion is at build (compile) time.Quote:
Non-generic C# is typesafe. If you cast a reference to the wrong type, you merely get an exception.
Remember the rule of "tens"
A error in the initial concepts that would cost $1 to fix....
Will cost $10 if it is caught at the final architectre phase
Will cost $100 if it is caught at the final design phase
Will cost $1,000 if it is caught at the final design phase
Will cost $10,000 if it is caught at the final QA (testing) phase
Will cost $100,000 if it is caught at the customers site.
For professional software packages these numbers can actually be fairly acurate....
Ok, in that case how are you using reflection in C# to replace the flexibility of templates ?Quote:
Originally Posted by TheCPUWizard
Also, any comment on the viability of writing a 3D vector class using generics ?
Didnt you hear? MS have taken a keen interest in this thread, saw the folly of their ways and now are drawing up the next version of these languages, which will be an effective merge of the two.Quote:
Originally Posted by TheCPUWizard
Oh and everyone who posts in this thread will also get $10K from Bill himself!
I assumed he was talking about sitations that generate an InvalidCastException..Quote:
Originally Posted by TheCPUWizard
Remember kids, weeks of coding can save you hours of planning! ;)Quote:
For professional software packages these numbers can actually be fairly acurate....
I forgot this one:Quote:
Originally Posted by TheCPUWizard
In C++/CLI there is built in support for indexed properties. This support actually exists in .net, but C# does not expose it, forcing you to write indexer helper classes.
Um.. do you assert that templates write code at runtime?Quote:
Originally Posted by Zaccheus
Um ... no, I'm saying reflection happens at runtime.
Agreed, but these are typically trivial when necessary, and there is always the option of exposing a collection as a property, so no additional class may be necessary....Quote:
In C++/CLI there is built in support for indexed properties. This support actually exists in .net, but C# does not expose it, forcing you to write indexer helper classes.
Agreed, but I am trying to figure out what this has to do with the discussion, properly designed, reflection does not necessarily mean that there is the introduction of any non type safe items [although they surely can be introduced....Quote:
Reflection occurs at runtime.
There will always be workarounds, but I think it is undeniable that C++/CLI has a few nice features which are not in C#.