|
A completely stupid idea. It adds a thrown exception that functions solely as a goto .
Software Zen: delete this;
|
|
|
|
|
At least with a GOTO you can get back to where you were - much more difficult with exceptions.
TTFN - Kent
|
|
|
|
|
True, but then I'm a purist. I haven't used a goto statement in over 20 years. I will admit I use break and continue , but they are 'structured' to my way of thinking.
Software Zen: delete this;
|
|
|
|
|
Did I miss something?
An exception is more than a goto , because it can jump outside of the current scope. This is very useful for aborting work that has run into a serious error, when it is appropriate to exit a chain of function calls and recover from a known point well down the stack. That's actually the only thing I use exceptions for. In most cases, such as a bad argument, the function should simply return a failure result instead.
EDIT: It looks like the code could well be overusing exceptions when returning a failure result would be more appropriate, so that's probably what I missed.
|
|
|
|
|
The 'guard' code from the article was this:
fun guard() {
if (!condition1) {
throw Exception1()
}
doThings1()
if (!condition2) {
throw Exception2()
}
doThings2()
if (!condition3) {
throw Exception3()
}
doThings3()
} This call needs to be surrounded by a try...catch in order to exactly reproduce the functionality of the original. I'm not sure which language is used for the original code; I think it may be Javascript, but the fun keyword is odd.
In any case, throwing an exception in lieu of nested conditionals or a goto is overly complicated and error-inducing. Imagine debugging this sort of nonsense when the catch misses one of the exceptions thrown.
Software Zen: delete this;
|
|
|
|
|
It's so sad that other programmers that I may end up working with at some point read that drivel and adopt it.
|
|
|
|
|
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Hi Marc, Perhaps my memory is flawed, but, I seem to recall eyeballing code of yours that used preventive filters in this way.
I'd appreciate your comments on my post below !
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 30-Nov-21 0:13am.
|
|
|
|
|
I believe in anticipating/handling errors in parameter data before you get to the juicy parts, and I think guard clauses are a good example of a strategy for that. I also think liberal use of Try/Catch for things like file-ops is a good thing.
Guard clauses' "virtual isolation" at the start of a method is, imho, "separation of concerns." You can easily comment them out, remove them, as conditions/state management require.
However, there are other strategies.
What I'd like to see is a radical extension of Attributes in C# that do AOP-like transformations, and, internally generate the equivalent of guard clauses: there's already an example of that in the semantics of the Nullable attributes: [^].
A "wedding" of unit-tests and attributes
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
BillWoodruff wrote: What I'd like to see is a radical extension of Attributes in C# You always did strike me as a radical!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The breakthrough compresses light into a nano-scale spot. "Mama's got a squeeze box, Daddy never sleeps at night"
|
|
|
|
|
The Joy of Cryptography is a free undergraduate textbook that introduces students to the fundamentals of provable security. One of these things is not like the other
|
|
|
|
|
"Joy" and "Cryptography" in the same sentence?
|
|
|
|
|
Australia will introduce legislation to make social media giants provide details of users who post defamatory comments, Prime Minister Scott Morrison said on Sunday. This legislation was proposed by three billy goats gruff
|
|
|
|
|
Banning weapons;
Using overwhelming force against unarmed people to enforce government policy;
Checking all communications for unapproved opinions.
Alas, the Soapbox is no more.
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
|
|
|
|
|
Better get all your insults of Kent in now.
|
|
|
|
|
Imagine being able to disconnect or redirect Internet traffic destined for some of the world’s biggest companies — just by spoofing an email. And we're almost out of spit
|
|
|
|
|
And this is new how? Every system is held together by bubble gum and duct tape, and we are all out of bubble gum.
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
|
|
|
|
|
In the 1970s my dad's Volkswagen was held together by rust.
|
|
|
|
|
But those cars were built better, they would just Go.
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
|
|
|
|
|
According to Daniel, while the practice of software development has changed in the past 20 years, SOLID principles are still the basis of good design. A lot of software architecture makes me want to hit the liquids
I think the title has a premise I'm not convinced is actually true.
|
|
|
|
|
Has it ever been? 99% of the software I see is less architecture and more spontanoeus growth, like a shrubbery.
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
|
|
|
|
|
Large systems grow out of small ones, so the shrubbery aspect is almost a given. Trying to build a large system from scratch virtually guarantees failure, and a system that isn't growing usually doesn't have long to live. The problem is that a system's architecture often doesn't evolve with it, assuming that it had one in the first place.
|
|
|
|
|
Yep but it has to be a planned and structured growth, not cancer-like.
Ah yes, that escrescence there was made to support vendor XYZ, it's no longer necessary but it has been used as a base for that other escrescence for when we experimented with rubbing methylene on the code, now if we remove it it stops working.
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
|
|
|
|
|
Google said 86% of 50 recently compromised Google Cloud accounts were used to perform cryptocurrency mining. People actually use the Google Cloud?
|
|
|
|