- 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
FristComment.Read = false;
{I had to do it!}
Admin
Frist = false
Admin
Reading this literally me say WTF?
Admin
Is this some sort of introspective class? Where access to the getter/setter functions is controlled by bools in the structure itself?
Not a bad idea to have an object enforce its readonly status by if(!field_readonly) in its setter, and if (field_visible) in its getter.
It might even be a design pattern. Not necessarily a good one, but a pattern none the less.
--Joe
Admin
Did Paula work for this team?
Admin
So I think the problem is that NameReadOnly = false still makes the name read only. I can only imagine that their is a NameNotReadOnly setter somewhere...
Admin
Ah, now I "see" it.
The GUI has 2 controls laid exactly on top of each other. An editable box (organizationName) and an un-editable box (organizationNameRead)
So to make it read-only, you hide the one that's editable.
Just hope that they never both get visible at the same time, and that nobody ever moves one of them.
--Joe
Admin
Admin
Admin
Classic property abuse with a bonus side-order of Visible/Enabled confusion. Not exactly a world-ending WTF but it always makes me cringe to see developers making such elementary errors.
Admin
Could have been worse. It could have been LabVIEW.
Admin
Please enlighten me. Why is this "abuse"? What do you mean by Visible/Enabled confusion? I can imagine this being an ASP.NET page for example, and the developers are hiding (say) a textbox and making visible a div/span with plain text. To me that seems like a pretty sensible solution.
Admin
Translating this to Java for those not familiar with C# property syntax:
public void setNameReadOnly(bool nameReadOnly) { organizationName.setVisible(false); organizationNameRead.setVisible(true); }
So it's a property setter that is not a property setter.. and there's no getNameReadOnly() method.
Admin
Admin
I worked on a product that had a web-based front-end; we did exactly this for enabling/disabling fields. That said, it was the easiest way to get the page working consistently across all the browsers we had to support.
Admin
Every time I see someone saying "there is no WTF" I'm thinking "this guy either has no humor or is a bad developer" , but here come on ! At worst it's a bad practice, but I would do it myself without any remorse !
Admin
After a couple of digging through the sloppy editing, I have come to the conclusion that you accidentally some of the article.
Admin
I don't even see the WTF. Ok, granted, they should have used
public bool NameReadOnly { set { organizationName.Visible = !value; organizationNameRead.Visible = value; } }
Assuming the difference between organizationName and organizationNameRead is bigger then just organizationName.ReadOnly, this might actually be a half sane solution.
Admin
ok I see ! There is a bug ! If by default the field is not readonly, then there is a only "maybe" a bug.
Admin
Cheater! You changed the outcome by observing it!
--Joe
Admin
You me to it!
Admin
Was this too subtle?
Admin
It doesn't return anything. It only has a set method.
Admin
Christ on a bike, do we ever have a metric ass ton of WTF apologists. No, it's not a good idea, not even maybe. Given no context I can still guarantee that this is a bad idea. No, this was a junior dev who had a poor grasp of which constructs/patterns to use where and when.
Also, setting a property should not cause side effects (I'm assuming though, that the developer intentionally didn't use "value" and is using a property setter as a method instead).
Admin
The problem with rats leaving a sinking ship is that they usually do it by gnawing holes in the bottom.
Admin
Visible/Enabled confusion: Using two controls (one editable, one non-editable) and managing them via their "Visible" property, instead of using a single control and managing its read-only state with the "Enabled" property.
Sensible solution? No comment.
Admin
So... the WTF is that thingy.NameReadOnly = true; and thingy.NameReadOnly = false; both either make name read-only or both make name read-write, but who knows which?
Admin
Admin
No, it's the fact that they used a property setter as a method. It gets the job done but is confusing as hell for anybody else who has to trudge through that "code".
Admin
I'm assuming that organizationNameRead is exactly the same control as organizationName with the exception of the ReadOnly property being set differently. Both controls sit on top of each other in the application's form.
At least, that's how I read it, this being The (somewhat) Daily WTF.
The code could likely be (and remove the other control):
public bool NameReadOnly { set { organizationName.ReadOnly = value; } }
Admin
Our company pride on completion of all project undertaken.
Admin
Yeah, what to the verbs?
Admin
Say what? Whilst I agree the codes a particularly horrendous wtf, both in not using value at all and in being a set only property... The fact that the property setter has side effects is not one of them. That's pretty much the whole point of property setters, just look at the standard uses - enabled, visible, text, font etc - without side effects, what purpose would these have?
Admin
Admin
Admin
Admin
How did he observe it if it wasn't visible?
Admin
That's kind of what I was thinking, why have a property with (getters and) setters if it never has side effects? What is the real advantage of a property which gets/sets a "hidden" field over just making the field public (similarly the getter/setter method (anti)pattern in java)? If you want the field read-only make it so (final in java). I'm not sure why one would want to make a property write-only and not expect there to be side effects from setting it (if at the very least it changes the behavior of the containing object).
I will concede, however, that they should either have used "value" so that obj.NameReadOnly = false undoes whatever obj.NameReadOnly = true does, or used a real method instead.
Admin
Admin
Yeah, people do all kinds of crazy stuff when you have mutable fields.
Admin
Not so. I am saying that with our company we would never go dessert ship like sinking rats.
Admin
Well yeah... It's a big WTF. If it's written for C#, this isn't a "read only" property. You have a setter that ignores the value... so somewhere in the code we must have this:
NameReadOnly = false;
But that doesn't really do anything... but you have to call it, or the states of the controls will be default, which may be unknown... I'm confused...
Admin
This is the codebehind for a .net webform. The idea is that 1) the user does something to cause a postback (click a button, for example) 2) the code looks at things like form values, etc; and determines that a value (organizationName) should no lcnger be editable; but that the organizationName's value should be displayed as text.
One way to do this is to set the Visible propery of the two webform controls involved at that point in the code. Another way to do it would be to call a method to set the Visible propery.
Another way to think of this, though, is that the form itself is an object; and that object has state. The state would be represented by properties; one of the properties is that the organizationName is editable, or is not editable.
In that sense, a property has a legitimate reason for setting the Visible property of these form controls.
[Of course, you'd actually want to code the property's code correctly, to turn the visibility on or off.]
Admin
To not observe is still to observe, thereby changing the outcome.
Admin
So setting the ".visible" property on a control should not cause the control to be shown or hidden?
Admin
Admin
Admin
Sorry, I didn't mean it that it shouldn't have ANY side effects. I should have been more explicit, and I realized after I submitted my post.
I'm talking more about something like this:
Sorry, I've seen stuff like this and it makes me cringe. Also a property is just that, a property and a method is a verb, a unit of work. IAmCool = false vs. MakeMeCool(bool makeCool).I hope that makes more sense then the aspergers induced crap that I wrote before.
Admin
Admin
The WTF is that write only accessors are effectively just functions. This should be written as follows:
public void MakeReadOnly(){ organizationName.Visible = false; organizationNameRead.Visible = true; }