- 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
fist
Admin
Um, "get" returns the return-code of the "SAVE-to-database" action?
Um, "set" returns the return-code of "LOAD-from-???" action?
Aside from the non-trivial processing wtf, wouldn't those make more sense if they were reversed (eg: "set" stores the value in the DB, and "get" retrieves it)?
Admin
frist
Admin
I would agree.
Admin
First
Admin
I seriously wonder what the hell the author of this was thinking....
Also, how long until we get the auto-ip-ban script when someone posts 'first' or some various misspelling?
Admin
So, accessing the address fields does not save to the db, while accessing the rest does? I don't get it.
Admin
This must be such a WTF that I'm not even really following it. The point of the class is to just wrap the setting and getting of the non-object variables? Seems the author doesn't understand object property manipulation insomuch as objects in general...
Admin
Actually, properties are usually wrapped around private variables. The "setter" refers to the routine that takes a value and "sets" that private variable to that value. The "getter" refers to the routine that returns the value of the private variable.
The property pattern is actually pretty useful, and is definitely not the wtf here. Often, when working in ASP.NET, I have the setter set not only the variable but also update the ViewState. The problem here is that the property has a major side effect. Code calling these properties would look like Contact.contact = theContact, which looks completely innocent.
Admin
Russ should be thanking his sweet job that the getter function didn't say "DeleteDatabase()".
Admin
I see your problem: you don't get it because you are thinking coherently! Bang your head with a hammer a few times and look at it again, it'll start to make sense [8o|]
Admin
I have to know... is this an obfuscation error, or were the methods truly implemented in this way?
This is horrible on so many levels.
P.S. Fourteenth!!
Admin
There's really no sense in using functions when you can just use an accessor is there? Doing it this way eliminates the need for all those annoying parenthesis throughout your code. The real WTF is........okay so it is the code after all
Admin
Judging by the comments after some of the lines in the first snippet this code was truly implemented that way. Yikes!
Admin
This is nonsensical. The accessor methods appear to do exactly the opposite of the usual meaning. I'm guessing this is somewhere on a government website. And hey, come to think of it, it's pretty enterprise too. You can define the accessor methods to do whatever the hell you want them to do, good programming practices be damned!
Admin
So, for example, one could write (not sure if this is the right way to format stuff for the forum s/w):
<pre>public Contact contact {
// Misuse get using WPP (worst-programming-practices)
get { return True || Boolean.FALSE.toString().equals("TrUe") && FileNotFound; }
// Misuse set with implied side effect
set { wtf(); }
}</pre>
Admin
Damn, it was the wrong way to format it. Can anyone provide a link to something that describes the proper way to format a post?
Thanks in advance!
Admin
I like that the comment on the accessor claims that this hasnt been saved to the database. Which it does. Everytime we access the object.
Admin
No it does make sence in an extreamly disturbing way, note that the code came from the Contact class. So you end up with something like:
Contact c = new Contact();
c.contact = new Contact(1234); // Populate the contact c from the database row with 1234
Contact newContact = c.contact; // Save the contacts state to the database populating the ID
Still an enourmouse WTF but I can see how they arived at this pattern. It would have made more sence if the type the accessors accept / return was an ID rather than a contact. Still would have been a stupid thing to do though.
Admin
The real WTF here is that the <VALUE></VALUE>tag isn't used here for xmldoc'ing.
Admin
Let's try <value></value> instead. DOH.
Admin
It's amazing when I run into code like this that causes no end to problems when users mistakingly reference the property from within the methods they execute from within the property. I guess school's don't teach looping referential bugs in code these days.
Admin
This definitely puts the OO in mOOse ( m Object-Oriented s e ). I'll leave the "m", "s", and "e" as an exercise for the reader. [|-)]
Admin
The scary thing here is what happens when you debug it and the debugger automatically call the property to get its value.
Can you smell a heisenbug?
Admin
Ugh... I think you're right. Kudos for decoding that monstrosity.
On a side note, this code is causing me to have bitter beer face.
Admin
The real WTF:
Admin
first post, w00t!!
Admin
Heh, bind it to a datagrid with a few users and have a look at the dbserver-load [:O]
Admin
1 or 2 or 15 keystone lights would help you out there, my man. It's the never bitter beer. :)
Admin
Well, it just looks to me like a write-on-access pattern, i.e you can set the contact, but it's only persisted if it's ever used. I'd guess the idea is that you pass in an existing contact to clone it, and that clone is only saved to the database if it ends up being used somewhere. It's similar to copy-on-write.
There isn't enough code here to decide if it's a real WTF, SaveToDatabase() might have a 'dirty' flag set by LoadFromContact that let it decide if the contact does in fact need to be written or not. Other properties might call SaveToDatabase when they are modified, etc.
Admin
Awesome: http://en.wikipedia.org/wiki/Keystone_Light
Admin
Object Oriented
or
Objectionably Obtuse?
Admin
And I thought a Keystone Light was a device to cast an irregular pattern of illumination!
Admin
So is the WTF here supposed to be (aside from the switched logic of the get/set functions) that they do more than just obtain and modify some internal property and instead initiate some database transaction? What's wrong with a database abstraction layer?
Admin
Okay, I've been thinking about this for about 15 minutes now, and I think I've figured out what the original developer was doing.
First of all, it doesn't make sense to give a Contact a property called "contact" that is also a Contact. If we have a Contact bob, then I can understand who bob.mother and bob.father are, but who is bob.contact?
Well, I guess it is this guy's way of saving and loading bob to/from the database! Example:
Why he didn't just make SaveToDatabase() and LoadFromContact() public, we may never know.
Admin
what's wrong with this?
this is what consultants do!... very interprisey indeed
Admin
Assuming my interpretation is correct, and that bob.contact == bob, the first code fragment could also be written as:
<FONT color=#006400>// none of the following will save</FONT>
string firstName = contactDetails.firstName;
string lastName = contactDetails.lastName;
string address1 = contactDetails.address1;
string address2 = contactDetails.address2;
string primaryPhone = contactDetails.primaryPhone;
Why address1 and address2 do not save is beyond me. Maybe they really do save, but whoever added those lines didn't bother putting the "saves" comment.
Admin
That is indeed one bass-ackwards pattern, but I can kinda see it. I honestly can't see why you'd need such a pattern, other than to be sure that it saves the data to the database everytime anybody modifies it in certain ways. And the set is completely baffling. Yes, you could do bob.contact = "Bob" to load Bob's info in from the database (or wherever), but why you'd want to do it in that particular way is a bit beyond me.
I find that it's hard to say whether the author is an absolute genius or a complete gibbering idiot. Either one of them could have written this code. :)
Admin
Gentlemen, I see you've all become acquainted with our new code obfuscator. We stymie your competition by secretly switching the contents of your getters and setters with totally random functions. And Folger's Crystals
Admin
Looking at it again, and at the comments above the property, I think I was wrong. Now I'm pretty sure the parameter for LoadFromContact is supposed to be another Contact. My best guess is that it actually copies the data from the passed Contact to this, as opposed to loading the data from the database.
Who knows, maybe there is actually some use for always saving (or saving only if there have been changes) whenever a Contact is used :P.
Admin
Oh, come on. Thanks to the latest misspelling the ubiquitous "first" post can now be "Senate Majority Leader!"
Admin
Boobies!
Also, I don't want to see the interfaces for that monstrosity.
Admin
Exactly what I was thinking. In fact, I'm going to bookmark this page so I have it handy next time I need to explain what a heisenbug is - I don't know when I've ever seen a finer specimen.
Admin
void Contact::LoadFromContact(Contact foo)
{
firstName = foo.firstName;
lastName = foo.lastName;
...etc...
}
The copy constructor probably calls LoadFromContact too.
As another poster said, the getter implements a write-on-access scheme. I don't know why so many people think the logic is switched.
Admin
I agree 'bout parentheses being annoying, but I can at least think of one aesthetic reason to use a Property where a Function would otherwise do; Functions grouped in the Methods section section of the Intellisense thingy (instead of with other Properties), and sometimes having consistent & reliable visual cues on things like that can make a larger than expected difference in productivity on a project.
Admin
There is absolutely nothing perverse about this save for the fact that OO programmers have so forgotten how to do OO that they think a getter is a proper part of OO programming. What is the point of a getter? you declare a field private and then expose it immediately as public thru a getter/setter pair? Ridiculous, just declare it public.
The procedural people (read C and Basic) have infiltrated and messed up OO so much that they actually have you believing that it is perverse for an object to encapsulate a method like retrieving a value from a database. And to the people who say "a getter is useful to do a bit more before returning the value" you've either forgotten what interfaces are meant for or are ignoring the fact that 95% of all getters written out there do NOTHING but return the value (or both). Even the most ardent of the getter apologists will admit that. And before you go saying that only bad programmers write empty getters, take a look thru the last bean you wrote.
Think how silly it would look if you wrote:
private public int x;
now think about what accessors and mutators do. C# programmers are somewhat off the hook because of properties, but if you look under the hood its just syntactic sugar and essentially does the same thing as a java/bean getter. Shame on you.
Going to flame? Read this article first:
http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html
Admin
Admin
agreed, but a small correction: lazy initialization not lazy evaluation. lazy init is lazily fetching portions of an object graph not immediately needed (which hibernate actually uses dynamic proxies for so it doesnt even really need getters).
lazy eval is a language feature which delays evaluation of an expression until it is needed. java does not support this (java is strict-evaluative), neither does c# or any other imperative/OO language.
but yea, rock on kornad
Admin
"the proper way to format a post"? Surely you jest!
But serisouly, I've found the best way to get the formatting right is to
<FONT style="BACKGROUND-COLOR: #000000" color=#ff0000 size=72>FUCK THE RICH EDITOR IN THE ASS</FONT>
and just use the HTML editor. Surround code and whatnot in <pre> tags and use <br> tags to insert "newlines". If you want to be sure, copy the HTML to a file and open it up in a browser and see how it renders.
Admin
Well, that's what I get for trying to use the rich text editor. The text in the black box is supposed to be large and red, but I think I actually like it better the way it came out. Highlight the black box for a surprise!