-
Content Count
3670 -
Joined
-
Last visited
-
Days Won
181
Everything posted by David Heffernan
-
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
I don't really see the value of this, if the input is contracted to be assigned. That makes it a programming error, your tests will AV and you will fix it. No need to clutter the code with if not Assigned tests. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
The whole point of exceptions is that in a huge number of cases it is impossible to "deal with it" at the point where the error is raised. The code has been called by another function that excepts it to succeed. If it can fail, but return normally without an exception bubbling up, then you need to return information to the caller that the function has failed. And the caller may in turn be have its own caller that needs to know this. And we are right back to exception free code where errors are indicated by boolean or integer error code return values. Exceptions that bubble up the stack are only difficult to manage if you don't write your exception raising and handling code properly. For sure it is perfectly possible to write crappy exception code. But you are pointing the finger in the wrong place. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
You described the correct construction pattern as a "problem" which is what confused me. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
Don't you know that exceptions bubble up the call stack? If you try to handle them immediately then you've just got crappy error code type code. The entire point of exceptions is that you don't need to deal with them at the point where the error occurs. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
No. The try finally here protects the lifetime management of the instantiated object, after the constructor has completed. An exception in the constructor will bubble up from here and never enter the try. This is a very very common misunderstanding. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
No. Its pointless trying to handle exceptions in destructors. If that happens the process should terminate. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
Again, can somebody explain what problem is caused by raising in a constructor. We all seem fine with TFileStream doing this, so all I can see is dogma. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
I don't see the point of trying not to raise in a constructor as a design goal. Raise the exception at the point where you know it needs to be raised. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
What do you think about TFileStream.Create raising an exception if the file can be opened in the requested mode for whatever reason? I cannot see the problem with this, or indeed any constructor raising. If you are going to admit exceptions in your program at all, you must be resilient to them. Why is it any different to get the exception raised in a constructor than anywhere else. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
The advantage of moving that teardown call to the subject's destructor is that you don't need to test Assigned. If it raises an exception then you are still hosed. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
In a destructor you do need to test Assigned on members if you call any method other than Free. That said, destructor must not raise exceptions. And its generally better to move the call to those teardown methods into the destructor of the class. -
BestPractices: To raise, or not to raise ... an Exception in a class constructor
David Heffernan replied to Rollo62's topic in Algorithms, Data Structures and Class Design
This is pertinent to some of the discussion here: https://stackoverflow.com/a/8550628/505088 -
Smart characters editing in strings in Delphi
David Heffernan replied to Bob Baudewyns's topic in Algorithms, Data Structures and Class Design
I mean if you have a bunch of files that need to transformed once, then writing delphi code isn't the most efficient. You'd just use a scripting language to make the change and throw the code away. But if you have a Delphi product that needs to repeatedly perform this transformation then that's not going to be useful. -
Smart characters editing in strings in Delphi
David Heffernan replied to Bob Baudewyns's topic in Algorithms, Data Structures and Class Design
If this is a one time transformation then it's easier with a scripting language -
'Floating point division by zero' when running script
David Heffernan replied to a topic in Python4Delphi
This is just going to be the age old issue that most Windows code expects floating point exceptions to be masked, and Delphi's RTL unmasks them. So, mask floating point exceptions when you call into Python, and unmask them when the Python call returns. Or just mask them always if you don't care about floating point exceptions. Of course, the floating point support for changing floating point control state is not thread safe in the Delphi RTL as I have been saying for more than a decade now. -
It still doesn't make any sense to me why you wouldn't just use TStopwatch.
-
No idea why you wouldn't use TStopwatch
-
stringreplace character in all string
David Heffernan replied to William23668's topic in RTL and Delphi Object Pascal
I'm sure your function would give the same result. Did you read the earlier posts? They explain what is going on. -
stringreplace character in all string
David Heffernan replied to William23668's topic in RTL and Delphi Object Pascal
Why is that better than StringReplace? How does it relate to the problem in this thread? -
Move a Function or Procedure to a Unit??
David Heffernan replied to Ian Branch's topic in General Help
Get Martin Fowler's book on refactoring. -
Fair enough. Let's just switch to PHP then and be done with it. Bruh.
-
Nothing there is useful. Hard to get past the basic sin of treating a string as if it were a byte array.
-
It doesn't much matter what the thing is that you encrypt. What matters is who encrypts it, and who has knowledge of the key or keys used to encrypt and decrypt. That's what I mean by usage. As for how you do it, convert the text to binary using a well defined encoding, e.g. UTF8, and encrypt that. Encryption algorithms work with binary data not text.
-
It depends on what your usage is
-
Your Delphi verion does not support COMMAND
David Heffernan replied to TimCruise's topic in Python4Delphi
Pro has command line compiler