|
Thank you for the explanation.
|
|
|
|
|
Just let it go
|
|
|
|
|
Sander Rossel wrote: Just let it go
Yeah, it is the best way. Acceptance.
But, it's a lot more fun to gripe about it.
|
|
|
|
|
Remember the old times of Basic and VisualBasic, where Let assigned the result of an arithmetical expression (luckily became optional) but if you needed to set a reference in VB you'd better remember it wanted the Set...To keyword or it would crash at the first execution.
GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
VB6 and earlier needed Set and Let because of non-indexed default properties, which thankfully went away when .NET was first released.
For example:
Dim rst As ADODB.Recordset
Set rst = ...
Dim foo As Variant
foo = rst["Bar"]
- The
Recordset class doesn't have an indexer, but it has a default property called Fields which does. - The indexer returns an
ADODB.Field object, with a non-indexed default property called Value . - At this point, the compiler wouldn't know whether you want the variable to contain the field object or the field's value.
- Therefore you have to use
Set if you want the field object, and Let (or nothing) if you want the value.
Fun times!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It was also needed with custom VB classes and objects with no default property. A "nice" syntactic requirements in a langauge that did not have references or pointers (but then the hidden VarPtr, StrPtr and another function whose name I forgot came to help).
GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
den2k88 wrote: Let assigned the result of an arithmetical expression
Yeah, that's a good one. I first saw let coming back with JavaScript and thought it was a weird throwback. Then Swift brought it back too. Let is taking over again.
|
|
|
|
|
Which is why using C# for native iOS and Android apps, as well as MacOS, tvOS, Linux, and web apps (with webassembly) makes so much sense. No Java, no Kotlin, no Swift, no JavaScript (or the myriad of JS libraries). Just C# for them all.
|
|
|
|
|
|
That really is the best explanation of the proliferation of programming languages.
|
|
|
|
|
The first result returned by a search for my WizardWrx.Core NuGet package was https://nugetmusthaves.com/Tag/Constants, which listed the library in question, along with another that contains even more constants, as "must-have" packages. Since I did nothing to seek out this attention, it was a very pleasant surprise.
The surprise here is that they ranked the WizardWrx.Core package ahead of WizardWrx.Constants , which defines far more constants. Perhaps that is because there is so much general purpose code in the former, in addition to the constants. Regardless, it was an unexpected discovery that they were ranked 1 and 2.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
Pretty little piece of code I inherited. I deleted code out of the try, the real point was the catch... that code is verbatim.
// create vector of file types so we can reorder the list from newest to oldest
try
{
}
catch(...)
{
}
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Still better than
int main() {
begin:
try {
}
catch(...) {
goto begin;
}
return 0;
}
PS - Enjoy the cleanup on aisle one, two, three, four...!
|
|
|
|
|
David O'Neil wrote: goto Blech. I'm sure someone will douse me with an accelerant and light me up for this, but the only time I've felt justified in using goto over the last umpteen years of my career has been in embedded assembly language code via jmp instructions of one flavor or another.
If you're using any kind of higher-level language that supports structured programming, the ease of misusing goto far outweighs it's utility. After writing millions of lines of FORTRAN, Ada, Pascal, LISP, PL/I, C, C++, and C# I've never written code using a goto that wasn't simpler, more robust, and easier to follow when written structured.
Software Zen: delete this;
|
|
|
|
|
To me, this is cleaner than the alternative. I'm certain many will disagree, but this matches my thought process, and eliminating the goto s requires more indentation levels (which I despise) and thinking time. And if it doesn't require more indentation levels, it still requires more time! I agree with not using goto s often.
void Repeater::createRepeatedObjs() {
if (!createdObjsC.empty()) throw dwl::Exception(_T("Delete created objs prior to "
"creation"));
app::ObjMap & holder = appC.objMap();
holder.setPtrPos(s_cast<OBJECT_TIME>(0));
object::BaseObj * obj;
object::BaseObj * objToCopy;
while ((obj = holder.objAtPtr()) && obj != nullptr && obj->time() < endTimeC) {
if (obj->time() < timeC) goto breakout;
for (size_t i=1, count=numRepeatsC; i<=count; ++i) {
object::BaseObj::Type type = obj->type();
if (type == object::BaseObj::Type::TypeOne) {
object::TypeOne * typeOne = s_cast<object::TypeOne *>(obj);
object::ObjParent * parent = s_cast<object::ObjParent*>(typeOne->parent());
if (parent) objToCopy = parent;
else objToCopy = typeOne;
}
else if (type == object::BaseObj::Type::TypeTwo) goto breakout;
else if (type == object::BaseObj::Type::TypeThree) goto breakout;
else objToCopy = obj;
if (objToCopy->copyOf()) goto breakout;
std::unique_ptr<object::BaseObj> newObj = objToCopy->copyToTick(objToCopy->time() +
durationC * i);
if (newObj->type() == object::BaseObj::Type::ObjParent) {
s_cast<object::ObjParent*>(newObj.get())->typeOne().copyOf((object::BaseObj*)1);
s_cast<object::ObjParent*>(newObj.get())->noteOff().copyOf((object::BaseObj*)1);
}
createdObjsC.push_back(newObj.get());
newObj.release();
}
breakout:
holder.incObjPtr();
}
}
Forcing it into your way, I believe it becomes:
void Repeater::createRepeatedObjs() {
if (!createdObjsC.empty()) throw dwl::Exception(_T("Delete created objs prior to "
"creation"));
app::ObjMap & holder = appC.objMap();
holder.setPtrPos(s_cast<OBJECT_TIME>(0));
object::BaseObj * obj;
object::BaseObj * objToCopy;
while ((obj = holder.objAtPtr()) && obj != nullptr && obj->time() < endTimeC) {
if (obj->time() < timeC) goto breakout;
for (size_t i=1, count=numRepeatsC; i<=count; ++i) {
object::BaseObj::Type type = obj->type();
if (!(type == object::BaseObj::Type::TypeTwo ||
type == object::BaseObj::Type::TypeThree)) {
if (type == object::BaseObj::Type::TypeOne) {
object::TypeOne * typeOne = s_cast<object::TypeOne *>(obj);
object::ObjParent * parent = s_cast<object::ObjParent*>(typeOne->parent());
if (parent) objToCopy = parent;
else objToCopy = typeOne;
}
else objToCopy = obj;
}
if (!(objToCopy->copyOf())) {
std::unique_ptr<object::BaseObj> newObj = objToCopy->copyToTick(objToCopy->time() +
durationC * i);
if (newObj->type() == object::BaseObj::Type::ObjParent) {
s_cast<object::ObjParent*>(newObj.get())->typeOne().copyOf((object::BaseObj*)1);
s_cast<object::ObjParent*>(newObj.get())->noteOff().copyOf((object::BaseObj*)1);
}
createdObjsC.push_back(newObj.get());
newObj.release();
}
}
holder.incObjPtr();
}
} That is much uglier to me, especially with the ! .
modified 31-May-19 23:50pm.
|
|
|
|
|
not that I'm really arguing, but it looks like your code base between example 1 and 2 have the same level of complexity. And why use a goto to leave the loop when a break would work just fine? Maybe it's just the example.
My point in the original is that I have try/catch pairs all through the code, and nothing is done in the catch. No logging, no recovery, no ASSERTS, I mean nothing. If you're not going to handle the exception, just remove the try and let it crater
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
The goto s don't break out of the loop, so a break won't keep the same flow. I should have named breakout something like skipProcessingTo , but the breakout nomenclature comes to my mind naturally.
I believe they are equivalent, except for the extra indentation level which I don't like, and the
if (!(type == object::BaseObj::Type::TypeTwo ||
type == object::BaseObj::Type::TypeThree)) {
which I despise. The ! / || construct flips my brain upside down, vs the other way which is clear.
I did not notice the 'verbatim' part. At least they gave you a template to fill in!
Their comment indicates they possibly once meant to do something. Copy/paste at its finest! Have fun making it better!
|
|
|
|
|
Ha! I missed that last bracket. My bad.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
David O'Neil wrote: The ! / || construct flips my brain upside down, vs the other way which is clear. I'm not familiar with C(++), but can't your if be rewritten as:
if (type != TypeTwo && type != TypeThree)
And do you even need it at all?
Simply checking for TypeOne should suffice as you do absolutely nothing in case of TypeTwo or TypeThree...
if (type == TypeOne) {
}
holder.incObjPtr(); Or maybe I'm wrong, but your example is mostly hard to read because indentation is way off
|
|
|
|
|
Sander Rossel wrote: ...can't your if be rewritten as: Possibly. It works, though, so I will leave it for now!
|
|
|
|
|
Sander Rossel wrote: I'm not familiar with C(++), but can't your if be rewritten as:
if (type != TypeTwo && type != TypeThree) Yes, that is part of De Morgan's laws.
"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?"
|
|
|
|
|
Somewhat recently I have found one genuine use for goto (in C# at least).
switch(someEnum)
{
case SomeEnum.FirstCase:
break;
case SomeEnum.SecondCase:
break;
default: goto case SomeEnum.FirstCase;
}
|
|
|
|
|
Really? Why not:
switch (someEnum)
{
case SomeEnum.SecondCase:
break;
default:
break;
} Exactly the same behaviour, with no need to use goto in your code.
(Of course, the generated IL will probably still use the equivalent of goto behind the scenes.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Wow, I haven't seen a goto since the last time I opened up some very, very, very old FORTRAN code.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|