- 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
Edit Admin
Not only he doesn't understand object oriented programming, he apparently doesn't understand functional programming, either.
In fact, he looks like he doesn't understand programming at all.
Admin
He's actually pioneering Dis-functional programming
Admin
I must admit, that I have serious problems even reading the code...
There are two references to Url (uppercase U) and I have no idea where they are coming from or what it is supposed to mean. Help...
Admin
This is a typed string concept where the idea is that it’s less likely to accidentally populate the incorrect string value between types.
We tied this on a C# project about 10 years ago and although it helped avoid a certain class of mistake, overall it didn’t really feel worth it.
It might be nice if C# had this as a more first class feature, but until then it’s too much of a pain.
Admin
Does the extract function use a global? Or in seniorese: the singleton factory pattern?
Admin
Poor Remy ... "a private member with no accessors"? "It doesn't use the UrlHolder, because of course it couldn't"? TRWTF is Java reflections because you can easily get, set and modify private variables with reflections and stringly typed field names :) The even more RWTF is the Java standard library and things like sun.misc.unsafe which are by design meant to be used only with reflections :) Below code is not a joke, it is how you use most built in libraries in Java (such as sun.misc.unsafe, java.security.MessageDigest, etc.)
Field f = Unsafe.class.getDeclaredField("theUnsafe"); f.setAccessible(true); unsafe = (Unsafe) f.get(null);
Edit Admin
Edit Admin
If these are inner classes (which they appear to be), you can access private members without doing anything special like reflection, so UrlHolder isn't useless. This compiles and runs perfectly fine:
It's still a WTF if they don't actually use the UrlHolder's value though.
Admin
you must be more "senior" than me because in 20 years I have never had to call a built in library this way
Admin
Er...
Unsafe
is used internally by the runtime. "By design", it isn't "meant to be used" at all, unless you're the runtime. Certain library authors have found that it's useful in certain highly specific reflective tasks, but they're knowingly using a highly internal implementation detail in an unsanctioned way. Newer versions of Java have introduced proper APIs for the functionality formerly provided byUnsafe
.You're correct that reflection can be used to bypass access constraints. This is generally regarded as a bad idea in most cases, but has one really useful, er, use: a reflective library can provide a mechanism for a class to register a member with the library without making it part of the class's API. (This typically happens with default constructors.) Like everything in software, it's a tradeoff: it can be used to do terribly unsafe things, but I don't see that as a reason to prevent it entirely. Hell, even C++ has a standards-compliant template hack to access
private
members (and no, I don't mean#define public private
).Edit Admin
@Johnathan: So a very verbose form of Apps Hungarian. But with partial compile-time enforcement of correct usage.
You can get from partial to total as long as you wrap every property and method parameter of every object in every API you use. Sounds ... laborious.
Addendum 2024-11-18 11:06: I imagine the same effort spent on unit tests instead would produce far better software.
Admin
No, it's Objectionable Programming.