|
I agree it can be easily abused. It is especially true if you are maintaining someone else's code. Yes, it's great for templated iterators and such, but it can also throw more work onto someone else down the road, which I consider rude or lazy.
Say I need to add some functionality. I see
auto foo = SomeFunctionReturningObjOrRef(bar);
foo.SomeMethod(blah);
Great. That's really easy for the original dev, and really easy for the compiler. Wonderful. Now I need to add some code. What the heck is a "foo"? What members does it have? What methods are available? Is it a base class, or a derived class that has the functions I need? The dev who wrote the code knew, but didn't bother to declare it. The compiler knows, and I suppose I can just try
foo.SomeMethodIHopeTheObjectHas();
And see if I get a compilation error. And hope that it really is the right type and not a base class or derived class of the one I expect...
But practically speaking I have to do the work the original dev didn't do and look up
SomeFunctionReturningObjOrRef() and see what it does, and what it returns so I can be sure I'm getting the right type or that it supports the methods I need, and I don't actually want to be using "bar" or something else or upcast or downcast etc.
|
|
|
|
|
I usually do "all that work" by hovering the mouse over the function call and seeing what the IDE shows as the prototype of the function. There is no guesswork involved.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Really the above isn't the issue. The issue is this:
auto whatever = GetSomething()
while (somecondition)
whatever++;
In a large code base, there are probably a hundred or more things that would be syntactically compatible with that, so that accidentally changing GetSomething(), either manually or via search and replace, such that it returned one of those types, would create a completely silent error.
Is it going to happen every day? No, obviously not. But that's not the point. The point is that, this:
FailureCounter& failCnt = GetFailCounter();
while (somecondition)
failCnt++;
is just far less likely to be subject to such a silent error because you have to make two parallel errors for that to happen. You are expressing your intent to the compiler by using an explicit type, which is the only way the compiler can know if your intent is not being followed.
And how much extra work did that take to get the extra safety? Almost nothing.
Explorans limites defectum
|
|
|
|
|
I always use the highest warning level available and set warnings to be failures and I have done this for many years. Since the auto keyboard has been available I have never seen a compiler allow anything through that could cause a failure.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
There's nothing to warn about in the scenario I indicated. It's a completely valid program, just the wrong one.
Explorans limites defectum
|
|
|
|
|
So are you saying that you don't want a self-driving auto?
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
How many calories does Herself burn by jumping to conclusions?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
About as many as you do by straining at gnats.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Dunno but I would not try to represent the answer in an unsigned int.
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
|
... dunno, but hubby better pack in some large extra servings for what comes next.
Message Signature
(Click to edit ->)
|
|
|
|
|
Since the number of conclusion can vary I would suggest using a List<caloryconclusioncounter>() object and run an asynchrounous count to stay tuned.
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
I was weighting for that kind of post. I hop you can scale the answer to something KSS.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I suggest a pre-emptive apology, accompanied by flowers (no candy, given the calorie reference).
Software Zen: delete this;
|
|
|
|
|
Aggressive little dog a cousin broke (10)
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
pugnacious
pug = little dog
nacious = anagram of "a cousin" ("broke" = anag. identifier)
|
|
|
|
|
Yay! You are up tomorrow!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Well done.
I got the pug and was trying to shoehorn pugilistic in there.
|
|
|
|
|
Thanks. I didn't actually get the "pug" part straight away... I was trying to work with "pup" for a while first.
|
|
|
|
|
97. To be ergonomic requires drink (4)
|
|
|
|
|
Beer
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
Well, that was quick *burp*
|
|
|
|
|
Yea back to work today so up early
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
Togonomic (adj): An alcohol-free state.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Ok - I get the joke smiley - but stop messing with my head!
Where did you get that anyway
|
|
|
|