- 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
Simple, one line from my original posts explains it all:
"The semantics of naming variables should follow one rule, do they adequately describe what they are representing without being overly verbose? If so then there is nothing wrong with a variable name."
If adding "the" to the variable makes it overly verbose then it is a problem, but if taken in context it makes sense, then leave it. This is a soft rule that can easily be followed.
I mentioned that anyone wanting hard rules will always be wrong follows this also. Once you set hard rules, like you can't use "the" or "my" as prefixes for variables, there will come a time when one of your hard rules causes unnecessary obfuscation of variable names.
Following these two lines of thought, no you should not explicitly deny any type of prefix, but if that prefix is overly verbose within your current context then get rid of it.
And this is exactly what my previous post said, only differently.
Admin
Sure, but it's still a crime against humanity to define the pre-inc operator in terms of post-inc on a member. That says "sloppy for no reason".
Admin
Admin
Admin
Why, Python of course.
Concerning "dangerous" and "evil" I meant that in these languages shooting yourself in the foot is easier than doing useful work (sure, it may be my lack of experience).
Admin
Did you guys miss that the iterator doesn't work, and thus must be manually incremented within the for loop?
Admin
Well, at least in C/C++ performance isn't usually an issue... explain to me how, as regards performance, Python's treatment of the global namespace (and namespaces in general) isn't both dangerous and evil?
What was Guido thinking: "Oh, I don't know, if it fails in the current namespace, then we'll try the next higher one..."? What??? Whyyyyyyy?
Admin
Someone else pointed out the Singleton pattern. Actually, the way it was described by that poster is not the correct way to implement a Singleton; it should be a static accessor of the class, and it's almost always called "Instance" or "Current" or sometimes "Default" depending on the context. For example, you might use "HttpContext.Current" or "Settings.Default" or "Application.Instance".
If you're working with a language that doesn't support this, then you're working with a language that essentially isn't fully object-oriented and hence the Singleton pattern is meaningless. However, for argument's sake, let's say you want to mimic this pattern with a global variable, then fine; the accepted notation for this is either "SingletonClass" (if you're working with a language like Delphi where the class itself would be called "TSingletonClass"), or "SingletonClassInstance" in other languages. Or, again, depending on the context, you might choose a variation of the static accessor names like "CurrentSingletonClass" or "DefaultSingletonClass" - but never "TheSingletonClass", it's meaningless.
So I ask again - please provide one valid example of where the word "the" is not redundant, irritating cruft.
Admin
You shouldn't need to track in your var names what sort of variable it is, just what its name is. the "sort of thing" it is should be encapsulated in its type
Position *p, *active, *the;
which highlights the discomfort of using pronouns for most non Perl coders.
Admin
That makes no sense at all.
Admin
What. The. Fuck.
Admin
Which amply demonstrates that you can be effective without being obscure. This was pure pleasure to read, so thank you, Aron.
Admin
(Pretending that "Application" is an extremely verbose class name.)
Admin
The real wtf has to be the indentation. Please tell me that's some quirk of posting it, and not as per the original code. It's hideously inconsistent!
Admin
The Real WTF is using const_cast. I'm generally of the opinion that once const, always const (and therefore, const_cast shouldn't even exist, neither should it be possible to cast const away C-style). It is much cleaner to have the base class variable be nonconst (you don't even have to change the type of operator* in your const iterator, and just because it's a nonconst var doesn't mean you have to write it at some point), that way nonconst iterator doesn't have to uglyhack-away const which can break things sometimes (compiler optimizing away reference to const, for example).
Admin
Why? How to I infer the type of something when I'm reading my code? Do I stick it under my pillow at night and learn it through osmosis?
So I'm reading along and I see: for(i = 1 to 10) active++; the = active; if (p == george) the++; end for
I don't know what an active is, nor a the, nor p or george. do p and george share the same type?
Admin
The C++ standard requires them to be syntactically correct.
Some compilers make the 'optimisation' of never bothering to compile a template that isn't instantiated -- but that is not something that you should rely on if you are trying to write portable code.
The standard supports compilers that compile a template which can later, behind the scenes, receive the template parameters as arguments. However, most compiler vendors have not implemented this because it is difficult and there is little customer demand. Look up 'export' in the context of C++.
Admin
It looks as if this code is from the ROOT framework: http://root.cern.ch/ The ROOT framework used to be written in FORTRAN, and has recently been ported to C++. Oh yes, and it's mostly used for High Energy Physics (HEP) analysis.
Oh, and most of the source code (available on the site) resembles the pseudo-crazyness that the post elucidates.
Admin
Admin
Hi,
Being the one who submitted this code, let me give you the executive summary:
The major wtf is that the ".begin()" and ".end()" methods return different types - rendering the use of well established algorithms from STL totally impossible since they all require that the iterators you give them are of the same type, irrespective of whether the algorithm was intended for forward, backward, bidi- or basically any sane type of iterator class.
In order to be able to anything with these "iterators" they overloaded the comparison operators == and != on the type that ".begin()" returns so it would be comparable with whatever ".end()" returns.
Other wtf indeed is the derivation of the non-const iterator of the const version.... Apparently that is considered "good practice" by the coders since that construction is found in more than one instance.
As for the "the" and "its" stuff: yeah it sux0rs but a coding convention for the whole package was decided upon long ago so you just have to go with that. 's a bum deal but with multiple developers spread over multiple continents and developers coming in and going out over time it's the only way to maintain some form of consistency.
Admin
Two words: Koenig lookup.
C++ loses right to whine about namespaces if only because of that hack.
Captcha: pirates. Yarr.
Admin
I can't figure out why so many people blame the languages due to the programmers mistakes
captcha: kungfu - well appropriate. IT people need more of this
Admin
First thing to remember, I am not defending any form of prefix or method of naming, neither am I saying I will deny any. You are attempting to force me to break my own rule and that won't happen. In a certain context, it could be seen that using "the" as a prefix might be valid, the other side of my statement does say that if it is meaningless, then remove it.
This is a very soft rule as it is up to personal interpretation at times. If I concede and say that "the" as a prefix should never be used, then it is a hard rule, that at some point might be wrong. There is no telling the context of a variable within these rules, and even as the technology changes we need rules that, by their very nature, change with them. My form of this rule does this and I won't deviate even if I can not find an example that satisfies you.
Admin
Actually you just provided it yourself. The following names all have the same meaning: CurrentSingletonClass DefaultSingletonClass TheSingletonClass
The prefixes all mean the same thing here. It is simply your aversion to using "the" that makes it different. I say that using "the" is just as appropriate via my rule as it does not "make it overly verbose" while still "representing its purpose." If you will allow "current" why not "the", this is simply personal choice which has no place in the formation of soft rules.
Admin
You forgot the fact that the increment operators are also broken since the following wouldn't compile:
while (iter++ != end) { /* foo */ }
which is fairly common code found in standard library algorithms.
I'm not sure how some people are saying that this is not WTF material. Surely it might have not been a decade ago (even then, this is some POS code) but I hope no one is writing code that looks like this today.
To be absolutely clear (since some people were saying these operators should return references and others saying it should return T), the pre-increment operator should return a reference to itself after having incremented, while the post-increment returns a copy of itself before being incremented. This is why it's always better to use the pre-increment operator on class types rather than the post-inc operator.
Admin
Hmm, reading my own post I realized the stupid example I posted. A correct example would be something like:
Particularly something like this may be used when you need to iterate in pairs. I left out checking if 'iter' wasn't equal to 'end' after the increment (or in the while condition) as to not clutter the example, but you get the idea.
Admin
Windows gives plenty of fodder. I use "the" to help separate my variables from the types (which can often have the same name.
E.g., look up the definition of WinMain in the Windows SDK, can you'll probably have something like:
HINSTANCE hInstance
which to me is a bit... silly (at least UNIX seems to have standardized on appending "_t" for types) since they really differ only in capitalization. I'd prefer my variables to actually be a bit more distinct than just capitalization (because you can forget to check "Case sensitive" and need to search for uses of a variable rather than including a variable declaration also), so I might write:
HINSTANCE theInstance
Of course, everyone KNOWS what WinMain's definition looks like, but if you're buried deep within code...
And sometimes, an unoriginal name is the type name. E.g., in a function prototype for graphics, I might want something that looks like:
BOOL ColourRectangle(HDC dest, RECT rect, ...);
I dislike "rect" because it differs from the type by case only (and you KNOW someone out there has typed RECT RECT...), so I'd probably call the variable theRect. Which also helps me find instances of it by searching within the function, should many other RECT's be declared.
And people who write multiple variables using slightly different casing should be shot. hInstance, hINSTANCE, ...
Admin
What - are you inferring that we should do test-based development? How dare you!!? Anyone with half a brain knows that the best way to impliment systems is to slap them together as fast as possible and immediately move on to the next project! 'Improving' the code is the job of Junior Maintainers, and development is the domain of the vain and clever - too clever to be slaving over such minor details...
Admin
Ok...i keep reading this as Standard temple Library....
Damn thing reminds me of the Vatican with the secret vaults and all....course it is 5pm here so I think my brain has gone home already...
Admin
The convention that I've seen most often for Singletons is:
This is particularly in Java code, but the convention appears to be common in C++ code as well.
Admin
holy s***
Admin
I know a project similar to ROOT from Astrophysics. It's called AIPS++. It's also from the early nineties, it has some of the most advanced C++ I have ever seen, some real gems, but very hard to understand at times.
While ROOT has been able to switch most of the community to the newer software, AIPS++ has made all the software management mistakes you can think of. So 15 years down the line, almost no-one uses it, most people are still stuck with software like Miriad and AIPS, which are so old that they do not know file systems, put the graphics on your TV and have input/ouput and program discs.
The AIPS++ is filled with WTFs, not so much at the code level, but in how it was designed and managed. Maybe a story for another time.
I have one final question to all forum readers, just to stay on topic:
What C++ Array library would you recommend?
I know of seeral projects that have rolled their own Array class (and sub-classes like Vector, Matrix, Cube), and I know the STL only provides vector, which is not sufficient. Is boost what I should be looking at, or is there some other library?
Admin
Admin
Yes, boost::array is a nice wrapper around a fixed-sized statically allocated array that provides a nice interface. It's also going to be in C++0x.
Admin
"For those who don't grok C++ or templates, the problem with the code here is that the begin and end iterators are of different type"
That is not the only problem. "void operator++()" and "void operator++(int)" aren't reall helpful, either.
Admin
Shudder.
I think the author was just guessing what C++ code to put in. Trial and error until the thing vaguely looks like it might be working. I didn't read all of it, lest I be corrupted.
captcha: dubya
Admin
hmmm, this is the reason why i left c++ for c-pound hahaha
Admin
I was amazed about the comments made on this WTF, which showed a piece of code without any context. And it's the context that is important. Only some people tried to look through the code and made useful comments.
Performance of for loops iterating over a container can be very important. Therefore it is important how one deals with the end() function. Many people use end() directly in the for statement which can have severe performance penalties. Doing that on e.g. boost's multi_array takes twice as much time than doing
beforehand and using iterend in the for statement. Maybe the same was true for this Array class and the author tried to safeguard against this (mis)usage of end(). It's too bad that some text books teach this bad practice.Admin
货架 仓储货架 仓库货架