- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
That's ... That's beautiful. They should have sent a poet.
Admin
I assume by that you mean:
That's also overloading the cast operator for the getter. It's definitely a possibility. However, you also need to override every OTHER operator= (*=, /=, etc), whereas properties do that automagically. There are other... undesirable consequences, but it is cross compiler.
However, all of this assumes you never use references or pointers to the data.
Admin
Forgive me TDWTF God, for I am about to sin. In mitigation, I'm listening to the Dead at the moment, so my perspective may be skewed. But ...
"Taking advantage of the fact that the BIT data type is not a true Boolean but is in fact the values 1 or 0..."
Um, yes.
Addendum (2009-02-23 16:34): Well, that didn't delete too well, did it?
Admin
Admin
Ah, reminds me of the following ...er, idiom I once saw in Java:
The WTFs here in ascending significance:
Perhaps I should submit that to the side bar some time...
Admin
Forgive me TDWTF God, for I am about to sin. In mitigation, I'm listening to the Dead at the moment, so my perspective may be skewed. But ...
"Taking advantage of the fact that the BIT data type is not a true Boolean but is in fact the values 1 or 0..."
Um, yes. I have splinters from the One True Boolean embedded in my skull. You might have thought that these splinters come from a Wooden Table, but you'd be wrong. They are, in fact, Al-27 and Al-22. Regrettably, Al-22 decays inside 59 milliseconds, and I'm trying to reprogram my brain with Al-28, which has the interesting property that it is stable for longer than the Standard Windows Timeout (ie 2 minutes). I think the tin-foil hat is getting in the way here.
But, getting back to whatever point there is, I see this as a failing to understand what stored procedures are for.
Stored procedures are not for computation. In general, they are not for business logic. (Although they're mighty fine for covering the cases where "business logic" corrupts the database.)
If you need to write code, you write code. If you write code against a data set, then that's fine: write code against a data set. If you need to write code in Java, with its own menagerie of Enterprisey exceptions, then -- that's fine. At least it's only one set of exceptions to deal with. Ditto most other languages at the consuming end of a DB connection.
Do NOT expect magic to emerge from stored procedures. It won't. They're on the other end of a dixie cup 'n' string, and they have not bathed in the Blood of the Lamb.
And what has this got to do with the OP?
Well, nothing, really. I just feel better for letting it all hang out.
On a completely unrelated matter: if your daughter has just died, may I recommend Franz Schmidt's Fourth Symphony? It may strike a chord.
Admin
There are more important things in life, like nibbling witchety grubs. Just sayin'.
Admin
Ok..
"Divide this comment by zero." / 0 = File not found.
Admin
Admin
Admin
Admin
Oh, we are going to seriously discuss my joke? Well, okay. Sorry if I'm about to write a book here.
I didn't say that I am opposed to using getters and setters. Yes, they have the advantage you mention of allowing you to implement side effects. I might also note that they let you handle changes to the data type, like if you start out defining something as an int but later decide it needs to be a float in some cases, you could keep the int setter but have it convert the value to float and then call the float setter. Etc.
My point, though, was that I have heard many people denounce the evils of global data, and then offer as a solution making the data element private and using getters and setters. I reply that this does nothing to solve the original problem.
Suppose I write a function to calculate square roots. I put it in my Math object and call it Math.root.
So now in Object A I write:
And in object B I write:
Cool. Then I decide that in Object A I also need to calculate a cube root. No problem, I say. I'll modify my Math object to include a public variable "power" that controls the behavior of the root() function, and is 2 for square roots, 3 for cube roots, etc. It initially defaults to 2.
So now in A I write:
I carefully test object A, it all works, and I declare victory. Right?
Umm, no. If object B is called after object A, then when B executes, whichPower is still equal to 3, so when it executes "Math.root(64)", the answer is not the expected 8, but only 4. Suddenly there is a very mysterious bug.
The problem, of course, is because creating the global variable was a stupid solution. A much better idea would have been to create a new function that accepts two parameters, the desired power and the starting number. (We might well change the original root(int x) function to now call anyRoot(x, 2). But that fact should be invisible to the caller.)
We all agree on that, right? That's why global data is evil.
So suppose I said, "Oh, you're right, global data is bad. So I'll make power private, and add setPower and getPower functions to update it."
Now object A says:
Did that solve or mitigate the problem in any way? No.
Getters and setters can encapsulate side effects, etc. But they are not a solution to the problem of global data.
Admin
Please don't take this as an opportunity to go into a lengthy dissertation on why your joke about "global data" was perfectly in context with an article about "using errors as flow control". Just let it drop
Admin
I think that you forgot: captcha <followed by utterly retarded comment>
Admin
In C#, you can do...
#if DEBUG //Do debug stuff #else //Do release stuff #endif
But have fun with your Linux
Admin
...and using core dumps to serialize objects.
Admin
You didn't think my joke was funny? Oh no, you have deeply wounded my self-esteem. For of course my whole self-image is dependent on whether someone I've never met and who I only know by a screen name appreciates my humor. This makes me cry inside.
Admin
When exceptions become part of your logic, they're not exceptions anymore, are they?
Admin
To Jay:
... The problem, of course, is because creating the global variable was a stupid solution.
Agreed, yes, in this case.
... A much better idea would have been to create a new function that accepts two parameters, the desired power and the starting number. (We might well change the original root(int x) function to now call anyRoot(x, 2).
Or in say, Delphi:
function SomeRoot(Value: integer; ARoot: integer = 2): integer;
Which necessitates just one param for a square root which is good enough for a general case if you mostly need square roots.
... But that fact should be invisible to the caller. ... We all agree on that, right?
Ok, this is where I fall off. Leave aside that other languages might not have default parameters.
Why should this function be invisible to callers? I mean, it's a math unit, and it's only ever going to be called by another routine in a semi-self deterministic way.
I'm not being antagonistic, I just don't get the invisible bit. Could you help me here?
And, yes, I know zip about C (insert flavour) stuff, but thanks to this site and other sources, I can at least read and figure out what code is doing. Sometimes. Getting better.
Opinion: Using exceptions for general flow control is not good.
Admin
Drat.
That should have been:
function SomeRoot(Value: integer; ARoot: integer = 2): real;
Admin
Considering what happens when an exception hits...
(C#)
Runtime with "q+=i/i" and no checks. 9998 in 00:00:00.0010001
sometimes the time doubles to .002002, that's probably the resolution of the timer.
Runtime with "q+=i/i" and an "if" to prevent divide by zero. 9998 in 00:00:00.0050005
(hardcoded zero gives a compiler error) Runtime with "q+=i/(i-i)" and an "if" to prevent divide by zero. 0 in 00:00:00.0020002
Actually, those vary over many runs between .002 and .008 seconds, thread scheduling, overhead, etc. dominates... but that hardly matters...
Runtime with "q+=i/i" and a try/catch for divide by zero. 9998 in 00:00:00.0150015
This one varied a lot as well, but generally I'd call it 5-10 times slower than using an 'if'
Runtime with "q+=i/(i-i)" and a try/catch for divide by zero. 0 in 00:00:13.3103309
Compared to the variations of the above tests, this one is pretty stable at 13 seconds and change. Only about two thousand times slower than pre-checking the input.
Admin
I've done that, but only in debugging code.
At my previous job, we joked about writing a function for this called Punt(). Punt would declare a pointer to a double, set the pointer to NULL, set the memory at that location (null) to PI, then cast the pointer to a pointer to a function and call it. Guaranteed to cause an exception! We never actually wrote this (that I know of).
Admin
Admin
Admin
Admin
Depends on how the code was copied. If it was originally scripted so that their tool used sp_executesql then the proc would've been embedded in a string and need the ' escaped regardless of where they were.
Admin
Oh no, you can't use a return statement in the middle of your method because it violates the principal of having only one exit point.
Admin
Was this an SQL server SP?
Was is SQL server 2000?
You'd be doing well to use RAISERROR in SQL server 2000 ;-)
Admin
In Australia, WAGDAG is funnier than WAGDOG.
Admin
FTW!
Admin
You forgot the classic: In Soviet Russia, zero divides by YOU!
Admin
In the days of Windows 3.x and OS/2 1.x (running on the 80286), programs had to switch between "real mode" and "protected mode" every so often. Though the 80286 could switch from real mode to protected mode in a well documented way, it lacked an instruction/method to do the reverse. The solution: force a processor exception, and have the exception handled by code that causes another exception, eventually "triple faulting" the processor and making it do a full reset. Special code in ROM and a signature in a reserved spot in RAM made the processor restart at the position where it left off.
If memory serves, this was even patented (do people inventing such kludges have no shame?), but I cannot find the patent right now.
Admin
"?etw".reverse.next.upcase
inhibeo: wizard incantation used to freeze stupidity in it's tracks.
Admin
Admin
This would not work for Chuck Norris. He can divide by zero.
Admin
Says who? ;o)
I was always feeling that under certain circumstances the code is clearer if one uses multiple exit points.
The code above is a prime and pathological example for that - even if there were many exit points, using "return" instead of all of the misused stuff above would've been preferable by far.
Of course not making the mistake of "hundreds of LOC in one method" in the first place would most probably cater to this problem, leaving only a handful of exit points (or even just one) for most of the methods this behemoth must be broken down into. And only then we could additionally talk about merging these handful of exit points into one.
Admin
You can try reading the comment again, on the understanding that it reflects my understanding of what stored procedures are for.
Alternatively, you may consider:
(a) only reading comments of less than, say, a coupla hunnert words or (b) a humorous, or bigoted, or possibly even informative, riposte. Only a coupla hunnert words, please. You have a duty to your subjects, damn it.
Admin
And, of course, after the first maintenance round #define TWO_POINT_NINE_FOUR_TWO 1.772
Admin
Chuck Norris can divide by zero.
Admin
Admin
[image]
Admin
Of course, single-entry-single-exit does not work in any language with exception support anyway (because exceptions create implicit exit points). Unless programs in said language are written in such a way as to nullify any exceptions, as demonstrated above.
You can program against the language. After all it is your users, not you, who will feel the pain.
Admin
Damn, now I need to unregister so I can always post my CAPTCHA. The memes, think of the memes I can have some omniscient, blameless being kill for me! It's like laundering money, except with murder instead.
Or Mimes. Either way works. I prefer the former, though.Admin
The docs state that API was available in Win2K or later. I remember looking around for a "proper" way at the time, so it either didn't exist or I found it and eliminated it as some of our clients were still on Windows 98. I honestly can't remember which was the case now.
As far as why I moved to Linux: Freedom. I control what my computer does - Microsoft doesn't.