- 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
Okay, he actually removed the sentence : "your company name here".
Wow!
Admin
Premature optimization for teh fail!
Admin
This reminds me of back in college when someone was trying to understand the concept behind private/protected functions. After a series of explanations about protecting your information so others couldn't see it the student thought for a second and asked, "What if they go in and change your code?".
The teacher didn't really know how to respond to such a stupid question.
Admin
private and protected have NOTHING to do with "protecting your information so that others can't see it". It's NOT a security feature. It's a design feature. The point is to declare which parts of a class are implementation details that can change at any time and which clients of the class should therefore not rely on.
Admin
That's why we used to have this beauty in our code:
Admin
This question is not stupid - explaining "private/protected functions" with "information security" modell is stupid. It produces wtf-programmers that think "if i declare variable as private then data will be secure from crackers". "public interface, private guts" modell ist better
Admin
Hmmm someone use a replace all "x"-es into "-"s. Is that the WTF?
Admin
The "inde-es" part is funny.
I wonder if it was done by Alex, Vlad or Vlad's predecessor.
Note from Alex: FWIW, only changes I made to the submission was formatting (removing a linebreak here and there, etc) and adding the "----" ...
Admin
I like how all the items in the comment are numbered -- 1.0, 2.0, and so on. It's like a whole Word document inside a comment block.
And what are inde-es?
Admin
Why bother with private methods when you can hide all your information by changing it to hyphens?
Admin
AOL. And it should be a good time to explain something about /social contract/ between developers (and between yourself and the instance of yourself a few weeks ago).
By the way, modern frameworks like Spring destroy all this public/protected information hiding anyway.
Admin
Besides allowing for changes to the way data is handled internally by the class, it also helps to ensure that other programmers using the class use it correctly, by letting you control how changes are made to internal variables, and how these variables are represented to other parts of the program, which in turn makes the class easier to use and reduces the need for documentation.
It also makes for more robust classes. For instance, you might decide that the "dimensions" property of a bitmap object is undefined if the bitmap doesn't (yet) contain data that has width and height, and then, rather than returning meaningless data to the caller, you might want to generate an exception.
In OOP public variables are just generally a bad idea. And with an optimizing compiler you most likely wouldn't gain any speed from using them anyway.
Admin
Hi, I don't know Spring, but I see a lot of fuss about it. Your comment intrigued me. What do you mean when you say that Spring destroys information hiding? Would you please care to elaborate? Thanks!
Captcha: bathe - not saturday yet though
Admin
X-lib had the exact-same-comment in all of its ("C") data structures: this field is private, so you should not change it - and people didn't, because if they did, X became unstable and inevitably crashed.
I find it interesting that the more you attempt to hide something, the more people seek it out and try to access it just to see what happens.
Admin
The real WTF is that the hyphens under 1.0 Identification are six, but the hyphens under 3.0 Description are only four.
Admin
Admin
I've seen that before:
Scary stuff..
Admin
It's people like you who perpetuate bad coding practices by writing things like this.
Encapsulation has been proven to be a useful feature, especially in complex programs, or in teams consisting of several members working on individual modules.
Shame on you for stating that it causes overhead and is a waste!
Admin
So scary
captcha: craaazy
Admin
Did nobody else notice the "Unclassified" in the header block? This gem appears to have been done on US Government money (probably by a contractor). That is awesome.
Admin
Damn! Nice troll! 5/5!
Admin
It's called satire.
captcha: pirates - Can't argue with that!
Admin
Let's assume for a second that this is C++ and this class defines absolutely no inline functions at all. Then a function like this:
actually ends up being a push on the stack, which can add up to lots of overhead just accessing a single integer. In Java or C# the runtime usually sees those trivial calls and inlines them, but when that code is separated into a .cpp file it's compiled and executed as a normal function, thus leading to lots of indirection. I worked at a place once which strictly forbade using inline functions (those functions defined in the header) and the performance noticeably suffered because of it. The real WTF was why the management, who understood nothing about programming, forced this upon us. They claimed that it safely hid the implementation details. They had no idea that the .h files weren't shipped with the final build of the software.
Admin
Once again, the writer of WTF is wrong. There's nothing slow about properties (well in .NET anyways). Perhaps s/he should think before s/he speaks and realize that slow is a meaningless term unless it's a comparative. Even then, we need benchmarks and statistics. In .NET, you won't find almost any difference... they are both insanely fast racing C++ fields (oh yes... .NET is no RAD system; it rivals C++, not Java).
Admin
Admin
Admin
I've always thought that private/protected/public thing was less than useful. If you have a class that is useful and well-written, chances are its implementation never changes. and any change to the class usually involves a re-write to the entire structure anyway, because seldom is the implemenation/interface as clear-cut as everyone wishes.
Has anyone EVER actually changed the private implementation of a class, and not have to re-work all the stuff dependent on it? Or are my suspicions correct and this is something that lots of thought goes into for little-to-no long-term benefit?
Admin
Holy hell. I haven't used C/C++ in years and years, but please tell me that isn't legal!
Admin
Seems reasonable...
Admin
So hey, on the internet, there's this thing called satire. But please, tell me more about your deep knowledge of C++/.NET/Java benchmarking, I do enjoy some good e-dick waving.
Admin
That's entirely legal because the language parser knows nothing about it, seeing as it's done entirely via preprocessor macros.
Admin
If you actually provide a good interface and clearly defined purpose for your classes, then it's pretty common to change the implementation without touching the public interface.
If you just write random methods as you need them and label them public or private, not so much.
Admin
Admin
Now this makes me understand why some people suggest putting private stuff first (without the private keyword). So only private things are well protected.
Though it seems to me that you can also access private members and methods through pointers. All you need to know is the type and the name.
Admin
When he said "Fast Performance" he was referring to time to write the code and not time for the code to execute.
Admin
Admin
Java has no problems with aggressive inlining, even if the code is inside another JAR. It has to do with JIT compiling, and runtime optimization (in this case runtime inlining). I'm no expert on compilers, but I think I know that much.
The same could be done for .NET, but I don't know about .NET runtime optimization in the current .NET runtime environment.
C++ is another beast. I'd guess it's not really possible in raw C++, unless you start using template libraries which allows aggressive optimization (inlining, processor spanning,...) but only at compile time.
CAPTCHA: stinky, that was a funny one :)
Admin
Note that some C++ compilers translate to C before compiling (Comeau C++ does that IIRC).
CAPTCH: Seems like captcha's are a fixed set...hmmm
Admin
He certainly was not referring to the time taken from other programmers to write code using his class.
It's always faster to understand a class that has all its unneeded methods and fields set private.
Admin
So, um. I don't get what's so bad about this.
Sometimes accessor functions really are too slow. In that case making the fields public and asking the callers not to modify them seems completely reasonable to me.
Admin
Yes. That's the whole point of public interface vs private implementation. The use of an object remains the same (ie interface doesn't change) but its inner implementation does (ie new data access layer). Only when the way you handle your object changes, does your interface change and as such the code where you manipulate these objects.
And,
Your suspicions are incorrect.
CAPTCHA: By all means...
Admin
You bet it is legal :). Can't say it's a good practice though ;-)
Admin
There is a C++ idiom that counters these bad practices, pimpl!
CAPTCHA: how's my e-dick ;-)
Admin
Perhaps it is legal, but a much more clean code would be achieved with:
And it will always work, since protected is never the default.
On the second thought, you can easily defend against the evil haxx0rs, by putting #undef protected (and probably #undef private) in all your headers.
If there was a CAPTCHA, it would be: craazy (or maybe scaary).
Admin
Shame on you for walking around with a broken irony detector.
Except it's not. 17.4.3.1.1/2 of the C++ standard WD reads:
"A translation unit that includes a header shall not contain any macros that define names declared or defined in that header. Nor shall such a translation unit define macros for names lexically identical to keywords."
Admin
Admin
ObThisIsNotAlwaysAWTF.
Suppose I've got a language that doesn't support friend syntax.
Suppose I have a getter that acutally does something more interesting than return the variable (think, oh say lazy loaded resources).
So (pseudo-code)
private Butt butt;
public Butt getButt() { if (butt == null) { butt = new Butt(shit); } return butt; }
and because it's a multithreaded app I need to wrap that getButt in a mutex.
Now if I'm in a tight loop that has to call getButt on a lot of classes, that could be expensive. If I know damn well all those butts are all nice and shitty to begin with, I can use the private butt variable safely, so I make butt public, but a comment in the code that says "don't even think of using this if you don't know what you are doing" and hope noone actually does. (I might make a public inlined function called getButtIfYouReallyKnowItIsSafe() or something silly, but that's still a public function that really shouldn't be being called.)
This kind of stuff happens when you need to optimize the hell out of a very small loop. Not all public functions are trivial getters and setters of private data variables.
Admin
It's not legal because the C++ Standard says that you can't #define a keyword to be something else. It will work on most compilers though.
http://www.gotw.ca/gotw/076.htm
Admin
Well, since it's in the standard library chapter, it looks like it only applies to standard headers. That way, if your file does not include any standard headers, you can redefine protected, no? (Evil, evil, new realms of evil... ;-))
Admin
Encapsulation is just convention. Some perfectly OO languages don't enforce it at all. Having used one for ten years, making the compiler act as a half-assed encapsulation police officer seems silly to me now. The programmer provided a perfectly good convention in place of the enforced convention provided by C++. Is anyone here really going to take the position that C++ is the one true way, and anything else is dumb? This ain't 1990...