|
There's an example of Duck Typing using 'dynamic in C# 4.0 on Wikpedia: [^].
Looking at the code, and how it is used, makes me ... nauseous.
“There are obvious things, and there are many obvious things no one tried, because no one needed to try them.” Sergey Alexandrovich Kryukov, January 1, 2014
|
|
|
|
|
Check out the article that the OP linked - it's Eric Lippert (a long time C# compiler writer until he recently left MS) specifically linking to that Wikipedia article and picking apart what it says about Duck Typing.
He even specifically derides that C# dynamic explanation you noted offered by that article.
|
|
|
|
|
See this:
http://www.google.com/search?q=c%2B%2B+compile+time+polymorphism[^]
For instance, in a C++ template, you can do something like this:
template <class T> class Foo: public T
{
int Baa(int k)
{
T * pT = static_cast<T*>(this); return 42 + pT->Baz(k - 3); }
};
Any class that exposes a method Baz that returns something that can be converted to an integer, and can be called with an integer parameter, can be a template paremeter for class Foo. No special interfaces required, so it is less restrictive than, for instance, C# generics.
Aside: 'less restrictive' doesn't mean 'better', or 'worse'.
Also, the code above is resolved at compile time, which may have a noticeable impact on performance.
Duck typing is also used in Javascript, for other reasons (mostly, IMHO, flexibility).
JM2B,
Pablo.
"Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).
"You are to act in the light of experience as guided by intelligence" (Rex Stout, "In the Best Families", 1950).
|
|
|
|
|
Ah yes, the Curiously Reoccuring Template Pattern reoccurs....
Templates are highly infectious, suddenly everything working with this type(s) has to be a template over that type. Templates still affect the tool chain significantly, and have some problems with other features (such as static data).
There is no explicit statement what T needs to support. Foo<T> can be instantiated for any struct / class typetype:
struct cool {};
Foo<cool> x;
x.Baa(17);
In a real app you can expect a dozen of "cool candidates", some that work and some you wish they did and that Baa() call ist hidden in deep jungle of calls, throwing error messages about a dozen of templated types you never heard of.
Duck Typing (or C++ concepts) would allow to reject early, at the instantiation of Foo<cool>.
|
|
|
|
|
C# has been internally using duct typing for a very long time.
Link says: For example, the C#’s foreach operator already uses duck typing. This might be surprising to some, but to support foreach in C# you don’t need to implement IEnumerable! All you have to do is:
Provide a public method GetEnumerator that takes no parameters and returns a type that has two members: a) a method MoveMext that takes no parameters and return a Boolean, and b) a property Current with a getter that returns an Object.
Source[^]
|
|
|
|
|
I think in a statically-typed language, Duck Typing would subvert all of the strengths of that environment. Indeed, Interfaces provide all of the function offered by Duck Typing, with the additional benefit of compile-time type checking.
Duck Typing, to me, is more of an approach or way of thinking than an actual type system. In dynamic languages, with no compile-time checks, thinking in terms of "duck typing" can be a tool for designing code structure.
In most cases, IMHO, if we work in a static language and think "duck typing" we should immediately think "interface" instead.
|
|
|
|
|
I thought you meant this[^]. My bad...
Will Rogers never met me.
|
|
|
|
|
|
Awesome thanks for the link!
|
|
|
|
|
Thank you for the link. Fantastic!
Dave.
|
|
|
|
|
SO I go to change the thrmostat on the alfa 156 JTS Veloce yadda yadda yadda super duper jobby, because its running at 50C, and the bottom bolt shears off in the cylinder head.
Bollocks.
Its an 8.8 carbon steel bolt too, so its going to be a pig to drill and easy out, and I gont have a MIG welder to weld a nut to whats left (this actually works well since so much heat is rammed into the bolt that it frees itself). And the angle to drill is not perfect, so there is little chance of drilling straight down the thing, even with the battery out, and I dont want to have to take the head off.
So, plan 2, put a couple of holes in either side of the sheared off bolt, drill to 6.8, tap to M8 x 1.25, and stick in some M8 stud. Then make up a little plate with two holes to fit over the studs, and pull the thermostat flange up tight. Should do it. Just need to find some place to get the right drill size...
F***ing cars.....
Still, changed the lamnda sensor, did an oil change, and found the knock, the front right suspension turret was lose.
Tell you what, Italian stuff isnt as good as it was. There is no way they would use a steel bolt in an ally head in the old days, a bit of stud and a nut is far better; the stud corrodes to the ally, and the nut would always undo. Thats how they used to make their engines, what wrong with the twats?
|
|
|
|
|
When they're good they're very good but when they're bad they're bad.
|
|
|
|
|
Reminds me of the old joke:
Q. What do you call 4 tyres sitting in a driveway?
A. An Alfa with the rust removed.
I always wanted an Alfa but never had the time to give to one. One day, should I be stupidly rich and have an actual garage, I'll get me a Alfa Romeo Giulietta SZ.
Does my head in that you can't get an Alfa in North America.
|
|
|
|
|
They dont rust anymore, and the electrics seem to be relatively OK so its a reasonable car to have today. I replaced a BMW 316 coupe with it, a 156 JTS Veloice, and have to say the BMW feels agricultural in comparison, yes, it has very good grip, but almost no feel compared to the Alfa. I have often had this impression with German cars, utterly dead feeling.
Whats the SZ, a 2 liter, 1750? The engine looks exactly the same as tihe one on my GTV
https://www.google.co.uk/search?q=Alfa+Romeo+Giulietta+SZ&source=lnms&tbm=isch&sa=X&ei=uUXKUrTYBenP0AX-7oGIAw&ved=0CAcQ_AUoAQ&biw=1280&bih=678#q=Alfa+Romeo+Giulietta+SZ+engine&tbm=isch[^]
https://www.google.co.uk/search?q=Alfa+Romeo+Giulietta+SZ&source=lnms&tbm=isch&sa=X&ei=uUXKUrTYBenP0AX-7oGIAw&ved=0CAcQ_AUoAQ&biw=1280&bih=678#q=Alfa+Romeo+2.0++GTV+engine&tbm=isch[^]
I used to have one, its a super tough engine, and really well made. For example the exhaust valve stems are hollow wnd half filled with sodium. When the engine gets hot, the sodiujm melts and sloshes back and forward carrying heat away from the valve head. Do you know ANY other car manufacturer that goes to such detail opn their engines? Just nuts, but thats Alfa for you (and Fiat to a large degree).
It will be easy to work on, and fun to maintain,m as well as a joy to take out for a blast when the weathers good. And the thing with alfas/fiats, you can really drive them hard, they love it, and are made for it.
I need to change the cam belt too, probelem is you are supposed to use special tools, not that I ever did on any of the other Fiats I changed belts on before.
|
|
|
|
|
A pit has always been one of my Ultimate Dream Home Must Haves. And a wine cellar in the bedroom hidden by a trap door.
I'll never forget changing a cam chain on a Mazda 1800 and getting it misaligned by one tooth. And dropping the tensioner to the bottom of the sump while doing it. Those were the days...
|
|
|
|
|
No excuses. England were out-bowled, out-batted, out-fielded, out-brained, out-run, out-smarted by the GCO (Genetically Criminalised Ockers) XI. I didn't really expect Engalnd to win The Ashes, but neither did I expect a 5-0, rub your nose in the kangaroo dung massacre it turned out to be.
Well done you thieving buggers Australians. If I could be there now, I'd drink a glass of Boag's or Cooper's with you, not to celebrate or commisurate but to enjoy a nice beer in the sunshine on a hot day which'll make a welcome change to the endless monsoon we've been having here in Blighty.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
|
|
|
|
|
Most unexpected, as a neutral, I expected England to win, maybe 2-1 or 3-1.
Australia didn't strike me as a particular strong unit, getting thrashed in India 4-0 just months before and all that - I guess England were just pathetic
Do you know home teams lost just 2 tests in all of 2013? (Yes, test matches, not series.)
Cheers,
विक्रम
"We have already been through this, I am not going to repeat myself." - fat_boy, in a global warming thread
|
|
|
|
|
Vikram A Punathambekar wrote: just 2 tests in all of 2013
Indeed. It looks like there is this strange phenomenon going around. Last year, I guess things were only slightly better (though I don't have any statistics behind this statement). Away teams don't perform well.
|
|
|
|
|
England imploded.
They look unbeatable a few months ago.
As an example, Matt Prior did tremendously well in June.
In a few months, he had to be dropped!
Haddin did badly in England. Few months later, he was a hero.
|
|
|
|
|
There was me thinking you meant this[^]
|
|
|
|
|
Yep - that's what I first thought of too. The wife is not happy!
However in other news Ha'way the Heed[^]
|
|
|
|
|
Woo hoo!
No doubt a great result and probably Michael Clarke's salvation but it was a particularly boring series. Please don't sent the girl's team next time.
|
|
|
|
|
_Josh_ wrote: Please don't sent the girl's team next time.
To be honest, the girl's XI would have played better than the "girls" that did go.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
|
|
|
|
|
thats unfair they did wonderful, the only problem is that had to keep stopping to play cricket, but that didnt take too long out of thier holiday
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
"Thou, silent form! dost tease us out of thought." [1] [^].
My favorite character in Star Wars is that debonair mound of quivering flesh, Jabba Desilijic Tiure, the Hut, but, of course, a lot of his charm was his tender relationship with his adorable pet sidekick Kowakian monkey-lizard, Salacious B. Crumb [^].
[1] John Keats, "Ode on a Grecian Urn"
“There are obvious things, and there are many obvious things no one tried, because no one needed to try them.” Sergey Alexandrovich Kryukov, January 1, 2014
|
|
|
|
|